Update app.py
Browse files
app.py
CHANGED
@@ -21,52 +21,55 @@ embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validat
|
|
21 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
22 |
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
)
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
demo
|
|
|
|
|
|
|
|
21 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
22 |
|
23 |
|
24 |
+
print(speaker_embeddings.shape)
|
25 |
+
|
26 |
+
if 0:
|
27 |
+
def translate(audio):
|
28 |
+
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
|
29 |
+
return outputs["text"]
|
30 |
+
|
31 |
+
|
32 |
+
def synthesise(text):
|
33 |
+
inputs = processor(text=text, return_tensors="pt")
|
34 |
+
speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
|
35 |
+
return speech.cpu()
|
36 |
+
|
37 |
+
|
38 |
+
def speech_to_speech_translation(audio):
|
39 |
+
translated_text = translate(audio)
|
40 |
+
synthesised_speech = synthesise(translated_text)
|
41 |
+
synthesised_speech = (synthesised_speech.numpy() * 32767).astype(np.int16)
|
42 |
+
return 16000, synthesised_speech
|
43 |
+
|
44 |
+
|
45 |
+
title = "Cascaded STST"
|
46 |
+
description = """
|
47 |
+
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
|
48 |
+
[SpeechT5 TTS](https://huggingface.co/microsoft/speecht5_tts) model for text-to-speech:
|
49 |
+
|
50 |
+
![Cascaded STST](https://huggingface.co/datasets/huggingface-course/audio-course-images/resolve/main/s2st_cascaded.png "Diagram of cascaded speech to speech translation")
|
51 |
+
"""
|
52 |
+
|
53 |
+
demo = gr.Blocks()
|
54 |
+
|
55 |
+
mic_translate = gr.Interface(
|
56 |
+
fn=speech_to_speech_translation,
|
57 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
58 |
+
outputs=gr.Audio(label="Generated Speech", type="numpy"),
|
59 |
+
title=title,
|
60 |
+
description=description,
|
61 |
+
)
|
62 |
+
|
63 |
+
file_translate = gr.Interface(
|
64 |
+
fn=speech_to_speech_translation,
|
65 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
66 |
+
outputs=gr.Audio(label="Generated Speech", type="numpy"),
|
67 |
+
examples=[["./example.wav"]],
|
68 |
+
title=title,
|
69 |
+
description=description,
|
70 |
+
)
|
71 |
+
|
72 |
+
with demo:
|
73 |
+
gr.TabbedInterface([mic_translate, file_translate], ["Microphone", "Audio File"])
|
74 |
+
|
75 |
+
demo.launch()
|