Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,6 @@ 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:
|
|
@@ -22,21 +21,34 @@ def transcribe_audio(audio, original_text):
|
|
| 22 |
|
| 23 |
try:
|
| 24 |
start_time = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Split the audio into chunks (1-minute chunks in this example)
|
| 26 |
audio_length = len(audio_data.frame_data)
|
| 27 |
chunk_size = 60000 # 1 minute (60,000 ms)
|
| 28 |
|
| 29 |
# Splitting audio data into chunks
|
| 30 |
chunks = [audio_data.frame_data[i:i+chunk_size] for i in range(0, audio_length, chunk_size)]
|
|
|
|
| 31 |
|
| 32 |
transcription = ""
|
| 33 |
for chunk in chunks:
|
| 34 |
audio_chunk = sr.AudioData(chunk, audio_data.sample_rate, audio_data.sample_width)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# Using Google Speech Recognition (supports Hindi)
|
| 36 |
transcription += recognizer.recognize_google(audio_chunk, language="hi-IN") + " "
|
| 37 |
|
| 38 |
end_time = time.time()
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
# Calculate Accuracy
|
| 41 |
original_words = original_text.strip().split()
|
| 42 |
transcribed_words = transcription.strip().split()
|
|
@@ -63,6 +75,8 @@ def transcribe_audio(audio, original_text):
|
|
| 63 |
except Exception as e:
|
| 64 |
return {"error": str(e)}
|
| 65 |
|
|
|
|
|
|
|
| 66 |
# Gradio App
|
| 67 |
with gr.Blocks() as app:
|
| 68 |
gr.Markdown("## 🗣️ Hindi Reading & Pronunciation Practice App")
|
|
|
|
| 14 |
os.system(f"start {temp_file.name}") # Windows
|
| 15 |
return "✅ Text is being read out. Please listen and read it yourself."
|
| 16 |
|
|
|
|
| 17 |
def transcribe_audio(audio, original_text):
|
| 18 |
recognizer = sr.Recognizer()
|
| 19 |
with sr.AudioFile(audio) as source:
|
|
|
|
| 21 |
|
| 22 |
try:
|
| 23 |
start_time = time.time()
|
| 24 |
+
|
| 25 |
+
# Debug: Check audio data length and properties
|
| 26 |
+
print(f"Audio Data Length: {len(audio_data.frame_data)}")
|
| 27 |
+
print(f"Sample Rate: {audio_data.sample_rate}")
|
| 28 |
+
|
| 29 |
# Split the audio into chunks (1-minute chunks in this example)
|
| 30 |
audio_length = len(audio_data.frame_data)
|
| 31 |
chunk_size = 60000 # 1 minute (60,000 ms)
|
| 32 |
|
| 33 |
# Splitting audio data into chunks
|
| 34 |
chunks = [audio_data.frame_data[i:i+chunk_size] for i in range(0, audio_length, chunk_size)]
|
| 35 |
+
print(f"Number of chunks: {len(chunks)}")
|
| 36 |
|
| 37 |
transcription = ""
|
| 38 |
for chunk in chunks:
|
| 39 |
audio_chunk = sr.AudioData(chunk, audio_data.sample_rate, audio_data.sample_width)
|
| 40 |
+
|
| 41 |
+
# Debug: Print chunk size
|
| 42 |
+
print(f"Transcribing Chunk: {len(chunk)}")
|
| 43 |
+
|
| 44 |
# Using Google Speech Recognition (supports Hindi)
|
| 45 |
transcription += recognizer.recognize_google(audio_chunk, language="hi-IN") + " "
|
| 46 |
|
| 47 |
end_time = time.time()
|
| 48 |
|
| 49 |
+
# Debug: Output full transcription
|
| 50 |
+
print(f"Transcribed Text: {transcription}")
|
| 51 |
+
|
| 52 |
# Calculate Accuracy
|
| 53 |
original_words = original_text.strip().split()
|
| 54 |
transcribed_words = transcription.strip().split()
|
|
|
|
| 75 |
except Exception as e:
|
| 76 |
return {"error": str(e)}
|
| 77 |
|
| 78 |
+
return {"error": str(e)}
|
| 79 |
+
|
| 80 |
# Gradio App
|
| 81 |
with gr.Blocks() as app:
|
| 82 |
gr.Markdown("## 🗣️ Hindi Reading & Pronunciation Practice App")
|