Created
September 7, 2017 21:51
-
-
Save cuuupid/e25536daf57a27b07ab2e7a448c3a606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pyttsx | |
| import speech_recognition as sr | |
| from console_logging import console | |
| import sys | |
| import os | |
| import requests | |
| _this = sys.modules[__name__] | |
| console.info("Initializing TTS engine...") | |
| _this.engine = pyttsx.init() | |
| console.info("Initializing STT engine...") | |
| r = sr.Recognizer() | |
| console.success("Welcome to Open-source Caesar Voice (OpenCV)!") | |
| remote_server = 'http://192.168.1.114:7200/trigger' | |
| waiting = False | |
| with sr.Microphone() as source: | |
| r.adjust_for_ambient_noise(source) | |
| while True: | |
| if not waiting: | |
| console.info("Waiting on wakeword \'elly\'.") | |
| waiting = True | |
| audio = r.listen(source, phrase_time_limit=2) | |
| try: | |
| recognized = r.recognize_sphinx(audio) | |
| console.log(recognized) | |
| if 'elly' in recognized or 'ellie' in recognized or 'deli' in recognized: | |
| console.info("LISTENING") | |
| audio = r.listen(source, phrase_time_limit=7) | |
| res = requests.post(remote_server, files={ | |
| 'file': audio.get_wav_data()}) | |
| transcription = res.text | |
| console.success(transcription) | |
| _this.engine.say(transcription) | |
| _this.engine.runAndWait() | |
| except sr.UnknownValueError: | |
| console.error("Sphinx could not understand audio") | |
| pass | |
| except sr.RequestError as e: | |
| console.error("Sphinx error; {0}".format(e)) | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment