Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,12 +9,14 @@ from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Proce
|
|
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-base", device=device)
|
13 |
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
processor = SpeechT5Processor.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl")
|
16 |
|
17 |
model = SpeechT5ForTextToSpeech.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl").to(device)
|
|
|
18 |
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
|
19 |
|
20 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
@@ -22,6 +24,8 @@ speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze
|
|
22 |
|
23 |
|
24 |
def translate(audio):
|
|
|
|
|
25 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"language": "nl","task": "transcribe"})
|
26 |
return outputs["text"]
|
27 |
|
@@ -69,4 +73,4 @@ file_translate = gr.Interface(
|
|
69 |
with demo:
|
70 |
gr.TabbedInterface([mic_translate, file_translate], ["Microphone", "Audio File"])
|
71 |
|
72 |
-
demo.launch()
|
|
|
9 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
# load speech translation checkpoint
|
12 |
+
|
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("sanchit-gandhi/speecht5_tts_vox_nl")
|
17 |
|
18 |
model = SpeechT5ForTextToSpeech.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl").to(device)
|
19 |
+
|
20 |
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
|
21 |
|
22 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
|
|
24 |
|
25 |
|
26 |
def translate(audio):
|
27 |
+
print(audio)
|
28 |
+
audio = librosa.resample(audio, orig_sr=22050, target_sr=16000)
|
29 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"language": "nl","task": "transcribe"})
|
30 |
return outputs["text"]
|
31 |
|
|
|
73 |
with demo:
|
74 |
gr.TabbedInterface([mic_translate, file_translate], ["Microphone", "Audio File"])
|
75 |
|
76 |
+
demo.launch(share=True)
|