jiaaro / pydub

Manipulate audio with a simple and easy high level interface
http://pydub.com
MIT License
8.58k stars 1.01k forks source link

Convert audio recording in 'webm' to 'flac' format (For Google Speech-to-Text) #603

Open Vishav3 opened 2 years ago

Vishav3 commented 2 years ago

I am trying to convert audio recording in webm format to 'flac' Below is my code:

import time camera = CameraStream(constraints={'audio': True,'video': False}) recorder = AudioRecorder(stream=camera, format='webm') recorder.recording = True time.sleep(5) recorder.recording = False recorder.audio.autoplay = False ipd.display(recorder.audio) with BytesIO(recorder.audio.value) as f: audioFile = AudioSegment.from_file(f, format='webm') with BytesIO() as f: audioFile.export(f, format='flac') audioBytes = f.getvalue()

I am getting the following error: image

GreyAlien502 commented 2 years ago

Are you sure recorder.audio.value has the correct format? Can you save it to disk and upload it?

Note that the error occurs on line 12:

audioFile = AudioSegment.from_file(f, format='webm')

, so everything after that is irrelevant to your problem.