Created
January 17, 2021 13:35
-
-
Save ankurdhuriya/f424195a8a565e2985e3691b8317b78b to your computer and use it in GitHub Desktop.
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 pydub import AudioSegement | |
def load_audio(audio_path, ext): | |
return AudioSegement.from_file(audio_path, format=ext) | |
def speed_change(audio, speed): | |
audio_with_altered_frame_rate = audio._spawn( | |
audio.raw_data, overrides={ | |
"frame_rate": int(audio.frame_rate * speed) | |
}) | |
return audio_with_altered_frame_rate.set_frame_rate(audio.frame_rate) | |
def save_audio(audio, save_path, ext='wav'): | |
return audio.export(save_path, format=ext) | |
def main(audio_path, ext, speed): | |
audio = load_audio(audio_path, ext) | |
new_audio = speed_change(audio, speed) | |
save_audio(audio, './out.wav', ext) | |
if __name__ == '__main__': | |
ext = 'wav' | |
audio_path = '/audio_file.wav' | |
speed=1.5 | |
main(audio_path, ext, speed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment