Update app.py
Browse files
app.py
CHANGED
@@ -21,21 +21,71 @@ def tts_demo(text, language):
|
|
21 |
# Return the audio file to be played in the Gradio interface
|
22 |
return audio_file
|
23 |
|
24 |
-
# Define Gradio inputs and outputs
|
25 |
-
inputs = [
|
26 |
-
|
27 |
-
|
28 |
-
]
|
29 |
-
outputs = gr.Audio(label="Generated Audio", type="filepath")
|
30 |
-
|
31 |
-
# Create the Gradio interface
|
32 |
-
iface = gr.Interface(
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
)
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
21 |
# Return the audio file to be played in the Gradio interface
|
22 |
return audio_file
|
23 |
|
24 |
+
# # Define Gradio inputs and outputs
|
25 |
+
# inputs = [
|
26 |
+
# gr.Textbox(label="Enter Text", placeholder="Type something here..."),
|
27 |
+
# gr.Dropdown(label="Language", choices=["en", "es", "fr", "de", "hr"], value="hr")
|
28 |
+
# ]
|
29 |
+
# outputs = gr.Audio(label="Generated Audio", type="filepath")
|
30 |
+
|
31 |
+
# # Create the Gradio interface
|
32 |
+
# iface = gr.Interface(
|
33 |
+
# fn=tts_demo,
|
34 |
+
# inputs=inputs,
|
35 |
+
# outputs=outputs,
|
36 |
+
# title="Text-to-Speech Demo",
|
37 |
+
# description="Enter text and select a language to generate and play audio."
|
38 |
+
# )
|
39 |
+
|
40 |
+
# # Launch the app
|
41 |
+
# iface.launch()
|
42 |
+
|
43 |
+
|
44 |
+
import gradio as gr
|
45 |
+
import random
|
46 |
+
import pyttsx3
|
47 |
+
|
48 |
+
engine = pyttsx3.init()
|
49 |
+
|
50 |
+
def select_and_speak(state):
|
51 |
+
if not state:
|
52 |
+
return "", "No names provided.", []
|
53 |
+
|
54 |
+
names_list = state
|
55 |
+
if not names_list:
|
56 |
+
return "", "List is empty. Please reset.", []
|
57 |
+
|
58 |
+
selected_name = random.choice(names_list)
|
59 |
+
names_list.remove(selected_name)
|
60 |
+
tts_demo(selected_name)
|
61 |
+
# engine.say(selected_name)
|
62 |
+
# engine.runAndWait()
|
63 |
+
play_sound()
|
64 |
+
return '\n'.join(names_list), selected_name, names_list
|
65 |
+
|
66 |
+
def play_sound():
|
67 |
+
return "<audio autoplay><source src='output.mp3' type='audio/mp3'></audio>"
|
68 |
+
|
69 |
+
|
70 |
+
def reset_names(names):
|
71 |
+
return names.split('\n')
|
72 |
+
|
73 |
+
demo = gr.Interface(
|
74 |
+
fn=select_and_speak,
|
75 |
+
inputs=[gr.State()],
|
76 |
+
outputs=[gr.Textbox(label="Remaining Names"), gr.Textbox(label="Selected Name"), gr.State(), ],
|
77 |
+
title="Random Name Selector and Speaker",
|
78 |
+
description="Enter a list of names separated by newlines in the 'Reset' tab to start.",
|
79 |
+
)
|
80 |
+
|
81 |
+
reset_demo = gr.Interface(
|
82 |
+
fn=reset_names,
|
83 |
+
inputs=[gr.Textbox(label="List of Names (separated by newline)")],
|
84 |
+
outputs=[gr.State()],
|
85 |
+
title="Reset Names",
|
86 |
+
description="Enter new list of names here to reset the app.",
|
87 |
)
|
88 |
|
89 |
+
if __name__ == "__main__":
|
90 |
+
demo.launch()
|
91 |
+
reset_demo.launch()
|