Created
January 14, 2018 05:54
-
-
Save naotokui/ae3f63d25eff9d7afeefe0c0c0ed9702 to your computer and use it in GitHub Desktop.
export mp3 in python using ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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