Spaces:
Build error
Build error
import streamlit as st | |
import speech_recognition as sr | |
def main(): | |
st.title("Speech to Text - Open Source") | |
# Instructions | |
st.write("Click the button below to start recording your voice.") | |
# Button to start recording | |
if st.button("Start Recording"): | |
recognizer = sr.Recognizer() | |
try: | |
with sr.Microphone() as source: | |
st.write("Listening... Please speak clearly.") | |
audio = recognizer.listen(source, timeout=5, phrase_time_limit=10) | |
st.write("Processing the audio...") | |
text = recognizer.recognize_google(audio, language='fa-IR') # Change language if needed | |
st.write(f"Recognized Text: {text}") | |
except sr.UnknownValueError: | |
st.write("Could not understand the audio.") | |
except sr.RequestError: | |
st.write("Error: Unable to connect to the speech recognition service.") | |
except Exception as e: | |
st.write(f"An error occurred: {str(e)}") | |
if __name__ == '__main__': | |
main() | |