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)
There is no inbuilt mechanism available to run a media file (such as mp3) in Python, but there are many 3rd party libraries such as vlc or pygame using which we can play an audio file in Python.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With