Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
from gtts import gTTS
|
4 |
import speech_recognition as sr
|
@@ -20,9 +19,9 @@ def recognize_speech_from_microphone(audio_path):
|
|
20 |
text = recognizer.recognize_google(audio_data)
|
21 |
return text
|
22 |
except sr.UnknownValueError:
|
23 |
-
return "
|
24 |
except sr.RequestError as e:
|
25 |
-
return f"
|
26 |
except Exception as e:
|
27 |
return str(e)
|
28 |
|
@@ -31,7 +30,7 @@ def calculate_similarity(word, recognized_text):
|
|
31 |
|
32 |
def process_audio(word, audio_path):
|
33 |
recognized_text = recognize_speech_from_microphone(audio_path)
|
34 |
-
if "
|
35 |
return recognized_text, 0.0
|
36 |
similarity = calculate_similarity(word, recognized_text)
|
37 |
return recognized_text, similarity
|
@@ -44,19 +43,21 @@ def process_all(word, audio_path):
|
|
44 |
recognized_text, similarity = process_audio(word, audio_path)
|
45 |
return recognized_text, similarity
|
46 |
|
47 |
-
with gr.Blocks() as demo:
|
|
|
|
|
48 |
with gr.Row():
|
49 |
-
word_input = gr.Textbox(label="
|
50 |
-
tts_button = gr.Button("
|
51 |
-
tts_audio = gr.Audio(label="
|
52 |
-
|
53 |
with gr.Row():
|
54 |
-
mic_input = gr.Audio(label="
|
55 |
-
result_button = gr.Button("
|
56 |
-
|
57 |
-
recognized_text = gr.Textbox(label="
|
58 |
-
similarity_score = gr.Number(label="
|
59 |
-
|
60 |
tts_button.click(evaluate_pronunciation, inputs=word_input, outputs=tts_audio)
|
61 |
result_button.click(process_all, inputs=[word_input, mic_input], outputs=[recognized_text, similarity_score])
|
62 |
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
import speech_recognition as sr
|
|
|
19 |
text = recognizer.recognize_google(audio_data)
|
20 |
return text
|
21 |
except sr.UnknownValueError:
|
22 |
+
return "μμ±μ μ΄ν΄ν μ μμ΄μ. λ€μ λ§ν΄ μ£ΌμΈμ! π§"
|
23 |
except sr.RequestError as e:
|
24 |
+
return f"μμ± μΈμ μλΉμ€μ μ°κ²°ν μ μμ΄μ. π’ μ€λ₯: {e}"
|
25 |
except Exception as e:
|
26 |
return str(e)
|
27 |
|
|
|
30 |
|
31 |
def process_audio(word, audio_path):
|
32 |
recognized_text = recognize_speech_from_microphone(audio_path)
|
33 |
+
if "μ€λ₯" in recognized_text or "μμ΄μ" in recognized_text:
|
34 |
return recognized_text, 0.0
|
35 |
similarity = calculate_similarity(word, recognized_text)
|
36 |
return recognized_text, similarity
|
|
|
43 |
recognized_text, similarity = process_audio(word, audio_path)
|
44 |
return recognized_text, similarity
|
45 |
|
46 |
+
with gr.Blocks(css="body {background-color: #FFFAF0; font-family: 'Comic Sans MS', cursive;} .title {font-size: 24px; text-align: center; color: #FF69B4;}") as demo:
|
47 |
+
gr.Markdown("<h1 class='title'>π€ μ¬λ―Έμλ λ°μ μ°μ΅ πΆ</h1>")
|
48 |
+
|
49 |
with gr.Row():
|
50 |
+
word_input = gr.Textbox(label="μ°μ΅ν λ¨μ΄λ₯Ό μ
λ ₯νμΈμ! βοΈ")
|
51 |
+
tts_button = gr.Button("π λ£κΈ°")
|
52 |
+
tts_audio = gr.Audio(label="π μμ΄λ―Ό λ°μ", type="filepath")
|
53 |
+
|
54 |
with gr.Row():
|
55 |
+
mic_input = gr.Audio(label="ποΈ λ΄ λ°μ λ
Ήμ", type="filepath")
|
56 |
+
result_button = gr.Button("π νκ°νκΈ°")
|
57 |
+
|
58 |
+
recognized_text = gr.Textbox(label="π μΈμλ λ¨μ΄")
|
59 |
+
similarity_score = gr.Number(label="π― μ νλ (%)")
|
60 |
+
|
61 |
tts_button.click(evaluate_pronunciation, inputs=word_input, outputs=tts_audio)
|
62 |
result_button.click(process_all, inputs=[word_input, mic_input], outputs=[recognized_text, similarity_score])
|
63 |
|