Skip to content
Snippets Groups Projects
Commit 28f798f2 authored by Sebastião Quintas's avatar Sebastião Quintas
Browse files

First commit

parents
No related branches found
No related tags found
Loading
Showing
with 108 additions and 0 deletions
# PATHS
wav_path: '../data/wavs/'
embedding_path: '../data/embeddings/'
# PARAMETERS
sampling_rate: 16000
batch_size: 16
learning_rate: 0.001
# Types of embeddings supported: 'ecapa_tdnn' or 'x-vector'
embedding_type: ecapa_tdnn
File added
File added
File added
File added
File added
File added
File added
File added
File added
sjfnjsdnf
import torchaudio
import torch
import sys
import os
import yaml
from speechbrain.pretrained import EncoderClassifier
from tqdm import tqdm
# LOADS CONFIGURATION .YAML FILE
def load_config(config_path):
try:
with open(config_path, 'r') as file:
config = yaml.safe_load(file)
return config
except Exception as e:
print('Error reading the config file')
# RETURNS THE EMBEDDING EXTRACTO
# TWO SUPPORTED TYPES: X-VECTORS AND ECAPA_TDNN
def embedding_type():
if config['embedding_type'] == 'x-vector':
classifier = EncoderClassifier.from_hparams(source=\
"speechbrain/spkrec-xvect-voxceleb", savedir=\
"pretrained_models/spkrec-xvect-voxceleb")
extension = 'xvec'
elif config['embedding_type'] == 'ecapa_tdnn':
classifier = EncoderClassifier.from_hparams(source=\
"speechbrain/spkrec-ecapa-voxceleb", savedir=\
"pretrained_models/spkrec-ecapatdnn-voxceleb")
extension = 'ecapa'
else:
print('Unknown embedding type')
sys.exit()
return classifier, extension
# EXTRACTS THE SPEAKER EMBEDDING BASED ON THE USED CLASSIFIER
# CLASSIFIERS OBTAINED FROM HUGGINGFACE
def extractor(wavfile, classifier):
signal, fs =torchaudio.load(wavfile)
embedding = classifier.encode_batch(signal)
return embedding
if __name__=="__main__":
config_path = '../configs/parameters.yaml'
config = load_config(config_path)
extraction_files = os.listdir(config['wav_path'])
classifier, ext = embedding_type()
saving_path = config['embedding_path']+ext+'/'
# CREATES SPECIFIC EMBEDDING SUBDIR IF IT DOESN'T EXIST
if not os.path.exists(saving_path):
os.makedirs(saving_path)
print("\nExtracting speaker embeddings...")
with tqdm(total=len(extraction_files)) as pbar:
for files in os.listdir(config['wav_path']):
if files.endswith('.wav'):
embedding = extractor(config['wav_path'] + files, classifier)
buf = os.path.splitext(files)
new_f = buf[0]+'_'+ext+'_emb.pickle'
torch.save(embedding, saving_path+new_f)
pbar.update(1)
else:
pbar.update(1)
continue
/home/squintas/.cache/huggingface/hub/models--speechbrain--spkrec-ecapa-voxceleb/snapshots/5c0be3875fda05e81f3c004ed8c7c06be308de1e/classifier.ckpt
\ No newline at end of file
/home/squintas/.cache/huggingface/hub/models--speechbrain--spkrec-ecapa-voxceleb/snapshots/5c0be3875fda05e81f3c004ed8c7c06be308de1e/embedding_model.ckpt
\ No newline at end of file
/home/squintas/.cache/huggingface/hub/models--speechbrain--spkrec-ecapa-voxceleb/snapshots/5c0be3875fda05e81f3c004ed8c7c06be308de1e/hyperparams.yaml
\ No newline at end of file
/home/squintas/.cache/huggingface/hub/models--speechbrain--spkrec-ecapa-voxceleb/snapshots/5c0be3875fda05e81f3c004ed8c7c06be308de1e/label_encoder.txt
\ No newline at end of file
/home/squintas/.cache/huggingface/hub/models--speechbrain--spkrec-ecapa-voxceleb/snapshots/5c0be3875fda05e81f3c004ed8c7c06be308de1e/mean_var_norm_emb.ckpt
\ No newline at end of file
/home/squintas/.cache/huggingface/hub/models--speechbrain--spkrec-xvect-voxceleb/snapshots/e2cc27f853f99bd5d539432f0cba3f124c059f71/classifier.ckpt
\ No newline at end of file
/home/squintas/.cache/huggingface/hub/models--speechbrain--spkrec-xvect-voxceleb/snapshots/e2cc27f853f99bd5d539432f0cba3f124c059f71/embedding_model.ckpt
\ No newline at end of file
/home/squintas/.cache/huggingface/hub/models--speechbrain--spkrec-xvect-voxceleb/snapshots/e2cc27f853f99bd5d539432f0cba3f124c059f71/hyperparams.yaml
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment