|
|
import streamlit as st |
|
|
import speech_recognition as sr |
|
|
|
|
|
def main(): |
|
|
st.title("Speech Recognition App") |
|
|
|
|
|
|
|
|
audio_bytes = st.microphone() |
|
|
|
|
|
if audio_bytes: |
|
|
st.audio(audio_bytes, format="audio/wav") |
|
|
|
|
|
|
|
|
r = sr.Recognizer() |
|
|
try: |
|
|
|
|
|
text = r.recognize_google(audio_bytes, language="th-TH") |
|
|
st.write(f"คำที่รับรู้: {text}") |
|
|
except sr.UnknownValueError: |
|
|
st.write("ไม่สามารถรับรู้เสียงได้") |
|
|
except sr.RequestError as e: |
|
|
st.write(f"ไม่สามารถขอผลลัพธ์จาก Google Speech Recognition service; {e}") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |