jiaaro / pydub

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

Can't export mp3 to ITU G.711 telephony format. #384

Open david-macias opened 5 years ago

david-macias commented 5 years ago

Steps to reproduce

sound = AudioSegment.from_mp3("speech.mp3") sound = sound.set_frame_rate(8000) sound.export("speech.wav", codec="mulaw", format="wav")

Expected behavior

Format should read: ffmpeg -i speech.wav Input #0, wav, from 'speech.wav': Duration: 00:00:02.27, bitrate: 64 kb/s Stream #0:0: Audio: pcm_mulaw ([7][0][0][0] / 0x0007), 8000 Hz, mono, s16, 64 kb/s

Actual behavior

ffmpeg -i speech.wav Input #0, wav, from 'speech.wav': Duration: 00:00:02.27, bitrate: 128 kb/s Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s

Your System configuration

Is there an audio file you can include to help us reproduce?

Any mp3 you wish to convert.

derek-adair commented 5 years ago

Does pydub support all of the filetypes that ffmpeg/libav does?

jiaaro commented 5 years ago

@derek-adair it does, but that list depends on how your specific copy of ffmpeg/libav was compiled. The install instructions in the README have some notes about e.g., flags you can include when installing via homebrew to enable more formats

derek-adair commented 5 years ago

Does it just silently fail when a ffmpeg can't find the codec?

It should probably throw a warning.

jiaaro commented 5 years ago

@derek-adair if ffmpeg fails to convert a file while loading it rasises a pydub.exceptions.CouldntDecodeError or during export, a pydub.exceptions.CouldntEncodeError

I think this may actually be another instance of pydub using the stdlib wave module because the output format is "wav".

david-macias commented 5 years ago

I guess I'm trying to understand here (pardon the noob) @derek-adair are you suggesting that the way I installed pydub might have something to do with the my issue? The file is "converted" it's just not the format I expected. Try yourself and you'll notice that "Audio: pcm_mulaw" comes up incorrectly as compared to a file from https://archive.codeplex.com/?p=audiotestfiles which I used as my baseline for u-law format.

derek-adair commented 5 years ago

I am overly suspicious of installation issues, it seems this is not the case here. I'll try and find the issue, but i'm out of time at the moment.

BASICALLY - ( @jiaaro - correct me if i'm wrong ) - pydub uses the standard python lib for wav file conversions and operations. This seems to be why PyDub is not exporting ITU G.711.

PS - that audiotestfiles archive is a great resource.

GreyAlien502 commented 4 years ago

This has been fixed by pull request #393. Now, nonsensical options like codec="mulaw", format="wav" result in a CouldntEncodeError. This issue can be closed now.