commit
6f248ca809
@ -0,0 +1,12 @@ |
||||
#!/usr/bin/env python |
||||
|
||||
from modules.hue.hue_controller import controller |
||||
from modules.hue.hue_remote import parseCommandline |
||||
|
||||
def init(): |
||||
controller.init() # very important to initialize the controller |
||||
parseCommandline() |
||||
controller.end() # also to end it |
||||
|
||||
if __name__ == "__main__": |
||||
init() |
@ -1,6 +0,0 @@ |
||||
################################## |
||||
# RENAME THIS FILE TO "config.py"# |
||||
################################## |
||||
|
||||
address = "" |
||||
username = "" |
@ -0,0 +1,4 @@ |
||||
# Hue Remote Settings |
||||
class hue_config: |
||||
address = "192.168.0.3" |
||||
username = "E0ru0AeVFKEH1E30X40JAJfovg4Uu1aTkdrKQ2Oi" |
@ -0,0 +1,8 @@ |
||||
################################## |
||||
# RENAME THIS FILE TO "config.py"# |
||||
################################## |
||||
|
||||
# Hue Remote Settings |
||||
class hue_config: |
||||
address = "" # Local IPv4 address to the HUE bridge |
||||
username = "" # Username for the bridge |
@ -0,0 +1,37 @@ |
||||
import speech_recognition as sr |
||||
|
||||
class voiceInput(object): |
||||
recognizer = sr.Recognizer() |
||||
|
||||
muted = True |
||||
|
||||
# "Error codes", can be used to check stuff |
||||
what = "??" |
||||
error = "ERROR" |
||||
|
||||
def start( self, deviceIndex=30 ): # a generator for everything that is said |
||||
while( True ): # loop |
||||
try: |
||||
if( not self.muted ): # this thing is not the NSA |
||||
with sr.Microphone( deviceIndex ) as src: |
||||
self.recognizer.adjust_for_ambient_noise( src, 0.2 ) |
||||
print("Listening...") |
||||
audio = self.recognizer.listen( src, phrase_time_limit=5 ) |
||||
print("Thinking...") |
||||
text = self.recognizer.recognize_google(audio) |
||||
yield text |
||||
|
||||
except sr.RequestError as err: |
||||
print("Unable to request results: {0}".format(err)) |
||||
yield self.error |
||||
|
||||
except sr.UnknownValueError: |
||||
yield self.what |
||||
|
||||
|
||||
def setMuted( self, setm: bool=True ): |
||||
self.muted = setm |
||||
|
||||
def switchMute( self ): |
||||
self.setMuted( not self.muted ) |
||||
|
@ -1,36 +0,0 @@ |
||||
import speech_recognition as sr |
||||
|
||||
class sr_microphone(object): |
||||
recognizer = sr.Recognizer() |
||||
|
||||
muted = True |
||||
|
||||
def getInput(self): # use the object as a generator |
||||
print("Awaiting input") |
||||
if( not self.muted ): |
||||
try: |
||||
with sr.Microphone() as src: |
||||
self.recognizer.adjust_for_ambient_noise( src, duration=0.2 ) # adjust for ambient noise |
||||
|
||||
audio = self.recognizer.listen(src) |
||||
|
||||
# Make audio -> text |
||||
return (self.recognizer.recognize_google( audio )).lower() # use googles recognizer and lower its output |
||||
|
||||
except sr.RequestError as err: |
||||
print("Unable to request results: {0}".format(err)) |
||||
|
||||
except sr.UnknownValueError as err: |
||||
print("Unknown Error: {0}".format(err)) |
||||
|
||||
def setMuted( self, setm: bool=True ): |
||||
self.muted = setm |
||||
|
||||
def switchMute( self ): |
||||
self.setMuted( not self.muted ) |
||||
|
||||
|
||||
# Small test |
||||
voice = sr_microphone() |
||||
voice.setMuted(False) |
||||
print( voice.getInput() ) |
@ -0,0 +1,29 @@ |
||||
#!/usr/bin/env python |
||||
|
||||
from modules.hue.hue_remote import parseCommandline |
||||
from modules.hue.hue_controller import controller |
||||
from modules.speech.speech import voiceInput |
||||
|
||||
prefixes = ["computer", "computers"] |
||||
|
||||
class speech_daemon(object): |
||||
voiceInpObj = None |
||||
|
||||
def __init__(self, deviceIndex=30): |
||||
self.voiceInpObj = voiceInput() |
||||
self.voiceInpObj.setMuted(False) |
||||
|
||||
def start(self): |
||||
controller.init() |
||||
|
||||
for inp in self.voiceInpObj.start(): |
||||
cmdBuf = inp.lower().split(" ") |
||||
if( cmdBuf[0] in prefixes ): |
||||
print("CMD:", cmdBuf) |
||||
parseCommandline( cmdBuf, False ) |
||||
|
||||
controller.end() |
||||
|
||||
if __name__ == "__main__": |
||||
daemon = speech_daemon() |
||||
daemon.start() |
Loading…
Reference in new issue