Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Proce
|
|
10 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
11 |
|
12 |
# load speech translation checkpoint
|
13 |
-
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-
|
14 |
|
15 |
# load text-to-speech checkpoint and speaker embeddings
|
16 |
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
@@ -21,11 +21,13 @@ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(devic
|
|
21 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
22 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
23 |
|
|
|
|
|
24 |
|
25 |
def translate(audio):
|
26 |
-
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe"
|
27 |
-
|
28 |
-
|
29 |
|
30 |
def synthesise(text):
|
31 |
inputs = processor(text=text, return_tensors="pt")
|
|
|
10 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
11 |
|
12 |
# load speech translation checkpoint
|
13 |
+
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
|
14 |
|
15 |
# load text-to-speech checkpoint and speaker embeddings
|
16 |
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
|
|
21 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
22 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
23 |
|
24 |
+
# load text en-ru translation model
|
25 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ru", device=device)
|
26 |
|
27 |
def translate(audio):
|
28 |
+
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe"})
|
29 |
+
translated_text = translator(outputs["text"])
|
30 |
+
return translated_text[0]['translation_text']
|
31 |
|
32 |
def synthesise(text):
|
33 |
inputs = processor(text=text, return_tensors="pt")
|