mr2along commited on
Commit
4a05e8e
·
verified ·
1 Parent(s): 558630b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -10,7 +10,7 @@ def transcribe_audio(audio):
10
 
11
  # Convert audio into recognizable format for the Recognizer
12
  audio_file = sr.AudioFile(audio)
13
-
14
  with audio_file as source:
15
  audio_data = recognizer.record(source)
16
 
@@ -25,7 +25,7 @@ def transcribe_audio(audio):
25
 
26
  # Step 2: Create pronunciation audio for incorrect words
27
  def create_pronunciation_audio(word):
28
- tts = gTTS(word)
29
  audio_buffer = io.BytesIO()
30
  tts.save(audio_buffer)
31
  audio_buffer.seek(0)
@@ -49,7 +49,7 @@ def compare_texts(reference_text, transcribed_text):
49
 
50
  # Generate colored word score list
51
  for i, word in enumerate(reference_words):
52
- try:
53
  if word.lower() == transcribed_words[i].lower():
54
  html_output += f'<span style="color: green;">{word}</span> ' # Correct words in green
55
  elif difflib.get_close_matches(word, transcribed_words):
@@ -62,7 +62,8 @@ def compare_texts(reference_text, transcribed_text):
62
  # Encode the audio as base64 for playback
63
  audio_base64 = audio_buffer.getvalue().hex()
64
  incorrect_words_audios.append((word, audio_base64))
65
- except IndexError:
 
66
  html_output += f'<span style="color: red;">{word}</span> ' # Words in reference that were not transcribed
67
 
68
  # Provide audio for incorrect words
@@ -77,7 +78,7 @@ def compare_texts(reference_text, transcribed_text):
77
 
78
  # Step 4: Text-to-Speech Function
79
  def text_to_speech(paragraph):
80
- tts = gTTS(paragraph)
81
  audio_buffer = io.BytesIO()
82
  tts.save(audio_buffer)
83
  audio_buffer.seek(0)
 
10
 
11
  # Convert audio into recognizable format for the Recognizer
12
  audio_file = sr.AudioFile(audio)
13
+
14
  with audio_file as source:
15
  audio_data = recognizer.record(source)
16
 
 
25
 
26
  # Step 2: Create pronunciation audio for incorrect words
27
  def create_pronunciation_audio(word):
28
+ tts = gTTS(word, lang='en') # Specify the language for TTS
29
  audio_buffer = io.BytesIO()
30
  tts.save(audio_buffer)
31
  audio_buffer.seek(0)
 
49
 
50
  # Generate colored word score list
51
  for i, word in enumerate(reference_words):
52
+ if i < len(transcribed_words):
53
  if word.lower() == transcribed_words[i].lower():
54
  html_output += f'<span style="color: green;">{word}</span> ' # Correct words in green
55
  elif difflib.get_close_matches(word, transcribed_words):
 
62
  # Encode the audio as base64 for playback
63
  audio_base64 = audio_buffer.getvalue().hex()
64
  incorrect_words_audios.append((word, audio_base64))
65
+ else:
66
+ # If reference word has no corresponding transcribed word
67
  html_output += f'<span style="color: red;">{word}</span> ' # Words in reference that were not transcribed
68
 
69
  # Provide audio for incorrect words
 
78
 
79
  # Step 4: Text-to-Speech Function
80
  def text_to_speech(paragraph):
81
+ tts = gTTS(paragraph, lang='en') # Specify the language for TTS
82
  audio_buffer = io.BytesIO()
83
  tts.save(audio_buffer)
84
  audio_buffer.seek(0)