|
|
import streamlit as st |
|
|
import pyttsx3 |
|
|
import speech_recognition as sr |
|
|
from gtts import gTTS |
|
|
import tempfile |
|
|
import os |
|
|
|
|
|
|
|
|
engine = pyttsx3.init() |
|
|
|
|
|
|
|
|
def speak_text(text): |
|
|
|
|
|
tts = gTTS(text=text, lang='en') |
|
|
tts.save("sentence.mp3") |
|
|
|
|
|
os.system("start sentence.mp3") |
|
|
|
|
|
|
|
|
def record_speech(): |
|
|
recognizer = sr.Recognizer() |
|
|
with sr.Microphone() as source: |
|
|
st.write("Listening... Speak now!") |
|
|
audio = recognizer.listen(source) |
|
|
try: |
|
|
|
|
|
recognized_text = recognizer.recognize_google(audio) |
|
|
st.write(f"Recognized: {recognized_text}") |
|
|
return recognized_text |
|
|
except sr.UnknownValueError: |
|
|
st.write("Sorry, I could not understand your speech.") |
|
|
return None |
|
|
except sr.RequestError: |
|
|
st.write("Could not request results from Google Speech Recognition service.") |
|
|
return None |
|
|
|
|
|
|
|
|
with tab2: |
|
|
st.header("2: English Shadowing Practice") |
|
|
|
|
|
st.write("In this section, you can practice your English speaking and reading skills.") |
|
|
|
|
|
sentence = st.text_area("Enter the sentence you want to practice", "Hello, how are you doing today?") |
|
|
|
|
|
|
|
|
if st.button("Listen to the Sentence"): |
|
|
speak_text(sentence) |
|
|
|
|
|
|
|
|
if st.button("Record Your Speech"): |
|
|
recognized_text = record_speech() |
|
|
if recognized_text: |
|
|
if recognized_text.lower() == sentence.lower(): |
|
|
st.success("Great job! Your pronunciation is correct.") |
|
|
else: |
|
|
st.warning("Oops! Your pronunciation is a bit off. Try again!") |
|
|
|