Commit
·
f4703fc
1
Parent(s):
c63bae6
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
from datasets import load_dataset
|
5 |
-
|
6 |
from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor, pipeline
|
7 |
|
8 |
|
@@ -12,7 +11,7 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
12 |
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
|
13 |
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
-
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts"
|
16 |
|
17 |
model = SpeechT5ForTextToSpeech.from_pretrained("Sandiago21/speecht5_finetuned_facebook_voxpopuli_french").to(device)
|
18 |
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
|
@@ -21,9 +20,13 @@ def npy_loader(path):
|
|
21 |
np_sample = np.transpose(np.load(path))
|
22 |
sample = torch.from_numpy(np_sample)
|
23 |
return sample
|
24 |
-
|
25 |
-
|
26 |
-
speaker_embeddings = torch.tensor(
|
|
|
|
|
|
|
|
|
27 |
|
28 |
|
29 |
def translate(audio):
|
@@ -39,6 +42,7 @@ def synthesise(text):
|
|
39 |
|
40 |
def speech_to_speech_translation(audio):
|
41 |
translated_text = translate(audio)
|
|
|
42 |
synthesised_speech = synthesise(translated_text)
|
43 |
synthesised_speech = (synthesised_speech.numpy() * 32767).astype(np.int16)
|
44 |
return 16000, synthesised_speech
|
@@ -46,8 +50,8 @@ def speech_to_speech_translation(audio):
|
|
46 |
|
47 |
title = "Cascaded STST"
|
48 |
description = """
|
49 |
-
Demo for cascaded speech-to-speech translation (STST), mapping from source speech in any language to target speech in
|
50 |
-
[SpeechT5 TTS](https://huggingface.co/microsoft/speecht5_tts) model for text-to-speech:
|
51 |
|
52 |

|
53 |
"""
|
|
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
from datasets import load_dataset
|
|
|
5 |
from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor, pipeline
|
6 |
|
7 |
|
|
|
11 |
asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
|
12 |
|
13 |
# load text-to-speech checkpoint and speaker embeddings
|
14 |
+
processor = SpeechT5Processor.from_pretrained("Sandiago21/speecht5_finetuned_facebook_voxpopuli_french") # "microsoft/speecht5_tts"
|
15 |
|
16 |
model = SpeechT5ForTextToSpeech.from_pretrained("Sandiago21/speecht5_finetuned_facebook_voxpopuli_french").to(device)
|
17 |
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
|
|
|
20 |
np_sample = np.transpose(np.load(path))
|
21 |
sample = torch.from_numpy(np_sample)
|
22 |
return sample
|
23 |
+
|
24 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation", streaming=True)
|
25 |
+
speaker_embeddings = torch.tensor(next(iter(embeddings_dataset))["xvector"]).unsqueeze(0)
|
26 |
+
|
27 |
+
#xvector_path = "xvectors/french_recording-bernard-candide_segment_182.npy"
|
28 |
+
#speaker_embeddings = torch.tensor(npy_loader(xvector_path)[0]).unsqueeze(0)
|
29 |
+
#print("speaker_embeddings shape", speaker_embeddings.shape)
|
30 |
|
31 |
|
32 |
def translate(audio):
|
|
|
42 |
|
43 |
def speech_to_speech_translation(audio):
|
44 |
translated_text = translate(audio)
|
45 |
+
print("translated_text", translated_text)
|
46 |
synthesised_speech = synthesise(translated_text)
|
47 |
synthesised_speech = (synthesised_speech.numpy() * 32767).astype(np.int16)
|
48 |
return 16000, synthesised_speech
|
|
|
50 |
|
51 |
title = "Cascaded STST"
|
52 |
description = """
|
53 |
+
Demo for cascaded speech-to-speech translation (STST), mapping from source speech in any language to target speech in french. Demo uses OpenAI's [Whisper Base](https://huggingface.co/openai/whisper-base) model for speech translation, and Microsoft's
|
54 |
+
[SpeechT5 TTS](https://huggingface.co/microsoft/speecht5_tts) model for text-to-speech [finetuned for french language](https://huggingface.co/Sandiago21/speecht5_finetuned_facebook_voxpopuli_french):
|
55 |
|
56 |

|
57 |
"""
|