Use 3 stage cascade for better results
Browse files
app.py
CHANGED
@@ -4,14 +4,18 @@ import numpy as np
|
|
4 |
import torch
|
5 |
|
6 |
from transformers import VitsModel, VitsTokenizer, pipeline
|
|
|
|
|
7 |
|
8 |
|
9 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
-
target_language = "
|
12 |
|
13 |
# load speech translation checkpoint
|
14 |
asr_pipe = pipeline("automatic-speech-recognition", model="bofenghuang/whisper-small-cv11-french", device=device)
|
|
|
|
|
15 |
|
16 |
# load text-to-speech checkpoint
|
17 |
model = VitsModel.from_pretrained("facebook/mms-tts-fra")
|
@@ -19,8 +23,11 @@ tokenizer = VitsTokenizer.from_pretrained("facebook/mms-tts-fra")
|
|
19 |
|
20 |
|
21 |
def translate(audio):
|
22 |
-
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
|
26 |
def synthesise(text):
|
|
|
4 |
import torch
|
5 |
|
6 |
from transformers import VitsModel, VitsTokenizer, pipeline
|
7 |
+
from transformers import M2M100ForConditionalGeneration
|
8 |
+
from tokenization_small100 import SMALL100Tokenizer
|
9 |
|
10 |
|
11 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
12 |
|
13 |
+
target_language = "fr"
|
14 |
|
15 |
# load speech translation checkpoint
|
16 |
asr_pipe = pipeline("automatic-speech-recognition", model="bofenghuang/whisper-small-cv11-french", device=device)
|
17 |
+
translation_model = M2M100ForConditionalGeneration.from_pretrained("alirezamsh/small100", device=device)
|
18 |
+
translation_tokenizer = SMALL100Tokenizer.from_pretrained("alirezamsh/small100", tgt_lang=target_language)
|
19 |
|
20 |
# load text-to-speech checkpoint
|
21 |
model = VitsModel.from_pretrained("facebook/mms-tts-fra")
|
|
|
23 |
|
24 |
|
25 |
def translate(audio):
|
26 |
+
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
|
27 |
+
eng_text = outputs["text"]
|
28 |
+
encoded_eng_text = translation_tokenizer(eng_text, return_tensors="pt")
|
29 |
+
generated_tokens = translation_model(**encoded_eng_text)
|
30 |
+
return translation_tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
31 |
|
32 |
|
33 |
def synthesise(text):
|