Spaces:
Sleeping
Sleeping
Update app.py
Browse files13 unmodified lines1415161718192021222324252627284 unmodified lines333435363738394041424344454620 unmodified lines676869707113 unmodified linesos.system(f"start {temp_file.name}") # Windowsreturn "β 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)transcription = recognizer.recognize_google(audio_data, language="hi-IN")end_time = time.time()# Calculate Accuracy4 unmodified lines# Calculate speedduration = 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 secondresult = {"π Transcribed Text": transcription,"π― Accuracy (%)": accuracy,"β±οΈ Speaking Speed (words/sec)": speed}return resultexcept Exception as e:20 unmodified lines# Launch the appapp.launch()13 unmodified lines1415161718192021222324252627282930313233343536373839404 unmodified lines4546474849505152535455565758596061626320 unmodified lines84858613 unmodified linesos.system(f"start {temp_file.name}") # Windowsreturn "β Text is being read out. Please listen and read it yourself."# Function to transcribe user's audio and compare with the original textdef transcribe_audio(audio, original_text):recognizer = sr.Recognizer()with sr.AudioFile(audio) as source:audio_data = recognizer.record(source)try:start_time = time.time()# Split the audio into chunks (1-minute chunks in this example)audio_length = len(audio_data.frame_data)chunk_size = 60000 # 1 minute (60,000 ms)# Splitting audio data into chunkschunks = [audio_data.frame_data[i:i+chunk_size] for i in range(0, audio_length, chunk_size)]transcription = ""for chunk in chunks:audio_chunk = sr.AudioData(chunk, audio_data.sample_rate, audio_data.sample_width)# Using Google Speech Recognition (supports Hindi)transcription += recognizer.recognize_google(audio_chunk, language="hi-IN") + " "end_time = time.time()# Calculate Accuracy4 unmodified lines# Calculate speedduration = end_time - start_time # time to process (not speaking time)speed = round(len(transcribed_words) / duration, 2) # words per second# Compare words and highlight mistakeswrong_words = []for i, word in enumerate(original_words):if i >= len(transcribed_words) or word != transcribed_words[i]:wrong_words.append(f"π΄ {word}")result = {"π Transcribed Text": transcription,"π― Accuracy (%)": accuracy,"β±οΈ Speaking Speed (words/sec)": speed,"β Incorrect Words": ' '.join(wrong_words) if wrong_words else "None"}return resultexcept Exception as e:20 unmodified lines# Launch the appapp.launch()
app.py+23-8