divakaivan commited on
Commit
ff917b6
1 Parent(s): 648fba4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -43,6 +43,18 @@ def synthesize_speech(text):
43
  return (16000, speech)
44
 
45
  def create_speaker_embedding(waveform):
 
 
 
 
 
 
 
 
 
 
 
 
46
  with torch.no_grad():
47
  speaker_embeddings = speaker_model.encode_batch(torch.tensor(waveform))
48
  speaker_embeddings = torch.nn.functional.normalize(speaker_embeddings, dim=2)
 
43
  return (16000, speech)
44
 
45
  def create_speaker_embedding(waveform):
46
+
47
+ import os
48
+ from speechbrain.inference.speaker import EncoderClassifier
49
+
50
+ spk_model_name = "speechbrain/spkrec-xvect-voxceleb"
51
+
52
+ device = "cuda" if torch.cuda.is_available() else "cpu"
53
+ speaker_model = EncoderClassifier.from_hparams(
54
+ source=spk_model_name,
55
+ run_opts={"device": device},
56
+ savedir=os.path.join("/tmp", spk_model_name),
57
+ )
58
  with torch.no_grad():
59
  speaker_embeddings = speaker_model.encode_batch(torch.tensor(waveform))
60
  speaker_embeddings = torch.nn.functional.normalize(speaker_embeddings, dim=2)