File size: 1,072 Bytes
9514810 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import streamlit as st
import speech_recognition as sr
def main():
st.title("Speech Recognition App")
# ใช้ st.microphone() เพื่อรับเสียงจากไมโครโฟน
audio_bytes = st.microphone()
if audio_bytes:
st.audio(audio_bytes, format="audio/wav")
# ใช้ speech_recognition library เพื่อแปลงเสียงเป็นข้อความ
r = sr.Recognizer()
try:
# แปลงเสียงเป็นข้อความโดยใช้ Google Speech Recognition
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() |