ソースを参照

wunderlist, cleanup

Martin 10 年 前
親
コミット
1691433948
6 ファイル変更、63 行追加、7 行削除
  1. 4 0
      .vscode/settings.json
  2. 12 1
      README.md
  3. 0 3
      dependencies.txt
  4. 43 0
      functions/todo.py
  5. 3 3
      main.py
  6. 1 0
      trigger.py

+ 4 - 0
.vscode/settings.json

@@ -0,0 +1,4 @@
+// Place your settings in this file to overwrite default and user settings.
+{
+    "python.pythonPath": "/home/martin/venvs/snowboy/bin/python"
+}

+ 12 - 1
README.md

@@ -1,2 +1,13 @@
-# voice_control
+Voice Control
+
+Python requirements:
+googleapiclient
+pygame
+pyaudio
+gTTS
+requests
+
+PortAudio: 
+http://portaudio.com/download.html
+download, configure, make, make install
 
 

+ 0 - 3
dependencies.txt

@@ -1,3 +0,0 @@
-PortAudio: http://portaudio.com/download.html
-  download, configure, make, make install
-

+ 43 - 0
functions/todo.py

@@ -3,11 +3,53 @@ import base
 import tts
 import tts
 import clips
 import clips
 import ears
 import ears
+import requests
 
 
 _LISTEN_TIMEOUT = 600
 _LISTEN_TIMEOUT = 600
 _GROCERIES = ['milk', 'bread']
 _GROCERIES = ['milk', 'bread']
 
 
+_WUNDERLIST_CLIENT_ID = '34e0e31945afeb63e1b8'
+_WUNDERLIST_ACCESS_TOKEN = 'a7258e8b6596fdaffc904fc6b65d40c23afe6d2a28bfe7be1a9026d44b59'
+
+class WunderlistClient(object):
+    lists = None
+    
+    def __init__(self, client_id, access_token):
+        self.client_id = client_id
+        self.access_token = access_token
+    
+    def call(self, method, url, body=None):
+        headers = {
+            'x-client-id': self.client_id,
+            'x-access-token': self.access_token,
+            'content-type': 'application/json',
+            'accept': 'application/json'
+        }
+
+        resp = requests.request(method, url, headers=headers, json=body)
+        
+        if resp.status_code < 300:
+            return resp.json()
+        else:
+            raise Exception(resp.content)
+
+    def create_task(self, list_id, title):
+        self.call('POST', 'https://a.wunderlist.com/api/v1/tasks', {'list_id': list_id, 'title': title})
+
+    def init(self):
+        lists_res = self.call('GET', 'https://a.wunderlist.com/api/v1/lists')
+        self.lists = {x['title'].lower(): x['id'] for x in lists_res}
+    
+c =  WunderlistClient(_WUNDERLIST_CLIENT_ID, _WUNDERLIST_ACCESS_TOKEN)
+c.init()
+c.create_task(c.lists['food'], 'Test #1')
+
+"""
 class WunderbarTodo(base.BaseFunction):
 class WunderbarTodo(base.BaseFunction):
+    def init(self):
+        self.client = WunderlistClient(_WUNDERLIST_CLIENT_ID, _WUNDERLIST_ACCESS_TOKEN)
+        return self.client.init()
+
     def _groceries(self):
     def _groceries(self):
         tts.tts('ready')
         tts.tts('ready')
 
 
@@ -33,3 +75,4 @@ class WunderbarTodo(base.BaseFunction):
         else:
         else:
             tts.tts('Bad trigger')
             tts.tts('Bad trigger')
 
 
+"""

+ 3 - 3
main.py

@@ -15,15 +15,15 @@ MODELS = [{
     'model': 'resources/snowboy/alexa.umdl',
     'model': 'resources/snowboy/alexa.umdl',
     'callbacks': {
     'callbacks': {
         'email': functions.email.Email(),
         'email': functions.email.Email(),
-        'food': functions.todo.WunderbarTodo(),
+#        'food': functions.todo.W,
         'play': functions.music.Music(),
         'play': functions.music.Music(),
     }
     }
 }]
 }]
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     init()
     init()
-    #trigger.start(MODELS)
+    trigger.start(MODELS)
     #trigger.loop_model(MODELS[0])
     #trigger.loop_model(MODELS[0])
 
 
-    trigger._callback(MODELS[0])
+    #trigger._callback(MODELS[0])
     #functions.music.Music().call(['elton'])
     #functions.music.Music().call(['elton'])

+ 1 - 0
trigger.py

@@ -54,6 +54,7 @@ def start(models):
             _callback(m)
             _callback(m)
         callbacks.append(c)
         callbacks.append(c)
 
 
+    logging.info('Launching Snowboy hotword detector...')
     signal.signal(signal.SIGINT, _signal_handler)
     signal.signal(signal.SIGINT, _signal_handler)
     detector = snowboy.snowboydecoder.HotwordDetector([m['model'] for m in models], sensitivity=[m.get('sensitivity', DEFAULT_SENSITIVITY) for m in models])
     detector = snowboy.snowboydecoder.HotwordDetector([m['model'] for m in models], sensitivity=[m.get('sensitivity', DEFAULT_SENSITIVITY) for m in models])
     detector.start(detected_callback=callbacks, interrupt_check=_interrupt_callback, sleep_time=0.03)
     detector.start(detected_callback=callbacks, interrupt_check=_interrupt_callback, sleep_time=0.03)