Created
August 21, 2020 12:17
-
-
Save LewisGet/c4ab304bc55641a3718825195a068d6d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AudioSegment | |
import numpy as np | |
import config | |
file_index = str(1) | |
audio = AudioSegment.from_file(config.resource_path("%s.wav" % file_index)) | |
audio = audio.set_channels(1) | |
raw_data = audio.raw_data | |
frame_rate = audio.frame_rate | |
def pitch_shifting(audio, value): | |
rate = int(frame_rate * (2.0 ** value)) | |
if rate == 0: | |
return audio | |
pitch_name = "down" | |
if value > 0: | |
pitch_name = "up" | |
file_name = config.resource_path("%s_%s_%s.wav" % (file_index, pitch_name, str(x))) | |
tmp_audio = audio._spawn(raw_data, overrides={'frame_rate': rate}) | |
tmp_audio.export(file_name, format="wav") | |
return tmp_audio | |
new_audio = list() | |
raw_data = audio.raw_data | |
frame_rate = audio.frame_rate | |
for i in range(-10, 10): | |
x = i / 10 | |
new_audio.append(pitch_shifting(audio, x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment