NLPV commited on
Commit
c81d3a2
Β·
verified Β·
1 Parent(s): c994feb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -14,7 +14,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,14 +33,19 @@ def transcribe_audio(audio, original_text):
33
 
34
  # Calculate speed
35
  duration = end_time - start_time # time to process (not speaking time)
36
- # Better: estimate speaking time from audio length if needed (advanced)
37
-
38
  speed = round(len(transcribed_words) / duration, 2) # words per second
39
 
 
 
 
 
 
 
40
  result = {
41
  "πŸ“ Transcribed Text": transcription,
42
  "🎯 Accuracy (%)": accuracy,
43
- "⏱️ Speaking Speed (words/sec)": speed
 
44
  }
45
  return result
46
  except Exception as e:
@@ -67,4 +72,3 @@ with gr.Blocks() as app:
67
 
68
  # Launch the app
69
  app.launch()
70
-
 
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 and compare with the original text
18
  def transcribe_audio(audio, original_text):
19
  recognizer = sr.Recognizer()
20
  with sr.AudioFile(audio) as source:
 
33
 
34
  # Calculate speed
35
  duration = end_time - start_time # time to process (not speaking time)
 
 
36
  speed = round(len(transcribed_words) / duration, 2) # words per second
37
 
38
+ # Compare words and highlight mistakes
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:
 
72
 
73
  # Launch the app
74
  app.launch()