mr2along commited on
Commit
00b9487
1 Parent(s): 23f5423

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -7,7 +7,7 @@ from gtts import gTTS
7
  import io
8
  from pydub import AudioSegment
9
  import time
10
- import pronouncing # Phonetic library
11
 
12
  # Create audio directory if it doesn't exist
13
  if not os.path.exists('audio'):
@@ -78,7 +78,22 @@ def create_pronunciation_audio(word):
78
  except Exception as e:
79
  return f"Failed to create pronunciation audio: {e}"
80
 
81
- # Step 3: Compare the transcribed text with the input paragraph and add phonetic transcription
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  def compare_texts(reference_text, transcribed_text):
83
  reference_words = reference_text.split()
84
  transcribed_words = transcribed_text.split()
@@ -101,9 +116,9 @@ def compare_texts(reference_text, transcribed_text):
101
  html_output += f"<strong>Quality Score:</strong> {similarity_score}%<br>"
102
  html_output += f"<strong>Transcribed Text:</strong> {transcribed_text}<br>"
103
 
104
- # Add phonetic transcription for the entire sentence
105
- phonetic_transcription = " ".join([pronouncing.phones_for_word(word)[0] if pronouncing.phones_for_word(word) else word for word in transcribed_words])
106
- html_output += f"<strong>Phonetic Transcription:</strong> {phonetic_transcription}<br>"
107
 
108
  html_output += "<strong>Word Score List:</strong><br>"
109
 
@@ -135,7 +150,7 @@ def compare_texts(reference_text, transcribed_text):
135
  html_output += f'{word}: '
136
  html_output += f'<audio controls><source src="{audio_src}" type="audio/mpeg">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
137
 
138
- # Return the final result with phonetic transcription
139
  return [html_output]
140
 
141
  # Step 4: Text-to-Speech Function
 
7
  import io
8
  from pydub import AudioSegment
9
  import time
10
+ import re
11
 
12
  # Create audio directory if it doesn't exist
13
  if not os.path.exists('audio'):
 
78
  except Exception as e:
79
  return f"Failed to create pronunciation audio: {e}"
80
 
81
+ # Function to respell words phonetically
82
+ def phonetic_respelling(word):
83
+ word = word.lower()
84
+ respelling = word
85
+ # Simplified phonetic transformations
86
+ respelling = re.sub(r'th', 'th', respelling) # 'th' as in 'the'
87
+ respelling = re.sub(r'[aeiou]', lambda m: f'{m.group(0)}', respelling) # Simplify vowels
88
+ respelling = re.sub(r'c', 'k', respelling) # 'c' sounds like 'k'
89
+ respelling = re.sub(r'ph', 'f', respelling) # 'ph' as 'f'
90
+ respelling = re.sub(r'ch', 'ch', respelling) # 'ch' as in 'church'
91
+ respelling = re.sub(r'qu', 'kw', respelling) # 'qu' as 'kw'
92
+ respelling = re.sub(r'sh', 'sh', respelling) # 'sh' as in 'shoe'
93
+ respelling = re.sub(r'[^a-z]', '', respelling) # Remove non-alphabet characters
94
+ return respelling
95
+
96
+ # Step 3: Compare the transcribed text with the input paragraph and add phonetic respelling
97
  def compare_texts(reference_text, transcribed_text):
98
  reference_words = reference_text.split()
99
  transcribed_words = transcribed_text.split()
 
116
  html_output += f"<strong>Quality Score:</strong> {similarity_score}%<br>"
117
  html_output += f"<strong>Transcribed Text:</strong> {transcribed_text}<br>"
118
 
119
+ # Add phonetic respelling for the entire sentence
120
+ phonetic_transcription = " ".join([phonetic_respelling(word) for word in transcribed_words])
121
+ html_output += f"<strong>Phonetic Respelling:</strong> {phonetic_transcription}<br>"
122
 
123
  html_output += "<strong>Word Score List:</strong><br>"
124
 
 
150
  html_output += f'{word}: '
151
  html_output += f'<audio controls><source src="{audio_src}" type="audio/mpeg">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
152
 
153
+ # Return the final result with phonetic respelling
154
  return [html_output]
155
 
156
  # Step 4: Text-to-Speech Function