crcdng commited on
Commit
741e0df
·
1 Parent(s): b8b8a4d

Synthesize nl

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -4,6 +4,8 @@ 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"
@@ -14,7 +16,10 @@ asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base",
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)
 
 
 
18
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
19
 
20
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
@@ -25,9 +30,10 @@ def translate(audio):
25
  outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", "language": "nl"})
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
 
 
4
  from datasets import load_dataset
5
 
6
  from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor, pipeline
7
+ from transformers import VitsModel, VitsTokenizer
8
+
9
 
10
 
11
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
 
16
  # load text-to-speech checkpoint and speaker embeddings
17
  processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
18
 
19
+ # model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts").to(device)
20
+ model = VitsModel.from_pretrained("Matthijs/mms-tts-nl")
21
+ tokenizer = VitsTokenizer.from_pretrained("Matthijs/mms-tts-nl")
22
+
23
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
24
 
25
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
 
30
  outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "transcribe", "language": "nl"})
31
  return outputs["text"]
32
 
 
33
  def synthesise(text):
34
+ inputs = tokenizer(text, return_tensors="pt")
35
+ input_ids = inputs["input_ids"]
36
+ # inputs = processor(text=text, return_tensors="pt")
37
  speech = model.generate_speech(inputs["input_ids"].to(device), speaker_embeddings.to(device), vocoder=vocoder)
38
  return speech.cpu()
39