Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
from transformers import pipeline, VitsModel, AutoTokenizer, AutoTokenizer
|
|
|
5 |
|
6 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
7 |
|
@@ -42,8 +43,19 @@ translation_models = {
|
|
42 |
|
43 |
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
|
44 |
|
45 |
-
vist_model = VitsModel.from_pretrained("facebook/mms-tts-spa")
|
46 |
-
vist_tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-spa")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
lang_detector = pipeline("text-classification", model="papluca/xlm-roberta-base-language-detection")
|
49 |
|
@@ -73,16 +85,18 @@ def synthesise(text):
|
|
73 |
else:
|
74 |
text = text
|
75 |
print(text)
|
76 |
-
inputs =
|
77 |
-
|
78 |
-
output = vist_model(**inputs).waveform[0]
|
79 |
return output
|
80 |
|
81 |
def speech_to_speech_translation(audio):
|
82 |
translated_text = translate(audio)
|
83 |
synthesised_speech = synthesise(translated_text)
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
86 |
|
87 |
title = "Cascaded STST"
|
88 |
description = """
|
|
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
from transformers import pipeline, VitsModel, AutoTokenizer, AutoTokenizer
|
5 |
+
from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor
|
6 |
|
7 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
8 |
|
|
|
43 |
|
44 |
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
|
45 |
|
46 |
+
#vist_model = VitsModel.from_pretrained("facebook/mms-tts-spa")
|
47 |
+
#vist_tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-spa")
|
48 |
+
|
49 |
+
|
50 |
+
model = SpeechT5ForTextToSpeech.from_pretrained(
|
51 |
+
"juangtzi/speecht5_finetuned_voxpopuli_es"
|
52 |
+
)
|
53 |
+
checkpoint = "microsoft/speecht5_tts"
|
54 |
+
processor = SpeechT5Processor.from_pretrained(checkpoint)
|
55 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
56 |
+
|
57 |
+
speaker_embeddings2 = np.load('speaker_embeddings.npy')
|
58 |
+
speaker_embeddings2 = torch.tensor(speaker_embeddings2)
|
59 |
|
60 |
lang_detector = pipeline("text-classification", model="papluca/xlm-roberta-base-language-detection")
|
61 |
|
|
|
85 |
else:
|
86 |
text = text
|
87 |
print(text)
|
88 |
+
inputs = processor(text, return_tensors="pt")
|
89 |
+
output = model.generate_speech(inputs["input_ids"], speaker_embeddings2, vocoder=vocoder)
|
|
|
90 |
return output
|
91 |
|
92 |
def speech_to_speech_translation(audio):
|
93 |
translated_text = translate(audio)
|
94 |
synthesised_speech = synthesise(translated_text)
|
95 |
+
audio_data = synthesised_speech.cpu().numpy()
|
96 |
+
audio_data = np.squeeze(audio_data)
|
97 |
+
audio_data = audio_data / np.max(np.abs(audio_data))
|
98 |
+
sample_rate = 16000
|
99 |
+
return (sample_rate, audio_data)
|
100 |
|
101 |
title = "Cascaded STST"
|
102 |
description = """
|