Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert wav to flac from python?

I've just started using Python and am using the PyAudio and Wave modules to take sound from my microphone and convert it to a .wav file.

What I'm trying to do is now convert that .wav to a .flac. I've seen a few ways to do this which all involve installing a converter and placing it in my environmental PATH and calling it via os.system.

Are there any other ways to convert a .wav to a .flac via Python? The solution I'm looking for needs to work on both Windows and Linux.

like image 891
Charles W Avatar asked May 29 '14 04:05

Charles W


1 Answers

I have not tested this solution but you can use pydub

    from pydub import AudioSegment
    song = AudioSegment.from_wav("test.wav")
    song.export("testme.flac",format = "flac")

the conversion is supported with numerous file formats (see the ffmpeg supported file formats list herehttps://ffmpeg.org/general.html#Audio-Codecs

like image 191
GodSaveTheDucks Avatar answered Oct 13 '22 02:10

GodSaveTheDucks