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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
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 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,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
- 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:
@@ -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()