arroyadr commited on
Commit
2200b46
1 Parent(s): 75ec919

Updated model to spanish

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -9,21 +9,19 @@ from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Proce
9
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
10
 
11
  # load speech translation checkpoint
12
- # asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
13
- asr_pipe = pipeline("automatic-speech-recognition", model="thunninoi/wav2vec2-japanese-vtuber", device=device)
14
 
15
  # load text-to-speech checkpoint and speaker embeddings
16
- processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
17
-
18
- model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts").to(device)
19
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
20
 
21
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
22
  speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
23
 
24
 
25
- def translate(audio):
26
- outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
27
  return outputs["text"]
28
 
29
 
 
9
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
10
 
11
  # load speech translation checkpoint
12
+ asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
 
13
 
14
  # load text-to-speech checkpoint and speaker embeddings
15
+ processor = SpeechT5Processor.from_pretrained("Sandiago21/speecht5_finetuned_facebook_voxpopuli_spanish")
16
+ model = SpeechT5ForTextToSpeech.from_pretrained("Sandiago21/speecht5_finetuned_facebook_voxpopuli_spanish").to(device)
 
17
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
18
 
19
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
20
  speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
21
 
22
 
23
+ def translate(audio, language="es"):
24
+ outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", language=language})
25
  return outputs["text"]
26
 
27