Spaces:
Runtime error
Runtime error
import csv | |
import os | |
from concurrent.futures import ThreadPoolExecutor | |
from loguru import logger | |
from app.utils.common import convert_mp3_to_wav, get_doc, transcribe_audio | |
from app.utils.comprehension import evaluate_comprehension | |
from app.utils.grammar import evaluate_grammar | |
from app.utils.intonation import evaluate_intonation | |
def get_content_score(audio_file): | |
if audio_file.endswith("mp3"): | |
wav_file = convert_mp3_to_wav(audio_file) | |
else: | |
wav_file = audio_file | |
# Step 2: Transcribe the WAV to text | |
transcript = transcribe_audio(wav_file) | |
doc = get_doc(transcript) | |
with ThreadPoolExecutor() as executor: | |
futures = [ | |
executor.submit(evaluate_intonation, wav_file), | |
executor.submit(evaluate_grammar, transcript, doc), | |
executor.submit(evaluate_comprehension, transcript, doc), | |
] | |
return { | |
"intonation_score": round((float(futures[0].result().get("intonation_score")) * 10), 2), | |
"grammar_score": round((float(futures[1].result().get("grammar_score")) * 10), 2), | |
"grammar_errors": futures[1].result().get("errors"), | |
"comprehension_score": round((float(futures[2].result().get("comprehension_score")) * 10), 2), | |
} | |