November 26, 2020
How to convert wav or mp3 to flac using Python.
Before you can use the script, you must install dependencies:
brew install ffmpeg
sudo apt-get install ffmpeg
pip install pydub
from os.path import splitext
from pydub import AudioSegment
def wav_to_flac(wav_path):
flac_path = "%s.flac" % splitext(wav_path)[0]
song = AudioSegment.from_wav(wav_path)
song.export(flac_path, format = "flac")
def mp3_to_flac(mp3_path):
flac_path = "%s.flac" % splitext(mp3_path)[0]
song = AudioSegment.from_mp3(mp3_path)
song.export(flac_path, format = "flac")
mp3_to_flac("test_split3.mp3")