Yassmen commited on
Commit
e01a69a
·
verified ·
1 Parent(s): e3521d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -78,7 +78,7 @@ processor = SpeechT5Processor.from_pretrained(checkpoint)
78
 
79
 
80
  def generate_wav_file(text):
81
- try:
82
  converted_text = replace_numbers_with_words(text)
83
  cleaned_text = cleanup_text(converted_text)
84
  final_text = normalize_text(cleaned_text)
@@ -86,16 +86,18 @@ def generate_wav_file(text):
86
  speaker_embeddings = torch.tensor(np.load('speaker_embedding.npy'))
87
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
88
  speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
89
- return Audio(speech.numpy(), rate=16000)
90
- except Exception as e:
 
 
 
91
  print(f"Error: {e}")
92
- return None
93
-
94
 
95
  iface = gr.Interface(
96
  fn=generate_wav_file,
97
  inputs=gr.Textbox(lines=3, label="Enter text to convert to speech"),
98
- outputs="audio",
99
  title="Text-to-Speech Technical EN"
100
  )
101
  if __name__ == "__main__":
 
78
 
79
 
80
  def generate_wav_file(text):
81
+ try:
82
  converted_text = replace_numbers_with_words(text)
83
  cleaned_text = cleanup_text(converted_text)
84
  final_text = normalize_text(cleaned_text)
 
86
  speaker_embeddings = torch.tensor(np.load('speaker_embedding.npy'))
87
  vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
88
  speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
89
+ # Convert the speech to a WAV file
90
+ output_file = "output.wav"
91
+ sf.write(output_file, speech.detach().cpu().numpy(), 16000)
92
+ return output_file # Return the file path for download
93
+ except Exception as e:
94
  print(f"Error: {e}")
95
+ return None
 
96
 
97
  iface = gr.Interface(
98
  fn=generate_wav_file,
99
  inputs=gr.Textbox(lines=3, label="Enter text to convert to speech"),
100
+ outputs=gr.Audio(type="file", label="Generated Audio"),
101
  title="Text-to-Speech Technical EN"
102
  )
103
  if __name__ == "__main__":