Add verification for words in speaking grading.

This commit is contained in:
Cristiano Ferreira
2023-09-05 20:31:30 +01:00
parent eb6e9b4ef7
commit 8e043104ad
2 changed files with 30 additions and 19 deletions

View File

@@ -1,7 +1,9 @@
import whisper
import os
import gtts
from playsound import playsound
import nltk
nltk.download('words')
from nltk.corpus import words
def speech_to_text(file_path):
if os.path.exists(file_path):
@@ -14,4 +16,9 @@ def speech_to_text(file_path):
def text_to_speech(text: str, file_name: str):
tts = gtts.gTTS(text)
tts.save(file_name)
tts.save(file_name)
def has_words(text: str):
english_words = set(words.words())
words_in_input = text.split()
return any(word.lower() in english_words for word in words_in_input)