+ 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, confidence = await ListenPhrase(s, ws)
+ if config["debug"]:
+ print(phrase,confidence)
+ if phrase == keyphrase and confidence>=confidence_treshold :
+ PlayBack(p, "Я жду команду", mic=s)
+ command = ""
+
+ for i in range(rec_attempts):
+ phrase, confidence = await ListenPhrase(s, ws)
+ if config["debug"]:
+ print(phrase,confidence)
+ if confidence > confidence_treshold:
+ 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:
+ pass