Created
October 30, 2019 03:41
-
-
Save grohith327/2f9121157039840a77b5d527e2313f06 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
import os | |
import librosa | |
import random | |
for files in os.listdir('./Dataset'): | |
count = 21 | |
for comm in os.listdir('./Dataset/'+str(files)): | |
sound = AudioSegment.from_file('./Dataset/'+str(files)+'/'+str(comm)) | |
halfway_point = len(sound) // 2 | |
for _ in range(10): | |
val = random.randint(1, halfway_point) | |
crop_audio = sound[val:val+halfway_point] | |
crop_audio.export('test.wav',format='wav') | |
data, sf = librosa.load('test.wav') | |
new_crop = np.pad(data,(0,22026),'constant') # Pad data so that the duration matches (2 Sec) | |
librosa.output.write_wav('./Dataset/'+str(files)+'/'+str(count)+'.wav',new_crop,sf) | |
count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey 👋