Spaces:
Sleeping
Sleeping
jinggujiwoo7
commited on
Commit
•
fb11cf4
1
Parent(s):
187a6f4
Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,16 @@ from Levenshtein import ratio
|
|
4 |
import tempfile
|
5 |
import numpy as np
|
6 |
import soundfile as sf
|
|
|
7 |
|
8 |
def transcribe_audio(file_info):
|
9 |
r = sr.Recognizer()
|
10 |
-
with tempfile.NamedTemporaryFile(delete=
|
11 |
sf.write(tmpfile.name, data=file_info[1], samplerate=44100, format='WAV')
|
12 |
tmpfile.seek(0)
|
13 |
with sr.AudioFile(tmpfile.name) as source:
|
14 |
audio_data = r.record(source)
|
|
|
15 |
try:
|
16 |
text = r.recognize_google(audio_data)
|
17 |
return text
|
@@ -49,8 +51,7 @@ def download_audio(file_info):
|
|
49 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
|
50 |
sf.write(tmpfile.name, data=file_info[1], samplerate=44100, format='WAV')
|
51 |
tmpfile.seek(0)
|
52 |
-
|
53 |
-
return f.read(), "recording.wav"
|
54 |
|
55 |
with gr.Blocks() as app:
|
56 |
with gr.Row():
|
@@ -61,6 +62,7 @@ with gr.Blocks() as app:
|
|
61 |
pronunciation_feedback = gr.Textbox(label="Pronunciation Feedback")
|
62 |
pronunciation_score = gr.Number(label="Pronunciation Accuracy Score: 0 (No Match) ~ 1 (Perfect)")
|
63 |
download_audio_button = gr.Button("Download Recording")
|
|
|
64 |
|
65 |
sentence_input.change(
|
66 |
validate_sentence,
|
@@ -77,7 +79,7 @@ with gr.Blocks() as app:
|
|
77 |
download_audio_button.click(
|
78 |
download_audio,
|
79 |
inputs=[audio_input],
|
80 |
-
outputs=
|
81 |
)
|
82 |
|
83 |
app.launch(debug=True)
|
|
|
4 |
import tempfile
|
5 |
import numpy as np
|
6 |
import soundfile as sf
|
7 |
+
import os
|
8 |
|
9 |
def transcribe_audio(file_info):
|
10 |
r = sr.Recognizer()
|
11 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
|
12 |
sf.write(tmpfile.name, data=file_info[1], samplerate=44100, format='WAV')
|
13 |
tmpfile.seek(0)
|
14 |
with sr.AudioFile(tmpfile.name) as source:
|
15 |
audio_data = r.record(source)
|
16 |
+
os.remove(tmpfile.name) # Cleanup temporary file
|
17 |
try:
|
18 |
text = r.recognize_google(audio_data)
|
19 |
return text
|
|
|
51 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
|
52 |
sf.write(tmpfile.name, data=file_info[1], samplerate=44100, format='WAV')
|
53 |
tmpfile.seek(0)
|
54 |
+
return tmpfile.name # Return file path for download
|
|
|
55 |
|
56 |
with gr.Blocks() as app:
|
57 |
with gr.Row():
|
|
|
62 |
pronunciation_feedback = gr.Textbox(label="Pronunciation Feedback")
|
63 |
pronunciation_score = gr.Number(label="Pronunciation Accuracy Score: 0 (No Match) ~ 1 (Perfect)")
|
64 |
download_audio_button = gr.Button("Download Recording")
|
65 |
+
download_output = gr.File(label="Download Your Recording")
|
66 |
|
67 |
sentence_input.change(
|
68 |
validate_sentence,
|
|
|
79 |
download_audio_button.click(
|
80 |
download_audio,
|
81 |
inputs=[audio_input],
|
82 |
+
outputs=download_output
|
83 |
)
|
84 |
|
85 |
app.launch(debug=True)
|