Joserzapata commited on
Commit
301c110
1 Parent(s): e8edcc6

add de translation

Browse files

update translate and synthesise

Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -20,13 +20,19 @@ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(devic
20
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
21
  speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
22
 
 
 
23
 
24
  def translate(audio):
25
- outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
26
  return outputs["text"]
27
 
28
 
29
  def synthesise(text):
 
 
 
 
30
  inputs = processor(text=text, return_tensors="pt")
31
  speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
32
  return speech.cpu()
 
20
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
21
  speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
22
 
23
+ model_mms = VitsModel.from_pretrained("Matthijs/mms-tts-deu").to(device)
24
+ tokenizer_mms = VitsTokenizer.from_pretrained("Matthijs/mms-tts-deu")
25
 
26
  def translate(audio):
27
+ outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", "language": "de"})
28
  return outputs["text"]
29
 
30
 
31
  def synthesise(text):
32
+ inputs = tokenizer_mms(text, return_tensors="pt")
33
+ input_ids = inputs["input_ids"]
34
+ with torch.no_grad():
35
+ outputs = model_mms(input_ids)
36
  inputs = processor(text=text, return_tensors="pt")
37
  speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
38
  return speech.cpu()