Commit
·
3e3f8b6
1
Parent(s):
5bd1eec
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,15 @@ 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 |
|
@@ -14,7 +21,10 @@ asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base",
|
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
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")
|
@@ -27,9 +37,18 @@ def translate(audio):
|
|
27 |
|
28 |
|
29 |
def synthesise(text):
|
30 |
-
inputs = processor(text=text, return_tensors="pt")
|
31 |
-
speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
def speech_to_speech_translation(audio):
|
@@ -43,7 +62,6 @@ title = "Cascaded STST"
|
|
43 |
description = """
|
44 |
Demo for cascaded speech-to-speech translation (STST), mapping from source speech in any language to target speech in English. Demo uses OpenAI's [Whisper Base](https://huggingface.co/openai/whisper-base) model for speech translation, and Microsoft's
|
45 |
[SpeechT5 TTS](https://huggingface.co/microsoft/speecht5_tts) model for text-to-speech:
|
46 |
-
|
47 |

|
48 |
"""
|
49 |
|
@@ -69,4 +87,4 @@ file_translate = gr.Interface(
|
|
69 |
with demo:
|
70 |
gr.TabbedInterface([mic_translate, file_translate], ["Microphone", "Audio File"])
|
71 |
|
72 |
-
demo.launch()
|
|
|
3 |
import torch
|
4 |
from datasets import load_dataset
|
5 |
|
6 |
+
from transformers import (
|
7 |
+
SpeechT5ForTextToSpeech,
|
8 |
+
SpeechT5HifiGan,
|
9 |
+
SpeechT5Processor,
|
10 |
+
VitsModel,
|
11 |
+
VitsTokenizer,
|
12 |
+
pipeline
|
13 |
+
)
|
14 |
+
from transformers import VitsModel, VitsTokenizer
|
15 |
|
16 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
17 |
|
|
|
21 |
# load text-to-speech checkpoint and speaker embeddings
|
22 |
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
23 |
|
24 |
+
# model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts").to(device)
|
25 |
+
model = VitsModel.from_pretrained("Matthijs/mms-tts-nld")
|
26 |
+
tokenizer = VitsTokenizer.from_pretrained("Matthijs/mms-tts-nld")
|
27 |
+
|
28 |
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
|
29 |
|
30 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
|
|
37 |
|
38 |
|
39 |
def synthesise(text):
|
40 |
+
# inputs = processor(text=text, return_tensors="pt")
|
41 |
+
# speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
|
42 |
+
# speech = speech.cpu()
|
43 |
+
|
44 |
+
inputs = tokenizer(text, return_tensors="pt")
|
45 |
+
input_ids = inputs["input_ids"]
|
46 |
+
|
47 |
+
with torch.no_grad():
|
48 |
+
outputs = model(input_ids)
|
49 |
+
|
50 |
+
speech = outputs.audio[0].cpu()
|
51 |
+
return speech
|
52 |
|
53 |
|
54 |
def speech_to_speech_translation(audio):
|
|
|
62 |
description = """
|
63 |
Demo for cascaded speech-to-speech translation (STST), mapping from source speech in any language to target speech in English. Demo uses OpenAI's [Whisper Base](https://huggingface.co/openai/whisper-base) model for speech translation, and Microsoft's
|
64 |
[SpeechT5 TTS](https://huggingface.co/microsoft/speecht5_tts) model for text-to-speech:
|
|
|
65 |

|
66 |
"""
|
67 |
|
|
|
87 |
with demo:
|
88 |
gr.TabbedInterface([mic_translate, file_translate], ["Microphone", "Audio File"])
|
89 |
|
90 |
+
demo.launch()
|