Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
import time
|
4 |
import difflib
|
@@ -14,7 +13,7 @@ def play_text(text):
|
|
14 |
os.system(f"start {temp_file.name}") # Windows
|
15 |
return "β
Text is being read out. Please listen and read it yourself."
|
16 |
|
17 |
-
# Function to transcribe user's audio
|
18 |
def transcribe_audio(audio, original_text):
|
19 |
recognizer = sr.Recognizer()
|
20 |
with sr.AudioFile(audio) as source:
|
@@ -33,19 +32,14 @@ def transcribe_audio(audio, original_text):
|
|
33 |
|
34 |
# Calculate speed
|
35 |
duration = end_time - start_time # time to process (not speaking time)
|
36 |
-
|
37 |
|
38 |
-
#
|
39 |
-
wrong_words = []
|
40 |
-
for i, word in enumerate(original_words):
|
41 |
-
if i >= len(transcribed_words) or word != transcribed_words[i]:
|
42 |
-
wrong_words.append(f"π΄ {word}")
|
43 |
|
44 |
result = {
|
45 |
"π Transcribed Text": transcription,
|
46 |
"π― Accuracy (%)": accuracy,
|
47 |
-
"β±οΈ Speaking Speed (words/sec)": speed
|
48 |
-
"β Incorrect Words": ' '.join(wrong_words) if wrong_words else "None"
|
49 |
}
|
50 |
return result
|
51 |
except Exception as e:
|
@@ -71,4 +65,4 @@ with gr.Blocks() as app:
|
|
71 |
submit_button.click(transcribe_audio, inputs=[audio_input, input_text], outputs=[output])
|
72 |
|
73 |
# Launch the app
|
74 |
-
app.launch()
|
|
|
|
|
1 |
from gtts import gTTS
|
2 |
import time
|
3 |
import difflib
|
|
|
13 |
os.system(f"start {temp_file.name}") # Windows
|
14 |
return "β
Text is being read out. Please listen and read it yourself."
|
15 |
|
16 |
+
# Function to transcribe user's audio
|
17 |
def transcribe_audio(audio, original_text):
|
18 |
recognizer = sr.Recognizer()
|
19 |
with sr.AudioFile(audio) as source:
|
|
|
32 |
|
33 |
# Calculate speed
|
34 |
duration = end_time - start_time # time to process (not speaking time)
|
35 |
+
# Better: estimate speaking time from audio length if needed (advanced)
|
36 |
|
37 |
+
speed = round(len(transcribed_words) / duration, 2) # words per second
|
|
|
|
|
|
|
|
|
38 |
|
39 |
result = {
|
40 |
"π Transcribed Text": transcription,
|
41 |
"π― Accuracy (%)": accuracy,
|
42 |
+
"β±οΈ Speaking Speed (words/sec)": speed
|
|
|
43 |
}
|
44 |
return result
|
45 |
except Exception as e:
|
|
|
65 |
submit_button.click(transcribe_audio, inputs=[audio_input, input_text], outputs=[output])
|
66 |
|
67 |
# Launch the app
|
68 |
+
app.launch()
|