Spaces:
Runtime error
Runtime error
Download interface.py from finaspirant/SearchWithVoice: direct link, hf CLI and curl.
- Browser
- Download file 679 Bytes
-
https://huggingface.co/spaces/finaspirant/SearchWithVoice/resolve/main/interface.py
- Command line
-
hf download hf://spaces/finaspirant/SearchWithVoice/interface.py
-
curl -L -o interface.py https://huggingface.co/spaces/finaspirant/SearchWithVoice/resolve/main/interface.py
679 Bytes
| import os | |
| import speech_recognition as sr | |
| from elevenlabs import generate, play, set_api_key | |
| set_api_key(os.environ['ELEVEN_API_KEY']) | |
| class AudioInterface: | |
| def listen(self) -> str: | |
| recognizer = sr.Recognizer() | |
| with sr.Microphone() as source: | |
| print("Say something!") | |
| audio = recognizer.listen(source) | |
| text = recognizer.recognize_whisper_api( | |
| audio, | |
| api_key=os.environ['OPENAI_API_KEY'], | |
| ) | |
| return text | |
| def speak(self, text): | |
| audio = generate( | |
| text=text, | |
| voice='Bella', | |
| model='eleven_monolingual_v1' | |
| ) | |
| return play(audio) |