Futuresony commited on
Commit
c7cbfb2
·
verified ·
1 Parent(s): 8487271

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -14
app.py CHANGED
@@ -1,26 +1,17 @@
1
  import gradio as gr
2
- import librosa
3
- import sounddevice as sd
4
- import numpy as np
5
  from ttsmms import download, TTS
6
 
7
  # Download and load the Swahili TTS model
8
  dir_path = download("swh", "./data") # Change "swh" to another language if needed
9
  tts = TTS(dir_path)
10
 
11
- # Function to generate speech from text
12
  def text_to_speech(text):
13
- result = tts.synthesis(text)
14
- audio = result["x"]
15
- sample_rate = result["sampling_rate"]
16
 
17
- # Play generated speech in real-time
18
- sd.play(audio, samplerate=sample_rate)
19
- sd.wait()
20
-
21
- return audio, sample_rate
22
-
23
- # Gradio UI for TTS
24
  gr.Interface(
25
  fn=text_to_speech,
26
  inputs=gr.Text(label="Enter Text"),
 
1
  import gradio as gr
 
 
 
2
  from ttsmms import download, TTS
3
 
4
  # Download and load the Swahili TTS model
5
  dir_path = download("swh", "./data") # Change "swh" to another language if needed
6
  tts = TTS(dir_path)
7
 
8
+ # Function to generate speech from text and return a .wav file
9
  def text_to_speech(text):
10
+ wav_path = "./output.wav"
11
+ tts.synthesis(text, wav_path=wav_path)
12
+ return wav_path
13
 
14
+ # Gradio UI
 
 
 
 
 
 
15
  gr.Interface(
16
  fn=text_to_speech,
17
  inputs=gr.Text(label="Enter Text"),