tsobolev commited on
Commit
75d8950
1 Parent(s): a75ab97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -16,21 +16,33 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
16
  asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
17
 
18
  # load text-to-speech checkpoint and speaker embeddings
19
- processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
20
 
21
- model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts").to(device)
22
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
23
 
24
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
25
- speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
 
26
 
27
 
28
- print("Blocks interface does not work, hmm. gradio version is ",gr.__version__)
29
 
30
 
31
  def translate(audio):
32
  outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
33
- return outputs["text"]
 
 
 
 
 
 
 
 
 
 
 
34
 
35
 
36
  def synthesise(text):
 
16
  asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
17
 
18
  # load text-to-speech checkpoint and speaker embeddings
19
+ processor = SpeechT5Processor.from_pretrained("tsobolev/speecht5_finetuned_voxpopuli_fi")
20
 
21
+ model = SpeechT5ForTextToSpeech.from_pretrained("tsobolev/speecht5_finetuned_voxpopuli_fi").to(device)
22
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
23
 
24
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
25
+ speaker_embeddings = torch.tensor(embeddings_dataset[7000]["xvector"]).unsqueeze(0)
26
+ en2fi_pipeline = pipeline("translation", model="Helsinki-NLP/opus-mt-en-fi")
27
 
28
 
29
+ print("gradio version is ",gr.__version__)
30
 
31
 
32
  def translate(audio):
33
  outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
34
+ fi_translation = en2fi_pipeline(outputs["text"])
35
+ text = fi_translation[0]['translation_text']
36
+ replacements = [
37
+ ("ä", "ae"),
38
+ ("ö", "oe"),
39
+ ]
40
+
41
+ for src, dst in replacements:
42
+ text = text.replace(src, dst)
43
+
44
+ print(text)
45
+ return text
46
 
47
 
48
  def synthesise(text):