Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ 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-
|
13 |
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
processor = SpeechT5Processor.from_pretrained("omthkkr/speecht5_finetuned_voxpopuli_sl")
|
@@ -20,6 +20,18 @@ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(devic
|
|
20 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
21 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def translate(audio):
|
25 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", "language": "sl"})
|
@@ -27,6 +39,7 @@ 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 |
return speech.cpu()
|
|
|
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-large-v2", device=device)
|
13 |
|
14 |
# load text-to-speech checkpoint and speaker embeddings
|
15 |
processor = SpeechT5Processor.from_pretrained("omthkkr/speecht5_finetuned_voxpopuli_sl")
|
|
|
20 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
21 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
22 |
|
23 |
+
replacements = [
|
24 |
+
("č", "c"),
|
25 |
+
("š", "s"),
|
26 |
+
("ž", "z"),
|
27 |
+
]
|
28 |
+
|
29 |
+
|
30 |
+
def cleanup_text(inputs):
|
31 |
+
for src, dst in replacements:
|
32 |
+
inputs = inputs.replace(src, dst)
|
33 |
+
return inputs
|
34 |
+
|
35 |
|
36 |
def translate(audio):
|
37 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", "language": "sl"})
|
|
|
39 |
|
40 |
|
41 |
def synthesise(text):
|
42 |
+
text = cleanup_text(text)
|
43 |
inputs = processor(text=text, return_tensors="pt")
|
44 |
speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
|
45 |
return speech.cpu()
|