jalal-elzein commited on
Commit
cd2c451
·
1 Parent(s): 7d3b893

language fix + debugging logs

Browse files

- Changed task language from french to italian
- changed synthesizer to my own
- added some prints for easier debugging

Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -7,14 +7,15 @@ from transformers import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Proce
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("sanchit-gandhi/speecht5_tts_vox_nl")
16
 
17
- model = SpeechT5ForTextToSpeech.from_pretrained("sanchit-gandhi/speecht5_tts_vox_nl").to(device)
18
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
19
 
20
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
@@ -22,7 +23,7 @@ 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": "translate", "language": "french"})
26
  return outputs["text"]
27
 
28
 
@@ -34,6 +35,7 @@ def synthesise(text):
34
 
35
  def speech_to_speech_translation(audio):
36
  translated_text = translate(audio)
 
37
  synthesised_speech = synthesise(translated_text)
38
  synthesised_speech = (synthesised_speech.numpy() * 32767).astype(np.int16)
39
  return 16000, synthesised_speech
 
7
 
8
 
9
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
10
+ print("> DEVICE: ", device)
11
 
12
  # load speech translation checkpoint
13
  asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device)
14
 
15
  # load text-to-speech checkpoint and speaker embeddings
16
+ processor = SpeechT5Processor.from_pretrained("jalal-elzein/speecht5_tts_voxpopuli_it_finetuned")
17
 
18
+ model = SpeechT5ForTextToSpeech.from_pretrained("jalal-elzein/speecht5_tts_voxpopuli_it_finetuned").to(device)
19
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(device)
20
 
21
  embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
 
23
 
24
 
25
  def translate(audio):
26
+ outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate", "language": "italian"})
27
  return outputs["text"]
28
 
29
 
 
35
 
36
  def speech_to_speech_translation(audio):
37
  translated_text = translate(audio)
38
+ print("> Translated Text: ", translated_text)
39
  synthesised_speech = synthesise(translated_text)
40
  synthesised_speech = (synthesised_speech.numpy() * 32767).astype(np.int16)
41
  return 16000, synthesised_speech