Skip to content
Snippets Groups Projects
Commit 3175caeb authored by Elquintas's avatar Elquintas
Browse files

second commit?

parent 28f798f2
Branches
No related tags found
No related merge requests found
File added
File added
File added
File added
File added
File added
...@@ -61,12 +61,15 @@ if __name__=="__main__": ...@@ -61,12 +61,15 @@ if __name__=="__main__":
if not os.path.exists(saving_path): if not os.path.exists(saving_path):
os.makedirs(saving_path) os.makedirs(saving_path)
# GENERATES TWO EMBEDDINGS [2,1,DIM] IF FILE IS IN STEREO
# GENERATES ONE EMBEDDING [1,1,DIM] IF FILE IS IN MONO
print("\nExtracting speaker embeddings...") print("\nExtracting speaker embeddings...")
with tqdm(total=len(extraction_files)) as pbar: with tqdm(total=len(extraction_files)) as pbar:
for files in os.listdir(config['wav_path']): for files in os.listdir(config['wav_path']):
if files.endswith('.wav'): if files.endswith('.wav'):
embedding = extractor(config['wav_path'] + files, classifier) embedding = extractor((config['wav_path'] + \
files), classifier)
buf = os.path.splitext(files) buf = os.path.splitext(files)
new_f = buf[0]+'_'+ext+'_emb.pickle' new_f = buf[0]+'_'+ext+'_emb.pickle'
......
from pydub import AudioSegment
import os
import sys
import wave
import contextlib
from tqdm import tqdm
fname = AudioSegment.from_wav("./file1.wav")
# RETURNS THE DURATION OF AN AUDIOFILE IN MILISECS
def get_file_duration(wavfile):
with contextlib.closing(wave.open(wavfile,'r')) as f:
frames = f.getnframes()
rate = f.getframerate()
duration = frames / float(rate)
return duration*1000 # DURATION IN MILISECS FOR AUDIOSEGMENT
# SEGMENTS THE AUDIO FILE IN EQUAL LENGTH SEGMENTS
def segmenter(wavpath, wavfile, segs, savepath):
duration = get_file_duration(wavpath+wavfile)
buf = os.path.splitext(wavfile)
i = 1
j = 0
tblock = duration/segs
while (j+tblock) <= duration:
newAudio = AudioSegment.from_wav(wavpath+wavfile)
newAudio = fname[j:j+tblock]
newAudio.export(savepath+buf[0]+'_seg'+\
str(i)+'.wav', format='wav')
j += tblock
i += 1
if __name__=="__main__":
segments = 3
wavfile = './file1.wav'
wav_path = '../data/wavs/'
saving_path = '../data/wavs/segmented/'
if not os.path.exists(saving_path):
os.makedirs(saving_path)
total_files = os.listdir(wav_path)
with tqdm(total=len(total_files)) as pbar:
for files in os.listdir(wav_path):
if files.endswith('.wav'):
segmenter(wav_path,files,segments,saving_path)
pbar.update(1)
else:
pbar.update(1)
continue
#segmenter(wavfile, segments)
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment