/forum/index.php?action=view&id=246

Welcome InMyPi Forum / Guestbook




DLD Sun 27 Jan 2019 at 8:46:23
Hey Google Home Assistant With Raspberry Pi

-
Hey Google Home Assistant With Raspberry Pi
Hey Google Raspberry Pi 433mhz ACTION impuls or Flamingo Cheap wall sockets hotword.py
Speak to microphone => Google returns your spoken in text => if text == "match" do WhatYouWant...




audio whas a pain in the .... to get microphone going, pulseaudio whas in the way i think
usr/share/alsa/pulse-alsa.conf whas my mic start problem i think
launchable file starthotword  located at /home/pi/     

launch "hey google" with ./starthotword

source env/bin/activate
cd assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/library
python3 hotword.py --device_model_id      >>>>>>>>>>>>>>>>>mydevicecodenamehere<<<<<<<<<<<<<<<<<<<<





Should be something like stopconversation to stop Google Whining about i do not how to do that yet
hotword.py

#!/usr/bin/env python
#(env) pi@raspberrypi:~/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/library $ python hotword.py --device_model_id raspberrypi-d2c38-rpi-lpf01r


# Copyright (C) 2017 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 RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(3,GPIO.OUT)
GPIO.setup(2,GPIO.OUT)

import argparse
import json
import os.path
import pathlib2 as pathlib
import sys
import subprocess




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
from google.assistant.library.device_helpers import register_device

try:
    FileNotFoundError
except NameError:
    FileNotFoundError = IOError


WARNING_NOT_REGISTERED = """
    This device is not registered. This means you will not be able to use
    Device Actions or see your device in Assistant Settings. In order to
    register this device follow instructions at:

    https://developers.google.com/assistant/sdk/guides/library/python/embed/register-device
"""

def radio():
    #aiy.audio.say('Good bye!')
    print('reboot hiero')
    #subprocess.call(['lxterminal', '-e', '/home/pi/q'])
    proc = subprocess.Popen(["mplayer", "http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3", "-ss", "30"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

def stopradio():
    #aiy.audio.say('Good bye!')
    print('reboot hiero')
    #player.stdin.write("q")
    proc.kill()
  
def heegoogle():
    #aiy.audio.say('Good bye!')
    print('reboot hiero')
    #subprocess.call(['lxterminal', '--command=','"espeak Hey_Google!"'])    
    os.system('espeak "Hey_Google!  What is the time"')
    
def clearscreen():
    #aiy.audio.say('Good bye!')
    print('clear screen hiero')
    os.system('clear')


    
    
    

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('1')
        #GPIO.output(3,GPIO.HIGH)
        os.system('aplay /home/pi/googlestart.wav')

    if (event.type == EventType.ON_RESPONDING_STARTED and event.args and not event.args['is_error_response']):
       print('2')
       #GPIO.output(3,GPIO.LOW)
       #GPIO.output(2,GPIO.HIGH)
 


    if event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED and event.args:
        print('You said:', event.args['text'])
        text = event.args['text'].lower()
     
     
        if text == 'radio':
            #Assistant.stop_conversation()
            radio()
        if text == 'stop radio':
            #Assistant.stop_conversation()
            stopradio()  
    
        if text == 'hey google':
            #assistant.stop_conversation()
            heegoogle()   
        if text == 'clear screen':
            #assistant.stop_conversation()
            clearscreen()                 
        
        
        
        if text == 'light on':
            #aiy.audio.say('Good bye!')
            print('licht aan')
            os.system("/home/pi/raspKaku/impuls.sh 31 B on 5")  
        if text == 'light off':
            #aiy.audio.say('Good bye!')
            print('licht uit')
            os.system("/home/pi/raspKaku/impuls.sh 31 B off 5")
        if text == 'lights on':
            #aiy.audio.say('Good bye!')
            print('licht aan')
            os.system("/home/pi/raspKaku/impuls.sh 31 B on 5")  
        if text == 'lights off':
            #aiy.audio.say('Good bye!')
            print('licht uit')
            os.system("/home/pi/raspKaku/impuls.sh 31 B off 5")         
            
        
        if text == 'main light on':
            #aiy.audio.say('Good bye!')
            print('main licht on')
            os.system("/home/pi/raspKaku/impuls.sh 31 E on 5") 
            os.system("aplay -d 5 -D plughw:0,0 /home/pi/trump.wav") 
        if text == 'main light off':
            #aiy.audio.say('Good bye!')
            print('main licht off')
            os.system("/home/pi/raspKaku/impuls.sh 31 E off 5") 
            os.system("aplay -d 5 -D plughw:0,0 /home/pi/trump.wav") 
            
    
  
  
  
        if text == 'kitchen light on':
            #aiy.audio.say('Good bye!')
            print('ok i turn kitchen light on')
            os.system("/home/pi/raspKaku/flamingo.sh 10 10 on 5")
        if text == 'kitchen light off':
            #aiy.audio.say('Good bye!')
            print('ok i turn kitchen light off')
            os.system("/home/pi/raspKaku/flamingo.sh 10 10 off 5")
  
        if text == 'tv on':
            #aiy.audio.say('Good bye!')
            print('ok i turn tv on')
            os.system("/home/pi/raspKaku/flamingo.sh 11 11 on 5")
        if text == 'tv off':
            #aiy.audio.say('Good bye!')
            print('ok i turn tv off')
            os.system("/home/pi/raspKaku/flamingo.sh 11 11 off 5")
            
            
        if text == 'computer on':
            #aiy.audio.say('Good bye!')
            print('ok i turn computer on')
            os.system("/home/pi/raspKaku/flamingo.sh A 1 on 5")
        if text == 'computer off':
            #aiy.audio.say('Good bye!')
            print('ok i turn computer off')
            os.system("/home/pi/raspKaku/flamingo.sh A 1 off 5")
            
            
            
            
        
    if event.type == EventType.ON_RESPONDING_FINISHED:
       #GPIO.output(2,GPIO.HIGH)
       #GPIO.output(3,GPIO.LOW)
       print('Finished ',event)

    if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and
            event.args and not event.args['with_follow_on_turn']):
        #GPIO.output(2,GPIO.LOW)   
        os.system('aplay /home/pi/googleend.wav')   
        print('Finished waiting for new command',event)
    if event.type == EventType.ON_DEVICE_ACTION:
        for command, params in event.actions:
            print('praat met me Do command', command, 'with params', str(params))


def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument('--device-model-id', '--device_model_id', type=str,
                        metavar='DEVICE_MODEL_ID', required=False,
                        help='the device model ID registered with Google')
    parser.add_argument('--project-id', '--project_id', type=str,
                        metavar='PROJECT_ID', required=False,
                        help='the project ID used to register this device')
    parser.add_argument('--device-config', type=str,
                        metavar='DEVICE_CONFIG_FILE',
                        default=os.path.join(
                            os.path.expanduser('~/.config'),
                            'googlesamples-assistant',
                            'device_config_library.json'
                        ),
                        help='path to store and read device configuration')
    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')
    parser.add_argument('-v', '--version', action='version',
                        version='%(prog)s ' + Assistant.__version_str__())

    args = parser.parse_args()
    with open(args.credentials, 'r') as f:
        credentials = google.oauth2.credentials.Credentials(token=None,
                                                            **json.load(f))

    device_model_id = None
    last_device_id = None
    try:
        with open(args.device_config) as f:
            device_config = json.load(f)
            device_model_id = device_config['model_id']
            last_device_id = device_config.get('last_device_id', None)
    except FileNotFoundError:
        pass

    if not args.device_model_id and not device_model_id:
        raise Exception('Missing --device-model-id option')

    # Re-register if "device_model_id" is given by the user and it differs
    # from what we previously registered with.
    should_register = (
        args.device_model_id and args.device_model_id != device_model_id)

    device_model_id = args.device_model_id or device_model_id

    with Assistant(credentials, device_model_id) as assistant:
        events = assistant.start()

        device_id = assistant.device_id
        print('device_model_id:', device_model_id)
        print('device_id:', device_id + '\n')

        # Re-register if "device_id" is different from the last "device_id":
        if should_register or (device_id != last_device_id):
            if args.project_id:
                register_device(args.project_id, credentials,
                                device_model_id, device_id)
                pathlib.Path(os.path.dirname(args.device_config)).mkdir(
                    exist_ok=True)
                with open(args.device_config, 'w') as f:
                    json.dump({
                        'last_device_id': device_id,
                        'model_id': device_model_id,
                    }, f)
            else:
                print(WARNING_NOT_REGISTERED)

        for event in events:
            process_event(event)


if __name__ == '__main__':
    main()



End of Message, Thanks For Viewing! ☺
Tip: if your watching on your phone or tablet ⁝ add / save to homescreen and you get a nice icon its Free!
Tip: on your computer or laptop do not forget to bookmark this page its Free!
BookMark ShortCut Keys press ctrl+d on your keyboard




-

-

Reply to this Message


Name
Subject
Message

, <code> <b> <i> <u> .

   


Design a Bit like ForumOne 4.0 WayBack 1999 ©
Always Read the Small print?!



http://forum.luberth.com - - http://www.luberth.com/forum/




Page Optimized for Netscape Navigator 2.0 or Newer Real Gecko ;-)




Domoticz/#/Floorplans Co2 FootPrint of this RaspBerry Pi 3B+ DeskTop PC & WebServer



----------

I am contacting my Lawyer
is the adult version of
I am telling my Mommy