From e05ab2f662f2f8c3ac3bf74bd4f8da34aa91ec2c Mon Sep 17 00:00:00 2001 From: yongyao_li Date: Wed, 23 May 2018 13:05:00 +0800 Subject: [PATCH 1/2] support stop listen not only by directive --- avs/alexa.py | 2 ++ avs/interface/speech_recognizer.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/avs/alexa.py b/avs/alexa.py index b56daa0..7f0e84c 100755 --- a/avs/alexa.py +++ b/avs/alexa.py @@ -79,6 +79,8 @@ def __init__(self, config=None): # listen() will trigger SpeechRecognizer's Recognize event self.listen = self.SpeechRecognizer.Recognize + self.stop_listen = self.SpeechRecognizer.stop_listen + self.done = False self.requests = requests.Session() diff --git a/avs/interface/speech_recognizer.py b/avs/interface/speech_recognizer.py index 5c948bf..9b5c740 100644 --- a/avs/interface/speech_recognizer.py +++ b/avs/interface/speech_recognizer.py @@ -127,6 +127,8 @@ def gen(): self.alexa.send_event(event, listener=on_finished, attachment=gen()) + def stop_listen(self): + self.listening = False # { # "directive": { # "header": { @@ -140,7 +142,7 @@ def gen(): # } # } def StopCapture(self, directive): - self.listening = False + self.stop_listen() logger.info('StopCapture') # { From ab680a2fda43dee1452696b10c55c9af9000a8aa Mon Sep 17 00:00:00 2001 From: yongyao_li Date: Wed, 23 May 2018 13:05:48 +0800 Subject: [PATCH 2/2] support custom port and ignore self-signed cert verify --- avs/alexa.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/avs/alexa.py b/avs/alexa.py index 7f0e84c..d90fe48 100755 --- a/avs/alexa.py +++ b/avs/alexa.py @@ -22,6 +22,7 @@ import requests import datetime import hyper +import ssl from avs.mic import Audio @@ -98,6 +99,12 @@ def __init__(self, config=None): self._config['api'] = 'v20160207' self._config['refresh_url'] = 'https://api.amazon.com/auth/o2/token' + if 'port' not in self._config: + self._config['port'] = 443 + + if 'verify' not in self._config: + self._config['verify'] = True + self.last_activity = datetime.datetime.utcnow() self._ping_time = None @@ -136,8 +143,16 @@ def run(self): continue def _run(self): - conn = hyper.HTTP20Connection('{}:443'.format( - self._config['host_url']), force_proto='h2') + if not self._config['verify']: + ssl_context = hyper.tls.init_context() + ssl_context.check_hostname = False + ssl_context.verify_mode = ssl.CERT_NONE # do not verify cert + else: + ssl_context = None + conn = hyper.HTTP20Connection('{}:{}'.format(self._config['host_url'], self._config['port']), + secure=True, + force_proto='h2', + ssl_context=ssl_context) headers = {'authorization': 'Bearer {}'.format(self.token)} if 'dueros-device-id' in self._config: