Merge pull request #5 from E-Almqvist/speechCMD

Added a working speech controller.
fetchIP
E. Almqvist 4 years ago committed by GitHub
commit 6f248ca809
  1. 12
      hue_cmd.py
  2. 6
      hue_remote/default-config.py
  3. 0
      modules/hue/__init__.py
  4. 0
      modules/hue/__main__.py
  5. 4
      modules/hue/config.py
  6. 8
      modules/hue/default-config.py
  7. 8
      modules/hue/hue_controller.py
  8. 25
      modules/hue/hue_remote.py
  9. 0
      modules/hue/lib/func.py
  10. 0
      modules/hue/presets.py
  11. 0
      modules/speech/__init__.py
  12. 0
      modules/speech/__main__.py
  13. 37
      modules/speech/speech.py
  14. 36
      speech/speech.py
  15. 29
      speech_daemon.py

@ -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

@ -3,17 +3,17 @@ import json # API uses JSON
import asyncio # ASync stuff
import time
from lib.func import * # useful functions
from .lib.func import * # useful functions
import config # Configuration for the controller (/config.py <- change this file)
from presets import * # presets for the lights
from .config import * # Configuration for the controller (/config.py <- change this file)
from .presets import * # presets for the lights
LIGHTS = {} # dictionary of all the lights
loop = asyncio.get_event_loop() # ASync loop
def genUrl(params: str):
return "http://" + config.address + "/api/" + config.username + params
return "http://" + hue_config.address + "/api/" + hue_config.username + params
class APIrequest:
# Get Req

@ -3,7 +3,7 @@
import sys
import hue_controller as hue # Actual controller
from modules.hue import hue_controller as hue # Actual controller
cmd = "hue"
@ -31,8 +31,7 @@ boolConvert = {
# this is the most spaghetti-ish code I have ever written but it works
def parseCommand( cmd:list, pos:int, i=-1 ):
index = int(i)
def parseCommand( cmd:list, pos:int, index=-1, displayHelp=True ):
try:
if( cmd[pos] == "on" or cmd[pos] == "off" ):
if( index == -1 ):
@ -82,26 +81,18 @@ def parseCommand( cmd:list, pos:int, i=-1 ):
help() # display help if function did nothing
except (RuntimeError, TypeError, NameError, IndexError) as err:
if(displayHelp):
help() # display the help page if parameters are missing (it will give out an IndexError)
print( "\n\nError: " + str(err) )
print( "\n\nError: " + str(err) )
def parseCommandline():
cmd = sys.argv
def parseCommandline( cmd=sys.argv, needHelp=True ):
if( len(cmd) > 1 ):
if( cmd[1] == "light" ):
parseCommand( cmd, 3, cmd[2] )
parseCommand( cmd, 3, cmd[2], displayHelp=needHelp )
elif( cmd[1] == "lights" ):
parseCommand( cmd, 2 )
else:
parseCommand( cmd, 2, displayHelp=needHelp )
elif( needHelp ):
help()
def init():
hue.controller.init() # very important to initialize the controller
parseCommandline()
hue.controller.end() # also to end it
init() # actually call the init function

@ -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…
Cancel
Save