englissi commited on
Commit
80f6579
Β·
verified Β·
1 Parent(s): 280ab37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
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 "Could not understand the audio"
24
  except sr.RequestError as e:
25
- return f"Could not request results from Google Speech Recognition service; {e}"
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 "Error" in recognized_text or "Could not" in recognized_text:
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="Enter the word for pronunciation")
50
- tts_button = gr.Button("Listen to the word")
51
- tts_audio = gr.Audio(label="Original Pronunciation", type="filepath")
52
-
53
  with gr.Row():
54
- mic_input = gr.Audio(label="Your Pronunciation", type="filepath")
55
- result_button = gr.Button("Evaluate Pronunciation")
56
-
57
- recognized_text = gr.Textbox(label="Recognized Text")
58
- similarity_score = gr.Number(label="Similarity (%)")
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