Lint warnings fixed

This commit is contained in:
Fabio Manganiello 2019-07-13 14:22:43 +02:00
parent 3c3496b19a
commit 8b2c6d333e
3 changed files with 28 additions and 22 deletions

View file

@ -60,15 +60,19 @@ class AssistantSnowboyBackend(Backend):
ok_google: # Hotword model name ok_google: # Hotword model name
voice_model_file: /path/models/OK Google.pmdl # Voice model file location voice_model_file: /path/models/OK Google.pmdl # Voice model file location
sensitivity: 0.5 # Model sensitivity, between 0 and 1 (default: 0.5) sensitivity: 0.5 # Model sensitivity, between 0 and 1 (default: 0.5)
assistant_plugin: assistant.google.pushtotalk # When the hotword is detected trigger the Google push-to-talk assistant plugin (optional) assistant_plugin: assistant.google.pushtotalk # When the hotword is detected trigger the Google
assistant_language: en-US # The assistant will conversate in English when this hotword is detected (optional) # push-to-talk assistant plugin (optional)
assistant_language: en-US # The assistant will conversate in English when this hotword is
detected (optional)
detect_sound: /path/to/bell.wav # Sound file to be played when the hotword is detected (optional) detect_sound: /path/to/bell.wav # Sound file to be played when the hotword is detected (optional)
ciao_google: # Hotword model name ciao_google: # Hotword model name
voice_model_file: /path/models/Ciao Google.pmdl # Voice model file location voice_model_file: /path/models/Ciao Google.pmdl # Voice model file location
sensitivity: 0.5 # Model sensitivity, between 0 and 1 (default: 0.5) sensitivity: 0.5 # Model sensitivity, between 0 and 1 (default: 0.5)
assistant_plugin: assistant.google.pushtotalk # When the hotword is detected trigger the Google push-to-talk assistant plugin (optional) assistant_plugin: assistant.google.pushtotalk # When the hotword is detected trigger the Google
assistant_language: it-IT # The assistant will conversate in Italian when this hotword is detected (optional) # push-to-talk assistant plugin (optional)
assistant_language: it-IT # The assistant will conversate in Italian when this hotword is
# detected (optional)
detect_sound: /path/to/bell.wav # Sound file to be played when the hotword is detected (optional) detect_sound: /path/to/bell.wav # Sound file to be played when the hotword is detected (optional)
:type models: dict :type models: dict
@ -93,7 +97,8 @@ class AssistantSnowboyBackend(Backend):
sensitivity=[model['sensitivity'] for model in self.models.values()], sensitivity=[model['sensitivity'] for model in self.models.values()],
audio_gain=self.audio_gain) audio_gain=self.audio_gain)
self.logger.info('Initialized Snowboy hotword detection with {} voice model configurations'.format(len(self.models))) self.logger.info('Initialized Snowboy hotword detection with {} voice model configurations'.
format(len(self.models)))
def _init_models(self, models): def _init_models(self, models):
if not models: if not models:
@ -117,7 +122,8 @@ class AssistantSnowboyBackend(Backend):
detect_sound = os.path.abspath(os.path.expanduser(detect_sound)) detect_sound = os.path.abspath(os.path.expanduser(detect_sound))
if not os.path.isfile(model_file): if not os.path.isfile(model_file):
raise FileNotFoundError('Voice model file {} does not exist or it not a regular file'.format(model_file)) raise FileNotFoundError('Voice model file {} does not exist or it not a regular file'.
format(model_file))
self.models[name] = { self.models[name] = {
'voice_model_file': model_file, 'voice_model_file': model_file,
@ -136,7 +142,6 @@ class AssistantSnowboyBackend(Backend):
except ImportError: except ImportError:
import snowboy.snowboydecoder as snowboydecoder import snowboy.snowboydecoder as snowboydecoder
def sound_thread(sound): def sound_thread(sound):
snowboydecoder.play_audio_file(sound) snowboydecoder.play_audio_file(sound)

View file

@ -3,13 +3,8 @@
""" """
import json import json
import logging
import os import os
import google.auth.transport.grpc
import google.auth.transport.requests
import google.oauth2.credentials
import googlesamples.assistant.grpc.audio_helpers as audio_helpers import googlesamples.assistant.grpc.audio_helpers as audio_helpers
import googlesamples.assistant.grpc.device_helpers as device_helpers import googlesamples.assistant.grpc.device_helpers as device_helpers
@ -22,6 +17,7 @@ from platypush.plugins import action
from platypush.plugins.assistant import AssistantPlugin from platypush.plugins.assistant import AssistantPlugin
from platypush.plugins.assistant.google.lib import SampleAssistant from platypush.plugins.assistant.google.lib import SampleAssistant
class AssistantGooglePushtotalkPlugin(AssistantPlugin): class AssistantGooglePushtotalkPlugin(AssistantPlugin):
""" """
Plugin for the Google Assistant push-to-talk API. Plugin for the Google Assistant push-to-talk API.
@ -89,10 +85,12 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin):
# Load OAuth 2.0 credentials. # Load OAuth 2.0 credentials.
try: try:
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
with open(self.credentials_file, 'r') as f: with open(self.credentials_file, 'r') as f:
self.credentials = google.oauth2.credentials.Credentials(token=None, self.credentials = Credentials(token=None, **json.load(f))
**json.load(f)) self.http_request = Request()
self.http_request = google.auth.transport.requests.Request()
self.credentials.refresh(self.http_request) self.credentials.refresh(self.http_request)
except Exception as ex: except Exception as ex:
self.logger.error('Error loading credentials: %s', str(ex)) self.logger.error('Error loading credentials: %s', str(ex))
@ -105,12 +103,11 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin):
self.device_handler = None self.device_handler = None
def _init_assistant(self): def _init_assistant(self):
from google.auth.transport.grpc import secure_authorized_channel
self.interactions = [] self.interactions = []
# Create an authorized gRPC channel. # Create an authorized gRPC channel.
self.grpc_channel = google.auth.transport.grpc.secure_authorized_channel( self.grpc_channel = secure_authorized_channel(self.credentials, self.http_request, self.api_endpoint)
self.credentials, self.http_request, self.api_endpoint)
self.logger.info('Connecting to {}'.format(self.api_endpoint)) self.logger.info('Connecting to {}'.format(self.api_endpoint))
# Configure audio source and sink. # Configure audio source and sink.
@ -143,14 +140,16 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin):
self.device_handler = device_helpers.DeviceRequestHandler(self.device_id) self.device_handler = device_helpers.DeviceRequestHandler(self.device_id)
def on_conversation_start(self): @staticmethod
def on_conversation_start():
""" Conversation start handler """ """ Conversation start handler """
def handler(): def handler():
get_bus().post(ConversationStartEvent()) get_bus().post(ConversationStartEvent())
return handler return handler
def on_conversation_end(self): @staticmethod
def on_conversation_end():
""" Conversation end handler """ """ Conversation end handler """
def handler(with_follow_on_turn): def handler(with_follow_on_turn):
get_bus().post(ConversationEndEvent(with_follow_on_turn=with_follow_on_turn)) get_bus().post(ConversationEndEvent(with_follow_on_turn=with_follow_on_turn))
@ -165,7 +164,8 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin):
return handler return handler
def on_volume_changed(self): @staticmethod
def on_volume_changed():
""" Volume changed event """ """ Volume changed event """
def handler(volume): def handler(volume):
get_bus().post(VolumeChangedEvent(volume=volume)) get_bus().post(VolumeChangedEvent(volume=volume))
@ -192,7 +192,7 @@ class AssistantGooglePushtotalkPlugin(AssistantPlugin):
return handler return handler
@action @action
def start_conversation(self, language=None): def start_conversation(self, *args, language=None, **kwargs):
""" """
Start a conversation Start a conversation

View file

@ -38,6 +38,7 @@ class Procedure(object):
if_count = 0 if_count = 0
if_config = LifoQueue() if_config = LifoQueue()
procedure_class = procedure_class or cls procedure_class = procedure_class or cls
key = None
for request_config in requests: for request_config in requests:
# Check if this request is a for loop # Check if this request is a for loop