Download app.py from Rathapoom/test_mic: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/Rathapoom/test_mic/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rathapoom/test_mic/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rathapoom/test_mic/resolve/main/app.py
1.07 kB
| 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() |