+ while True:
+ try:
+ async with AsyncExitStack() as web_stack:
+ ws = await web_stack.enter_async_context(websockets.connect(uri))
+ print('Type Ctrl-C to exit')
+ phrases = [] + config["commands"]
+ phrases.append(config["keyphrase"])
+ phrases = json.dumps(phrases, ensure_ascii=False)
+ await ws.send('{"config" : { "phrase_list" : '+phrases+', "sample_rate" : 16000.0}}')
+
+ ws = await web_stack.enter_async_context(_polite_websocket(ws))
+ while True:
+ phrase = await ListenPhrase(s, ws)
+ if config["debug"]:
+ print(phrase)
+ if phrase == keyphrase :
+ print("COMMAND!")
+ PlayBack(p, "Слушаю!", mic=s)
+ command = ""
+
+ for i in range(rec_attempts):
+ phrase = await ListenPhrase(s, ws)
+ if config["debug"]:
+ print(phrase)
+ if (not commands) or (phrase in commands):
+ if config["debug"]:
+ print("Command: ", phrase)
+ command = phrase
+ RunCommand(command, p, s)
+ break
+ else:
+ PlayBack(p, "Не знаю такой команды: "+phrase, mic=s)
+ else:
+ PlayBack(p, "Не поняла, слишком неразборчиво", mic=s)
+
+ if not command:
+ PlayBack(p, "Так команду и не поняла...", mic=s)
+ except KeyboardInterrupt:
+ raise
+ except Exception as e:
+ print('Exception: '+str(e))
+ pass