def process(self):
        print("[Playlist] Processing started for: " + self.output_file_name)
        try:
            AudioSegment.converter = which('ffmpeg')
            uploaded_file = AudioSegment.from_file(self.uploaded_file_path, self.uploaded_file_path[-3:])
            info = mediainfo(self.uploaded_file_path)
            
            self.allowed_durations = [ float(info['duration']) / 60 ] #Music of all durations is permitted

            checker = FileChecker(file_path=self.uploaded_file_path, durations=self.allowed_durations,
                                  min_sample_rate=self.min_sample_rate, min_bitrate=self.min_bitrate,
                                  recommended_bitrate=self.recommended_bitrate, info=info,
                                  do_normalization=True, do_check_duration=False, accept_clipping=True)
            print("\t* Checking file...")
            parameters = checker.run_checks()

            self.build_tags(info)

            print("\t* Exporting...")
            uploaded_file.export(self.output_file_path,
                                 bitrate=self.recommended_bitrate + "k",
                                 tags=self.tags,
                                 parameters=parameters)

            print("\t* Uploading...")
            self.remote_service.upload_track_to_playlist(self.output_file_name, self.output_file_path)

        finally:
            print("\t* Cleaning up...")
            self.cleanup()
def convert_audio_files():
    if not which("ffmpeg"):
        log.warning("Couldn't find ffmpeg")

    error_files = []

    for original_audio_file_path in glob.glob(
            os.path.join(AUDIO_DIR(), '*.wav')):
        try:
            for speed in []:
                _convert_audio(original_audio_file_path, speed)

            for speed in []:
                _convert_audio_with_normalisation(original_audio_file_path,
                                                  speed)

            _convert_audio_with_noise_injection(original_audio_file_path, 0.01)
            _convert_audio_with_noise_injection(original_audio_file_path, 0.03)
            _convert_audio_with_noise_injection(original_audio_file_path, 0.05)
            _convert_audio_with_noise_injection(original_audio_file_path, 0.07)
            _convert_audio_with_noise_injection(original_audio_file_path, 0.09)
            _convert_audio_with_noise_injection(original_audio_file_path, 0.1)

            #_convert_audio_with_random_speed(original_audio_file_path, random.choice(np.arange(0.7, 1.3, 0.1)))
        except:
            error_files.append(original_audio_file_path)
            log.warning(f'Could not convert {original_audio_file_path}')

    if len(error_files) != 0:
        log.warning(f'Could not convert {error_files}')
    def process(self):
        print("Processing started for: " + self.normalized_program_name)
        try:
            AudioSegment.converter = which('ffmpeg')
            uploaded_file = AudioSegment.from_file(
                self.uploaded_file_path, self.uploaded_file_path[-3:])
            info = mediainfo(self.uploaded_file_path)

            checker = FileChecker(file_path=self.uploaded_file_path,
                                  durations=self.allowed_durations,
                                  min_sample_rate=self.min_sample_rate,
                                  min_bitrate=self.min_bitrate,
                                  recommended_bitrate=self.recommended_bitrate,
                                  info=info,
                                  do_normalization=not self.already_normalized,
                                  do_check_duration=self.adjust_duration)
            print("\t* Checking file...")
            parameters = checker.run_checks()

            self.build_tags(info)

            print("\t* Exporting...")
            uploaded_file.export(self.output_file_path,
                                 bitrate=self.recommended_bitrate + "k",
                                 tags=self.tags,
                                 parameters=parameters)

            print("\t* Uploading...")
            self.remote_service.upload_program_to_archive(
                self.normalized_program_name, self.output_file_path)
            if self.emission_date == datetime.now().strftime("%Y%m%d"):
                self.remote_service.upload_program_to_emission(
                    self.output_file_path)

            print("\t* Sending email...")
            self.email_service.send_upload_accepted(
                checker=checker,
                program_name=self.normalized_program_name,
                emission_date=self.emission_date)

        except IrrecoverableProblemsException:
            print("\t\t- File has bad problems, sending email...")
            self.email_service.send_upload_rejected(
                checker=checker,
                program_name=self.normalized_program_name,
                emission_date=self.emission_date)

        except Exception as e:
            print("- Something unexpected happened, sending email...")
            print(e)
            print_tb(e.__traceback__)
            self.email_service.send_upload_failed(
                program_name=self.normalized_program_name,
                emission_date=self.emission_date)

        finally:
            print("\t* Cleaning up...")
            self.cleanup()
Exemple #4
0
 def __init__(self):
     self.file_name = None
     # SET CONVERTER
     self.__converter__ = "ffmpeg"
     AS.converter = which(self.__converter__)
     # SET OUTPUT FILE TYPE
     self.output_type = "mp3"
     # INIT SOUNDBYTE FILE
     self.sound_byte = None
     # INIT OUTPUT FILE
     self.output_sound_byte = None
     # INIT DESTINATION PATH
     self.destination_path = None
def audio_segment(AUDIO_FILE):
	AudioSegment.converter = which("ffmpeg")
	sound = AudioSegment.from_file(AUDIO_FILE,format= 'mp3')

	Fs,sound = readAudioFile(AUDIO_FILE)

	mid = len(sound)//2

	first_half = sound[:mid]
	second_half = sound[mid+1:]

	first_half.export("/home/ayush/Desktop/WishFin/first_half.mp3",format = "mp3")
	second_half.export("/home/ayush/Desktop/WishFin/first_half.mp3",format = "mp3")
def save(login, file):
    if login != '':
        try:
            current_path = path + '/' + login
            for chunk in file.chunks():
                AudioSegment.converter = which("ffmpeg")
                Audio = AudioSegment.from_file(io.BytesIO(chunk), format="wav")
                normalized_audio = match_target_amplitude(Audio, -20.0)
                file_path = os.path.join(current_path,
                                         login + uuid.uuid4().hex)
                #                 ubmfile_path = os.path.join(path + '/' + 'UBM', login + uuid.uuid4().hex)
                normalized_audio.export(file_path + '.wav', format="wav")
#                 normalized_audio.export(ubmfile_path + '.wav', format='wav')
        except:
            pass
import time
import boto3
from boto.s3.key import Key
import requests
import threading

# Imports the Google Cloud client library
from google.cloud import speech
from google.cloud.speech import types
from google.cloud.storage import Blob
from google.cloud import storage

from pydub import AudioSegment
from pydub.utils import which

AudioSegment.converter = which("ffmpeg")

class SttIntegrated:
    def __init__(self, file_path):
        self.inputFilePath = file_path
        # Hard-coding the path for credentials file downloaded from Google API dashboard.
        
        os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = 'FILL WITH YOUR OWN'

        # fix as necessary
        self.s3_region = "FILL WITH YOUR OWN"
        self.s3_bucket_name = "FILL WITH YOUR OWN"

    def google_stt(self):
        # Instantiates a client
        client = speech.SpeechClient()
def make_a_call():
    AudioSegment.converter = which("ffmpeg")

    chunk = 1024  # Record in chunks of 1024 samples
    sample_format = pyaudio.paInt16  # 16 bits per sample
    channels = 1
    fs = 8000  # Record at 44100 samples per second
    #seconds = 4
    filename = "outputfrom2.wav"

    p = pyaudio.PyAudio()

    print('请开始说话')
    tk.messagebox.showinfo('提示', '请开始说话')

    stream = p.open(format=sample_format,
                    channels=channels,
                    rate=fs,
                    frames_per_buffer=chunk,
                    input=True)

    frames = []  # Initialize array to store frames

    # Store data in chunks for 3 seconds
    for i in range(0, int(fs / chunk * second)):
        data = stream.read(chunk)
        frames.append(data)

    # Stop and close the stream
    stream.stop_stream()
    stream.close()
    # Terminate the PortAudio interface
    p.terminate()

    print('Finished recording')

    # Save the recorded data as a WAV file
    wf = wave.open(filename, 'wb')
    wf.setnchannels(channels)
    wf.setsampwidth(p.get_sample_size(sample_format))
    wf.setframerate(fs)
    wf.writeframes(b''.join(frames))
    wf.close()

    sound = AudioSegment.from_file('outputfrom2.wav', format='wav')
    #play(sound)
    sound.export('outputfrom2.amr', format='amr')

    with open('outputfrom2.amr', 'rb') as f:
        amr = f.read()
    with open('encryptfrom2.amr', 'wb') as e:
        e.write(rc4encrypt(amr, '123456789'))

    clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    clientsocket.connect(('127.0.0.1', 4050))
    with open('encryptfrom2.amr', 'rb') as f:
        while True:
            filedata = f.read(1024)
            if filedata:
                clientsocket.send(filedata)
            else:
                tk.messagebox.showinfo('提示', '发送完毕')
                break
    clientsocket.close()
Exemple #9
0
import os
import pydub
import glob
import datetime
import shutil
from pydub.utils import which
from PIL import Image

which("ffmpeg")
dato = datetime.date.today()

print("Opretter mp3-mappe...")
os.mkdir(str(dato) + "_MP3")

wav_files = glob.glob('./*.wav')
for wav_format in wav_files:
    mp3_file = os.path.splitext(wav_format)[0] + '.mp3'
    sound = pydub.AudioSegment.from_wav(wav_format)
    sound.export((str('./') + str(dato) + "_MP3/" + mp3_file[2:]),
                 format="mp3")
    print(str(mp3_file[2:][:-4]), "succesfuldt konverteret til mp3")
im = Image.open("abby.png")
im.show()
Exemple #10
0
from pydub import AudioSegment
from pydub.utils import which

import os
import sys

GLOBAL_PATH = os.path.dirname(os.path.abspath(__file__))
CUT_COMMAND = " ffmpeg -i {0}.mp3 -f segment -segment_time 10 -c copy {0}%01d.mp3"
DELETE_COMMAND = "rm -rf {0}"
AudioSegment.converter = which('ffmpeg')
GLOBAL_DIR = os.path.dirname(os.path.abspath(__file__))


def mixing(audio_segment_first, audio_segment_second, position=0):
    difference = audio_segment_second.max_dBFS - audio_segment_first.max_dBFS
    # print(difference)
    if difference > 0:
        audio_segment_second += difference * 2
        # audio_segment_second = audio_segment_second.apply_gain(-difference + audio_segment_second.dBFS)
        # print('new ', audio_segment_second.dBFS)
    return audio_segment_first.overlay(audio_segment_second,
                                       position=position * 1000)


def read_file(path_to_file):
    audio_segment = AudioSegment.from_file(path_to_file)
    return audio_segment


def save_mixing_file(mixing_audio_segment, filename):
    mixing_audio_segment.export(filename, format='mp3')
Exemple #11
0
 def __init__(self, url):
     AudioSegment.converter = which("ffmpeg")
     self.url = url