Spaces:
Build error
Build error
Download app.py from DataWizard9742/SalesPerson: direct link, hf CLI and curl.
- Browser
- Download file 903 Bytes
-
https://huggingface.co/spaces/DataWizard9742/SalesPerson/resolve/main/app.py
- Command line
-
hf download hf://spaces/DataWizard9742/SalesPerson/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DataWizard9742/SalesPerson/resolve/main/app.py
903 Bytes
| import speech_recognition as sr | |
| from gtts import gTTS | |
| from playsound import playsound | |
| def speech_to_text(): | |
| recognizer = sr.Recognizer() | |
| with sr.Microphone() as source: | |
| print("Speak something...") | |
| audio = recognizer.listen(source) | |
| try: | |
| user_input = recognizer.recognize_google(audio) | |
| return user_input | |
| except sr.UnknownValueError: | |
| print("Sorry, could not understand audio.") | |
| return None | |
| except sr.RequestError as e: | |
| print("Could not request results; {0}".format(e)) | |
| return None | |
| def text_to_speech(text): | |
| tts = gTTS(text=text, lang='en') | |
| tts.save("output.mp3") | |
| playsound("output.mp3") | |
| def main(): | |
| user_input = speech_to_text() | |
| if user_input: | |
| print("You said:", user_input) | |
| text_to_speech(user_input) | |
| if __name__ == "__main__": | |
| main() | |