From 63219baa217617b0702002f8dc128152f8e57d3d Mon Sep 17 00:00:00 2001 From: binary-husky Date: Thu, 7 Sep 2023 17:04:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=AF=AD=E9=9F=B3=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E6=97=B6=20=E5=8F=A5=E5=AD=90=E6=9C=AB=E5=B0=BE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crazy_functions/live_audio/aliyunASR.py | 7 +++---- crazy_functions/语音助手.py | 14 +++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/crazy_functions/live_audio/aliyunASR.py b/crazy_functions/live_audio/aliyunASR.py index 9641057..ed67fcd 100644 --- a/crazy_functions/live_audio/aliyunASR.py +++ b/crazy_functions/live_audio/aliyunASR.py @@ -1,4 +1,4 @@ -import time, threading, json +import time, logging, json class AliyunASR(): @@ -12,14 +12,14 @@ class AliyunASR(): message = json.loads(message) self.parsed_sentence = message['payload']['result'] self.event_on_entence_end.set() - print(self.parsed_sentence) + # print(self.parsed_sentence) def test_on_start(self, message, *args): # print("test_on_start:{}".format(message)) pass def test_on_error(self, message, *args): - print("on_error args=>{}".format(args)) + logging.error("on_error args=>{}".format(args)) pass def test_on_close(self, *args): @@ -36,7 +36,6 @@ class AliyunASR(): # print("on_completed:args=>{} message=>{}".format(args, message)) pass - def audio_convertion_thread(self, uuid): # 在一个异步线程中采集音频 import nls # pip install git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git diff --git a/crazy_functions/语音助手.py b/crazy_functions/语音助手.py index 6fe1afc..b1c8c41 100644 --- a/crazy_functions/语音助手.py +++ b/crazy_functions/语音助手.py @@ -80,9 +80,9 @@ class InterviewAssistant(AliyunASR): def __init__(self): self.capture_interval = 0.5 # second self.stop = False - self.parsed_text = "" - self.parsed_sentence = "" - self.buffered_sentence = "" + self.parsed_text = "" # 下个句子中已经说完的部分, 由 test_on_result_chg() 写入 + self.parsed_sentence = "" # 某段话的整个句子,由 test_on_sentence_end() 写入 + self.buffered_sentence = "" # self.event_on_result_chg = threading.Event() self.event_on_entence_end = threading.Event() self.event_on_commit_question = threading.Event() @@ -132,7 +132,7 @@ class InterviewAssistant(AliyunASR): self.plugin_wd.feed() if self.event_on_result_chg.is_set(): - # update audio decode result + # called when some words have finished self.event_on_result_chg.clear() chatbot[-1] = list(chatbot[-1]) chatbot[-1][0] = self.buffered_sentence + self.parsed_text @@ -144,7 +144,11 @@ class InterviewAssistant(AliyunASR): # called when a sentence has ended self.event_on_entence_end.clear() self.parsed_text = self.parsed_sentence - self.buffered_sentence += self.parsed_sentence + self.buffered_sentence += self.parsed_text + chatbot[-1] = list(chatbot[-1]) + chatbot[-1][0] = self.buffered_sentence + history = chatbot2history(chatbot) + yield from update_ui(chatbot=chatbot, history=history) # 刷新界面 if self.event_on_commit_question.is_set(): # called when a question should be commited