#Harshita Gangaswamy

from pydub import AudioSegment
from pydub.playback import play
from os import path
import sys
import os


dstPath = '/home/ubuntu/DeepSpeech/data/audiosinc/dst'

if( len(sys.argv) < 2 ):
    sys.exit(os.EX_OK)

file = sys.argv[1]

sound = AudioSegment.from_file(file, format="wav")

# shift the pitch up by half an octave (speed will increase proportionally)
octaves = 0.25

new_sample_rate = int(sound.frame_rate * (2 ** octaves))

# keep the same samples but tell the computer they ought to be played at the
# new, higher sample rate. This file sounds like a chipmunk but has a weird sample rate.
hipitch_sound = sound._spawn(sound.raw_data, overrides={'frame_rate': new_sample_rate})

# now we just convert it to a common sample rate (44.1k - standard audio CD) to
# make sure it works in regular audio players. Other than potentially losing audio quality (if
# you set it too low - 44.1k is plenty) this should now noticeable change how the audio sounds.
hipitch_sound = hipitch_sound.set_frame_rate(16000)

#Play pitch changed sound
#play(hipitch_sound)

#export / save pitch changed sound
hipitch_sound.export("out.wav", format="wav")
