"convert any audio file to mp3 with python" Code Answer

1

you can use the following the code:

from pydub import audiosegment

wav_audio = audiosegment.from_file("audio.wav", format="wav")
raw_audio = audiosegment.from_file("audio.wav", format="raw",
                                   frame_rate=44100, channels=2, sample_width=2)

wav_audio.export("audio1.mp3", format="mp3")
raw_audio.export("audio2.mp3", format="mp3")

you can also look here for more options.

flac_audio = audiosegment.from_file("sample.flac", "flac")
flac_audio.export("samplemp3.mp3", format="mp3")
By karolf on July 7 2022

Answers related to “convert any audio file to mp3 with python”

Only authorized users can answer the Search term. Please sign in first, or register a free account.