Spoken Language Processing in Python
Daniel Bourke
Machine Learning Engineer/YouTube Creator
from pydub import AudioSegment # Audiobestand importeren wav_file = AudioSegment.from_file("wav_file.wav")# Verhoog met 10 decibel louder_wav_file = wav_file + 10# Luider audiobestand exporteren louder_wav_file.export(out_f="louder_wav_file.wav", format="wav")
<_io.BufferedRandom name='louder_wav_file.wav'>
def make_wav(wrong_folder_path, right_folder_path):# Loop door verkeerd geformatteerde bestanden for file in os.scandir(wrong_folder_path):# Werk alleen met audio-extensies die we fixen if file.path.endswith(".mp3") or file.path.endswith(".flac"):# Maak de nieuwe .wav-bestandsnaam out_file = right_folder_path + os.path.splitext(os.path.basename(file.path))[0] + ".wav"# Lees het audiobestand en exporteer als wav AudioSegment.from_file(file.path).export(out_file, format="wav")print(f"Creating {out_file}")
# Roep onze nieuwe functie aan
make_wav("data/wrong_formats/", "data/right_format/")
Creating data/right_types/wav_file.wav
Creating data/right_types/flac_file.wav
Creating data/right_types/mp3_file.wav
def make_no_static_louder(static_quiet, louder_no_static): # Loop door bestanden met ruis en lage volume (al in wav) for file in os.scandir(static_quiet_folder_path):# Maak nieuw bestandspad out_file = louder_no_static + os.path.splitext(os.path.basename(file.path))[0] + ".wav"# Lees het audiobestand audio_file = AudioSegment.from_file(file.path)# Verwijder eerste drie seconden, +10 dB en exporteer audio_file = (audio_file[3100:] + 10).export(out_file, format="wav") print(f"Creating {out_file}")
# Verwijder ruis en maak luider
make_no_static_louder("data/static_quiet/", "data/louder_no_static/")
Creating data/louder_no_static/speech-recognition-services.wav
Creating data/louder_no_static/order-issue.wav
Creating data/louder_no_static/help-with-acount.wav
Spoken Language Processing in Python