Skip to content

Instantly share code, notes, and snippets.

@naotokui
Created January 14, 2018 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naotokui/ae3f63d25eff9d7afeefe0c0c0ed9702 to your computer and use it in GitHub Desktop.
Save naotokui/ae3f63d25eff9d7afeefe0c0c0ed9702 to your computer and use it in GitHub Desktop.
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