elizabetvaganova
commited on
Commit
•
551adb2
1
Parent(s):
986912d
Update app.py
Browse files
app.py
CHANGED
@@ -2,35 +2,26 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
from datasets import load_dataset
|
5 |
-
|
6 |
-
from transformers import
|
7 |
|
8 |
|
9 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
# load speech translation checkpoint
|
12 |
-
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-
|
13 |
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
-
|
16 |
-
|
17 |
-
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts").to(device)
|
18 |
-
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
|
19 |
-
|
20 |
-
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
21 |
-
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
22 |
-
|
23 |
|
24 |
def translate(audio):
|
25 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
|
26 |
return outputs["text"]
|
27 |
|
28 |
-
|
29 |
def synthesise(text):
|
30 |
-
|
31 |
-
|
32 |
-
return
|
33 |
-
|
34 |
|
35 |
def speech_to_speech_translation(audio):
|
36 |
translated_text = translate(audio)
|
|
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
from datasets import load_dataset
|
5 |
+
from espnet2.bin.tts_inference import Text2Speech
|
6 |
+
from transformers import pipeline
|
7 |
|
8 |
|
9 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
# load speech translation checkpoint
|
12 |
+
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-tiny", device=device)
|
13 |
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
+
tts_model = Text2Speech.from_pretrained("espnet/kan-bayashi_ljspeech_tts_train_tacotron2_raw_phn_tacotron_g2p_en_no_space_train.loss.best")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
def translate(audio):
|
18 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
|
19 |
return outputs["text"]
|
20 |
|
|
|
21 |
def synthesise(text):
|
22 |
+
with torch.no_grad():
|
23 |
+
wav = tts_model(text)["wav"]
|
24 |
+
return wav.view(-1).cpu()
|
|
|
25 |
|
26 |
def speech_to_speech_translation(audio):
|
27 |
translated_text = translate(audio)
|