Skip to content

Instantly share code, notes, and snippets.

@Vages
Last active November 9, 2018 20:59
Show Gist options
  • Save Vages/8069ce6b5908844305e278072a1654c6 to your computer and use it in GitHub Desktop.
Save Vages/8069ce6b5908844305e278072a1654c6 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python3
"""
Requires you to install ffmpeg with all options (or at least the rubberband module):
https://gist.github.com/Piasy/b5dfd5c048eb69d1b91719988c0325d8#gistcomment-2571754
Example usage:
$ ./convert_pitch_by_semitones.py /input.mp3 /output.mp3 -2
"""
import sys
import subprocess
from math import pow
[_, input_file, output_file, semitones] = sys.argv
actual_pitch_difference = pow(2, (int(semitones) / 12))
subprocess.run(["ffmpeg", "-i", input_file, "-af", "rubberband=pitch=%.2f:pitchq=quality" % (actual_pitch_difference,), "-vn", output_file])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment