I am getting oga file from javascript blob and I want to convert it to PCM compatible wav file in python. The approach I am using is as follow
AudioSegment.converter = r"C:/ffmpeg/bin/ffmpeg.exe"
AudioSegment.ffprobe = r"C:/ffmpeg/bin/ffprobe.exe"
sound = AudioSegment.from_file("file.oga")
sound.export("file.wav", format="wav")
For this I have to download ffmpeg locally. Is there any way to convert oga file to wave directly.
This is how i am saving file
f = open('./file.oga', 'wb')
f.write(base64.b64decode(file))
f.close()
Try this:
import os
import soundfile as sf # pip install pysoundfile
input_folder = 'ogg_files_folder'
output_folder = 'wav_files_folder'
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for filename in os.listdir(input_folder):
if filename.endswith('.ogg'):
input_file_path = os.path.join(input_folder, filename)
data, samplerate = sf.read(input_file_path)
output_file_path = os.path.join(output_folder, os.path.splitext(filename)[0] + '.wav')
sf.write(output_file_path, data, samplerate)
print(f'Converted {input_file_path} to {output_file_path}')
print('Conversion complete.')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With