Spaces:
Runtime error
Runtime error
preproccessing the text
Browse files
app.py
CHANGED
@@ -20,6 +20,22 @@ 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": "nl"})
|
@@ -27,6 +43,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()
|
|
|
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 |
+
("à", "a"),
|
25 |
+
("ç", "c"),
|
26 |
+
("è", "e"),
|
27 |
+
("ë", "e"),
|
28 |
+
("í", "i"),
|
29 |
+
("ï", "i"),
|
30 |
+
("ö", "o"),
|
31 |
+
("ü", "u"),
|
32 |
+
]
|
33 |
+
|
34 |
+
def cleanup_text(text):
|
35 |
+
for src, dst in replacements:
|
36 |
+
text = text.replace(src, dst)
|
37 |
+
return text
|
38 |
+
|
39 |
|
40 |
def translate(audio):
|
41 |
outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", "language": "nl"})
|
|
|
43 |
|
44 |
|
45 |
def synthesise(text):
|
46 |
+
text = cleanup_text(text)
|
47 |
inputs = processor(text=text, return_tensors="pt")
|
48 |
speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
|
49 |
return speech.cpu()
|