Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export mp3 in python using ffmpeg
from subprocess import call
import shutil
def export_as_mp3(export_path, y, sr, bitrate='192k'):
tmp_input_path = "/tmp/___mp3___.wav"
tmp_output_path = "/tmp/___mp3___.mp3"
librosa.output.write_wav(tmp_input_path, y, sr)
call(["ffmpeg", "-i", tmp_input_path, "-b:a", str(bitrate), tmp_output_path])
shutil.move(tmp_output_path, export_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment