BaşlayınÜcretsiz Başlayın

Manipulating multiple audio files with PyDub

You've seen how to convert a single file using PyDub but what if you had a folder with multiple different file types?

For this exercise, we've setup a folder which has .mp3, .m4a and .aac versions of the good-afternoon audio file.

We'll use PyDub to open each of the files and export them as .wav format so they're compatible with speech recognition APIs.

Bu egzersiz

Spoken Language Processing in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Pass audio_file to the from_file() function.
  • Use export() to export wav_filename with the format ".wav".

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Loop through the files in the folder
for audio_file in folder:
    
	# Create the new .wav filename
    wav_filename = os.path.splitext(os.path.basename(audio_file))[0] + ".wav"
        
    # Read audio_file and export it in wav format
    AudioSegment.from_file(____).____(out_f=wav_filename, 
                                      format=____)
        
    print(f"Creating {wav_filename}...")
Kodu Düzenle ve Çalıştır