Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=
|
|
|
|
|
|
|
|
|
|
| 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__":
|