22

I want to convert any audio file (flac, wav,...) to mp3 with python I am a noob , I tried pydub but I didn't found out how to make ffmpeg work with it, and If I'm right it can't convert flac file.

The idea of my project is to : Make musicBee send the path of the 'now playing' track (by pressing the assigned shortcut) to my python file which would convert the music if it is not in mp3 and send it to a folder. (Everything in background so I don't have to leave what I'm doing to make the operation)

Canapy
  • 223
  • 1
  • 2
  • 4

1 Answers1

34

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")
Community
  • 1
  • 1
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108