hivecorp commited on
Commit
8a61d62
·
verified ·
1 Parent(s): a503146

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -1,9 +1,16 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- def kokoro_tts(text):
5
- # Initialize the transformers pipeline for text-to-speech
6
- tts_pipeline = pipeline("text-to-speech", model="kokoro/tts")
 
 
 
 
 
 
 
7
  # Generate speech from text
8
  speech = tts_pipeline(text)
9
  return speech["waveform"]
@@ -11,10 +18,13 @@ def kokoro_tts(text):
11
  # Create a Gradio interface
12
  iface = gr.Interface(
13
  fn=kokoro_tts,
14
- inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
 
 
 
15
  outputs=gr.outputs.Audio(label="Generated Speech"),
16
  title="Kokoro Text-to-Speech",
17
- description="A Text-to-Speech app powered by Kokoro and Transformers.js"
18
  )
19
 
20
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Define a list of available speaker models
5
+ SPEAKER_MODELS = {
6
+ "Default": "kokoro/tts-default",
7
+ "Speaker 1": "kokoro/tts-speaker1",
8
+ "Speaker 2": "kokoro/tts-speaker2"
9
+ }
10
+
11
+ def kokoro_tts(text, speaker):
12
+ # Initialize the transformers pipeline for text-to-speech with the selected speaker model
13
+ tts_pipeline = pipeline("text-to-speech", model=SPEAKER_MODELS[speaker])
14
  # Generate speech from text
15
  speech = tts_pipeline(text)
16
  return speech["waveform"]
 
18
  # Create a Gradio interface
19
  iface = gr.Interface(
20
  fn=kokoro_tts,
21
+ inputs=[
22
+ gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
23
+ gr.inputs.Dropdown(choices=list(SPEAKER_MODELS.keys()), label="Select Speaker")
24
+ ],
25
  outputs=gr.outputs.Audio(label="Generated Speech"),
26
  title="Kokoro Text-to-Speech",
27
+ description="A Text-to-Speech app powered by Kokoro and Transformers.js with multiple speaker options"
28
  )
29
 
30
  if __name__ == "__main__":