Views
No views yet
| Splits | Backend | S-norm | EER(%) | minDCF(0.01) |
|---|---|---|---|---|
| VoxCeleb1-O | cosine | no | 1.91 | 0.20 |
| VoxCeleb1-E | cosine | no | TBD | TBD |
| VoxCeleb1-H | cosine | no | TBD | TBD |
1import torch
2import torchaudio
3from speechbrain.pretrained.interfaces import Pretrained
4from speechbrain.pretrained import EncoderClassifier
5
6
7class Encoder(Pretrained):
8
9 MODULES_NEEDED = [
10 "compute_features",
11 "mean_var_norm",
12 "embedding_model"
13 ]
14
15 def __init__(self, *args, **kwargs):
16 super().__init__(*args, **kwargs)
17
18 def encode_batch(self, wavs, wav_lens=None, normalize=False):
19 # Manage single waveforms in input
20 if len(wavs.shape) == 1:
21 wavs = wavs.unsqueeze(0)
22
23 # Assign full length if wav_lens is not assigned
24 if wav_lens is None:
25 wav_lens = torch.ones(wavs.shape[0], device=self.device)
26
27 # Storing waveform in the specified device
28 wavs, wav_lens = wavs.to(self.device), wav_lens.to(self.device)
29 wavs = wavs.float()
30
31 # Computing features and embeddings
32 feats = self.mods.compute_features(wavs)
33 feats = self.mods.mean_var_norm(feats, wav_lens)
34 embeddings = self.mods.embedding_model(feats, wav_lens)
35 if normalize:
36 embeddings = self.hparams.mean_var_norm_emb(
37 embeddings,
38 torch.ones(embeddings.shape[0], device=self.device)
39 )
40 return embeddings
41
42
43classifier = Encoder.from_hparams(
44 source="yangwang825/etdnn-vox2"
45)
46signal, fs = torchaudio.load('spk1_snt1.wav')
47embeddings = classifier.encode_batch(signal)
48>>> torch.Size([1, 1, 192])