Spaces:
Sleeping
Sleeping
jinggujiwoo7
commited on
Commit
•
9ef4232
1
Parent(s):
80164bf
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,18 @@
|
|
1 |
-
# app.py
|
2 |
-
|
3 |
import gradio as gr
|
4 |
import speech_recognition as sr
|
5 |
from Levenshtein import ratio
|
6 |
import tempfile
|
7 |
import numpy as np
|
8 |
import soundfile as sf
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def transcribe_audio(file_info):
|
11 |
r = sr.Recognizer()
|
12 |
with tempfile.NamedTemporaryFile(delete=True, suffix=".wav") as tmpfile:
|
13 |
-
sf.write(tmpfile.name, data=file_info, samplerate=44100, format='WAV')
|
14 |
tmpfile.seek(0)
|
15 |
with sr.AudioFile(tmpfile.name) as source:
|
16 |
audio_data = r.record(source)
|
@@ -38,19 +40,33 @@ def pronunciation_correction(expected_text, file_info):
|
|
38 |
|
39 |
return feedback, description
|
40 |
|
|
|
|
|
|
|
|
|
|
|
41 |
with gr.Blocks() as app:
|
42 |
-
with gr.
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
app.launch(debug=True)
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import speech_recognition as sr
|
3 |
from Levenshtein import ratio
|
4 |
import tempfile
|
5 |
import numpy as np
|
6 |
import soundfile as sf
|
7 |
+
import language_tool_python
|
8 |
+
|
9 |
+
# Initialize LanguageTool for English grammar checking
|
10 |
+
tool = language_tool_python.LanguageTool('en-US')
|
11 |
|
12 |
def transcribe_audio(file_info):
|
13 |
r = sr.Recognizer()
|
14 |
with tempfile.NamedTemporaryFile(delete=True, suffix=".wav") as tmpfile:
|
15 |
+
sf.write(tmpfile.name, data=file_info[1], samplerate=44100, format='WAV')
|
16 |
tmpfile.seek(0)
|
17 |
with sr.AudioFile(tmpfile.name) as source:
|
18 |
audio_data = r.record(source)
|
|
|
40 |
|
41 |
return feedback, description
|
42 |
|
43 |
+
def grammar_check(text):
|
44 |
+
matches = tool.check(text)
|
45 |
+
corrected_text = tool.correct(text)
|
46 |
+
return corrected_text, matches
|
47 |
+
|
48 |
with gr.Blocks() as app:
|
49 |
+
with gr.Row():
|
50 |
+
sentence_input = gr.Textbox(label="Enter a Sentence", lines=2)
|
51 |
+
check_grammar_button = gr.Button("Check Grammar")
|
52 |
+
corrected_sentence_output = gr.Textbox(label="Corrected Sentence", interactive=False)
|
53 |
+
grammar_feedback = gr.Textbox(label="Grammar Feedback", interactive=False)
|
54 |
+
|
55 |
+
audio_input = gr.Audio(label="Upload Audio File", type="numpy")
|
56 |
+
check_pronunciation_button = gr.Button("Check Pronunciation")
|
57 |
+
pronunciation_feedback = gr.Textbox(label="Pronunciation Feedback")
|
58 |
+
pronunciation_score = gr.Number(label="Pronunciation Accuracy Score: 0 (No Match) ~ 1 (Perfect)")
|
59 |
+
|
60 |
+
check_grammar_button.click(
|
61 |
+
grammar_check,
|
62 |
+
inputs=sentence_input,
|
63 |
+
outputs=[corrected_sentence_output, grammar_feedback]
|
64 |
+
)
|
65 |
+
|
66 |
+
check_pronunciation_button.click(
|
67 |
+
pronunciation_correction,
|
68 |
+
inputs=[corrected_sentence_output, audio_input],
|
69 |
+
outputs=[pronunciation_feedback, pronunciation_score]
|
70 |
+
)
|
71 |
|
72 |
app.launch(debug=True)
|