vladelesin
commited on
Commit
•
d771f86
1
Parent(s):
ecfd58a
Update app.py
Browse files
app.py
CHANGED
@@ -17,19 +17,23 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
17 |
asr_pipe = pipeline("automatic-speech-recognition", model="asapp/sew-d-mid-400k-ft-ls100h", device=device)
|
18 |
|
19 |
# Translate en to rus text
|
20 |
-
translation_en_to_rus = pipeline("translation", model="
|
21 |
|
22 |
# Create speech from rus text
|
23 |
-
vits_model = VitsModel.from_pretrained("
|
24 |
-
vits_tokenizer = VitsTokenizer.from_pretrained("
|
|
|
|
|
|
|
25 |
|
26 |
def transform_audio_to_speech_en(audio):
|
27 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
|
28 |
return outputs["text"]
|
29 |
|
30 |
def translator(text):
|
31 |
-
|
32 |
-
|
|
|
33 |
|
34 |
def synthesise(translated_text):
|
35 |
translated_text = translator(translated_text)
|
|
|
17 |
asr_pipe = pipeline("automatic-speech-recognition", model="asapp/sew-d-mid-400k-ft-ls100h", device=device)
|
18 |
|
19 |
# Translate en to rus text
|
20 |
+
translation_en_to_rus = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ru")
|
21 |
|
22 |
# Create speech from rus text
|
23 |
+
#vits_model = VitsModel.from_pretrained("Helsinki-NLP/opus-mt-ru-en")
|
24 |
+
#vits_tokenizer = VitsTokenizer.from_pretrained("Helsinki-NLP/opus-mt-ru-en")
|
25 |
+
|
26 |
+
model = MarianMTModel.from_pretrained("Helsinki-NLP/opus-mt-ru-en")
|
27 |
+
tokenizer = MarianTokenizer.from_pretrained("Helsinki-NLP/opus-mt-ru-en")
|
28 |
|
29 |
def transform_audio_to_speech_en(audio):
|
30 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
|
31 |
return outputs["text"]
|
32 |
|
33 |
def translator(text):
|
34 |
+
translated = translator_model.generate(**translator_tokenizer(text, return_tensors="pt", padding=True))
|
35 |
+
translated_text = translator_tokenizer.decode(translated[0], skip_special_tokens=True)
|
36 |
+
return translated_text
|
37 |
|
38 |
def synthesise(translated_text):
|
39 |
translated_text = translator(translated_text)
|