Last active
August 20, 2017 10:34
-
-
Save Wqrld/29ad57e45b9e9d28cc9040c8fd32b1ea to your computer and use it in GitHub Desktop.
w.i.p. jarvis home assistant
This file contains 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
#!/usr/bin/env python | |
# Copyright (C) 2017 Luc H and Google Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
from __future__ import print_function | |
import argparse | |
import os.path | |
import json | |
import google.oauth2.credentials | |
from google.assistant.library import Assistant | |
from google.assistant.library.event import EventType | |
from google.assistant.library.file_helpers import existing_file | |
import sys | |
import signal | |
model = 'jarvis.pmdl' | |
import snowboydecoder | |
detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5) | |
interrupted = False | |
def signal_handler(signal, frame): | |
global interrupted | |
interrupted = True | |
def interrupt_callback(): | |
global interrupted | |
return interrupted | |
signal.signal(signal.SIGINT, signal_handler) | |
def process_event(event): | |
"""Pretty prints events. | |
Prints all events that occur with two spaces between each new | |
conversation and a single space between turns of a conversation. | |
Args: | |
event(event.Event): The current event to process. | |
""" | |
if event.type == EventType.ON_CONVERSATION_TURN_STARTED: | |
print() | |
print(event) | |
if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and | |
event.args and not event.args['with_follow_on_turn']): | |
print() | |
def main(): | |
global credentials | |
parser = argparse.ArgumentParser( | |
formatter_class=argparse.RawTextHelpFormatter) | |
parser.add_argument('--credentials', type=existing_file, | |
metavar='OAUTH2_CREDENTIALS_FILE', | |
default=os.path.join( | |
os.path.expanduser('~/.config'), | |
'google-oauthlib-tool', | |
'credentials.json' ), | |
help='Path to store and read OAuth2 credentials') | |
args = parser.parse_args() | |
with open(args.credentials, 'r') as f: | |
credentials = google.oauth2.credentials.Credentials(token=None,**json.load(f)) | |
print(credentials) | |
# with Assistant(credentials) as assistant: | |
# for event in assistant.start(): | |
# process_event(event) | |
if __name__ == '__main__': | |
main() | |
def detect_callback(): | |
with Assistant(credentials) as assistant: | |
print('ja baas?') | |
detector.terminate() | |
print("ik laat google maar zn werk doen") | |
snowboydecoder.play_audio_file(snowboydecoder.DETECT_DING) | |
assistant.start_conversation() | |
snowboydecoder.play_audio_file(snowboydecoder.DETECT_DONG) | |
print("bye") | |
detector.start(detected_callback=detect_callback, interrupt_check=interrupt_callback, sleep_time=0.03) | |
print("ik detect") | |
#with Assistant(credentials) as assistant: | |
# assistant.start() | |
detector.start(detected_callback=detect_callback, interrupt_check=interrupt_callback, sleep_time=0.03) | |
detector.terminate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment