Antoine101
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -14,10 +14,10 @@ asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base",
|
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
model = VitsModel.from_pretrained("facebook/mms-tts-fra")
|
20 |
-
tokenizer = VitsTokenizer.from_pretrained("facebook/mms-tts-fra")
|
21 |
|
22 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
23 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
@@ -29,17 +29,19 @@ def translate(audio):
|
|
29 |
|
30 |
|
31 |
def synthesise(text):
|
32 |
-
|
33 |
-
|
34 |
-
inputs = tokenizer(text, return_tensors="pt")
|
35 |
-
speech = model(inputs["input_ids"])
|
36 |
-
|
|
|
37 |
|
38 |
|
39 |
def speech_to_speech_translation(audio):
|
40 |
translated_text = translate(audio)
|
41 |
synthesised_speech = synthesise(translated_text)
|
42 |
-
synthesised_speech = (synthesised_speech.detach().numpy() * 32767).astype(np.int16)
|
|
|
43 |
return 16000, synthesised_speech
|
44 |
|
45 |
|
|
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
16 |
|
17 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts").to(device)
|
18 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
|
19 |
+
#model = VitsModel.from_pretrained("facebook/mms-tts-fra")
|
20 |
+
#tokenizer = VitsTokenizer.from_pretrained("facebook/mms-tts-fra")
|
21 |
|
22 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
23 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
|
|
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 |
+
#inputs = tokenizer(text, return_tensors="pt")
|
35 |
+
#speech = model(inputs["input_ids"])
|
36 |
+
#output = speech["waveform"]
|
37 |
+
return speech
|
38 |
|
39 |
|
40 |
def speech_to_speech_translation(audio):
|
41 |
translated_text = translate(audio)
|
42 |
synthesised_speech = synthesise(translated_text)
|
43 |
+
#synthesised_speech = (synthesised_speech.detach().numpy() * 32767).astype(np.int16)
|
44 |
+
synthesised_speech = (synthesised_speech.numpy() * 32767).astype(np.int16)
|
45 |
return 16000, synthesised_speech
|
46 |
|
47 |
|