Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions avs/alexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import requests
import datetime
import hyper
import ssl

from avs.mic import Audio

Expand Down Expand Up @@ -79,6 +80,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()
Expand All @@ -96,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

Expand Down Expand Up @@ -134,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:
Expand Down
4 changes: 3 additions & 1 deletion avs/interface/speech_recognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -140,7 +142,7 @@ def gen():
# }
# }
def StopCapture(self, directive):
self.listening = False
self.stop_listen()
logger.info('StopCapture')

# {
Expand Down