Spaces:
Runtime error
Runtime error
Download speech_input.py from innocentpeter/talkAI: direct link, hf CLI and curl.
- Browser
- Download file 564 Bytes
-
https://huggingface.co/spaces/innocentpeter/talkAI/resolve/main/speech_input.py
- Command line
-
hf download hf://spaces/innocentpeter/talkAI/speech_input.py
-
curl -L -o speech_input.py https://huggingface.co/spaces/innocentpeter/talkAI/resolve/main/speech_input.py
564 Bytes
| import speech_recognition as sr | |
| class SpeechInput: | |
| def __init__(self): | |
| self.recognizer = sr.Recognizer() | |
| def listen(self, prompt="Speak/Type now..."): | |
| print(f"\n[{prompt}] 🎙️ Listening...") | |
| try: | |
| with sr.Microphone() as source: | |
| audio = self.recognizer.listen(source, timeout=5, phrase_time_limit=10) | |
| return self.recognizer.recognize_google(audio) | |
| except Exception: | |
| # fallback: manual typing | |
| return input(f"[{prompt}] (typing fallback): ") | |