Spaces:
Runtime error
Runtime error
Commit
·
074afb0
1
Parent(s):
375e423
Translate in Dutch
Browse files
app.py
CHANGED
@@ -3,15 +3,18 @@ import numpy as np
|
|
3 |
import torch
|
4 |
from datasets import load_dataset
|
5 |
|
6 |
-
from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor, 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-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("microsoft/speecht5_tts").to(device)
|
@@ -22,12 +25,13 @@ 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={"task": "
|
26 |
return outputs["text"]
|
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 |
return speech.cpu()
|
33 |
|
|
|
3 |
import torch
|
4 |
from datasets import load_dataset
|
5 |
|
6 |
+
from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor, pipeline, AutoProcessor
|
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-base", chunk_length_s=30, device=device)
|
13 |
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
+
#processor = AutoProcessor.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl")
|
16 |
+
#model = SpeechT5ForTextToSpeech.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl").to(device)
|
17 |
+
|
18 |
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
19 |
|
20 |
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts").to(device)
|
|
|
25 |
|
26 |
|
27 |
def translate(audio):
|
28 |
+
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", "language":"nl"})
|
29 |
return outputs["text"]
|
30 |
|
31 |
|
32 |
def synthesise(text):
|
33 |
+
inputs = processor(text=text, padding='max_length', truncation=True, return_tensors="pt")
|
34 |
+
#inputs = processor(text=text, padding='max_length', truncation=True, return_tensors="pt")
|
35 |
speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
|
36 |
return speech.cpu()
|
37 |
|