model-man commited on
Commit
403e974
1 Parent(s): bbc2e31

changed to run speecht5

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -3,19 +3,25 @@ import numpy as np
3
  import torch
4
  from datasets import load_dataset
5
 
6
- from transformers import VitsModel, VitsTokenizer, pipeline
7
-
8
 
9
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
10
 
 
 
 
11
  # load speech translation checkpoint
12
  pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
13
 
14
  # load text-to-speech checkpoint for MMS
15
- model = VitsModel.from_pretrained("Matthijs/mms-tts-fra")
16
- tokenizer = VitsTokenizer.from_pretrained("Matthijs/mms-tts-fra")
17
 
 
18
 
 
 
19
 
20
  def translate(audio):
21
  outputs = pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", "language": "fr"})
@@ -23,9 +29,9 @@ def translate(audio):
23
 
24
 
25
  def synthesise(text):
26
- inputs = tokenizer(text=text, return_tensors="pt")
27
- speech = model(inputs["input_ids"].to(device))
28
- return speech.audio[0].cpu()
29
 
30
 
31
  def speech_to_speech_translation(audio):
 
3
  import torch
4
  from datasets import load_dataset
5
 
6
+ #from transformers import VitsModel, VitsTokenizer, pipeline
7
+ from transformers import pipeline, SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
8
 
9
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
10
 
11
+ embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
12
+ speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
13
+
14
  # load speech translation checkpoint
15
  pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
16
 
17
  # load text-to-speech checkpoint for MMS
18
+ # model = VitsModel.from_pretrained("Matthijs/mms-tts-fra")
19
+ # tokenizer = VitsTokenizer.from_pretrained("Matthijs/mms-tts-fra")
20
 
21
+ processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
22
 
23
+ model = SpeechT5ForTextToSpeech.from_pretrained("Sandiago21/speecht5_finetuned_facebook_voxpopuli_french")
24
+ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
25
 
26
  def translate(audio):
27
  outputs = pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", "language": "fr"})
 
29
 
30
 
31
  def synthesise(text):
32
+ inputs = processor(text=text, return_tensors="pt")
33
+ speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
34
+ return speech.cpu()
35
 
36
 
37
  def speech_to_speech_translation(audio):