Shago commited on
Commit
ac9eb20
·
verified ·
1 Parent(s): 8207d4b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from tts import generate_tts, LANGUAGES
3
+ from audio_analysis import compare_both, reset_all
4
+ from llm import generate_sentences
5
+
6
+
7
+ def gen_sentences_and_audio(topic, n):
8
+ n = max(1, min(int(n), 3))
9
+ sentences = generate_sentences(topic, n)
10
+ sentences_no_quotes = [s.strip().strip('"') for s in sentences]
11
+ text = "\n".join(sentences_no_quotes)
12
+ audio = generate_tts(text, LANGUAGES["English (US)"])
13
+ return text, audio
14
+
15
+
16
+ with gr.Blocks() as app:
17
+ gr.Markdown("## Listen, Record, and Compare Your Pronunciation (in English)")
18
+
19
+ with gr.Row():
20
+ topic_in = gr.Textbox(label="Enter a Topic", value="", interactive=True)
21
+ n_sentences_in = gr.Number(label="Number of Sentences", value=1, precision=0, minimum=1, maximum=3,interactive=True)
22
+ gen_text_btn = gr.Button("Generate Sentence(s) and Reference Audio")
23
+ text_in = gr.Textbox(label="Generated Sentence(s) for Reference Audio", interactive=False)
24
+ tts_audio = gr.Audio(label="Reference Audio (gTTS)", interactive=False, type="filepath")
25
+
26
+
27
+ gr.Markdown("**Step 2: Record your version after listening to the reference.**")
28
+ user_audio = gr.Audio(sources=["microphone"], label="Your Recorded Audio", type="filepath")
29
+ compare_btn = gr.Button("Compare")
30
+ reset_btn = gr.Button("Restart / Reset")
31
+
32
+
33
+ table_out = gr.Dataframe(label="Word-by-Word Comparison", visible=True)
34
+ plot_out = gr.Plot(label="Waveform Comparison Plot")
35
+
36
+ gen_text_btn.click(
37
+ fn=gen_sentences_and_audio,
38
+ inputs=[topic_in, n_sentences_in],
39
+ outputs=[text_in, tts_audio]
40
+ )
41
+
42
+ compare_btn.click(
43
+ fn=compare_both,
44
+ inputs=[tts_audio, user_audio],
45
+ outputs=[plot_out, table_out]
46
+ )
47
+ reset_btn.click(
48
+ fn=reset_all,
49
+ inputs=[],
50
+ outputs=[topic_in, text_in, tts_audio, user_audio, plot_out, table_out]
51
+ )
52
+
53
+
54
+
55
+ if __name__ == "__main__":
56
+ app.launch()