Spaces:
Sleeping
Sleeping
Update app.py
Browse files13 unmodified lines14151617171820211923242021222324262528293026272829303132333435363738393435363738394041424344454647484950515213 unmodified lines os.system(f"start {temp_file.name}") # Windows return "✅ Text is being read out. Please listen and read it yourself."
# Function to transcribe user's audiodef transcribe_audio(audio, original_text): recognizer = sr.Recognizer() with sr.AudioFile(audio) as source: audio_data = recognizer.record(source) try: start_time = time.time() # Using Google Speech Recognition (supports Hindi) with sr.AudioFile(audio) as source: audio_data = recognizer.record(source) # Try chunking if needed transcription = recognizer.recognize_google(audio_data, language="hi-IN") end_time = time.time() # Calculate Accuracy original_words = original_text.strip().split() transcribed_words = transcription.strip().split() # Clean and split the text better (remove punctuations etc.) import re original_words = re.findall(r'\w+', original_text.strip()) transcribed_words = re.findall(r'\w+', transcription.strip()) matcher = difflib.SequenceMatcher(None, original_words, transcribed_words) accuracy = round(matcher.ratio() * 100, 2) # Calculate speed duration = end_time - start_time # time to process (not speaking time) # Better: estimate speaking time from audio length if needed (advanced) speed = round(len(transcribed_words) / duration, 2) # words per second speed = round(len(transcribed_words) / (len(audio_data.frame_data) / audio_data.sample_rate), 2)
result = { "📝 Transcribed Text": transcription, "🎯 Accuracy (%)": accuracy, "⏱️ Speaking Speed (words/sec)": speed } return result except sr.UnknownValueError: return {"error": "Could not understand audio"} except sr.RequestError as e: return {"error": f"Request error: {e}"} except Exception as e: return {"error": str(e)}
# Gradio Appwith gr.Blocks() as app: gr.Markdown("## 🗣️ Hindi Reading & Pronunciation Practice App")app.py+16-15