修正语音对话时 句子末尾显示异常的问题
This commit is contained in:
parent
97cb9a4adc
commit
63219baa21
@ -1,4 +1,4 @@
|
|||||||
import time, threading, json
|
import time, logging, json
|
||||||
|
|
||||||
|
|
||||||
class AliyunASR():
|
class AliyunASR():
|
||||||
@ -12,14 +12,14 @@ class AliyunASR():
|
|||||||
message = json.loads(message)
|
message = json.loads(message)
|
||||||
self.parsed_sentence = message['payload']['result']
|
self.parsed_sentence = message['payload']['result']
|
||||||
self.event_on_entence_end.set()
|
self.event_on_entence_end.set()
|
||||||
print(self.parsed_sentence)
|
# print(self.parsed_sentence)
|
||||||
|
|
||||||
def test_on_start(self, message, *args):
|
def test_on_start(self, message, *args):
|
||||||
# print("test_on_start:{}".format(message))
|
# print("test_on_start:{}".format(message))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_on_error(self, message, *args):
|
def test_on_error(self, message, *args):
|
||||||
print("on_error args=>{}".format(args))
|
logging.error("on_error args=>{}".format(args))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_on_close(self, *args):
|
def test_on_close(self, *args):
|
||||||
@ -36,7 +36,6 @@ class AliyunASR():
|
|||||||
# print("on_completed:args=>{} message=>{}".format(args, message))
|
# print("on_completed:args=>{} message=>{}".format(args, message))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def audio_convertion_thread(self, uuid):
|
def audio_convertion_thread(self, uuid):
|
||||||
# 在一个异步线程中采集音频
|
# 在一个异步线程中采集音频
|
||||||
import nls # pip install git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git
|
import nls # pip install git+https://github.com/aliyun/alibabacloud-nls-python-sdk.git
|
||||||
|
@ -80,9 +80,9 @@ class InterviewAssistant(AliyunASR):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.capture_interval = 0.5 # second
|
self.capture_interval = 0.5 # second
|
||||||
self.stop = False
|
self.stop = False
|
||||||
self.parsed_text = ""
|
self.parsed_text = "" # 下个句子中已经说完的部分, 由 test_on_result_chg() 写入
|
||||||
self.parsed_sentence = ""
|
self.parsed_sentence = "" # 某段话的整个句子,由 test_on_sentence_end() 写入
|
||||||
self.buffered_sentence = ""
|
self.buffered_sentence = "" #
|
||||||
self.event_on_result_chg = threading.Event()
|
self.event_on_result_chg = threading.Event()
|
||||||
self.event_on_entence_end = threading.Event()
|
self.event_on_entence_end = threading.Event()
|
||||||
self.event_on_commit_question = threading.Event()
|
self.event_on_commit_question = threading.Event()
|
||||||
@ -132,7 +132,7 @@ class InterviewAssistant(AliyunASR):
|
|||||||
self.plugin_wd.feed()
|
self.plugin_wd.feed()
|
||||||
|
|
||||||
if self.event_on_result_chg.is_set():
|
if self.event_on_result_chg.is_set():
|
||||||
# update audio decode result
|
# called when some words have finished
|
||||||
self.event_on_result_chg.clear()
|
self.event_on_result_chg.clear()
|
||||||
chatbot[-1] = list(chatbot[-1])
|
chatbot[-1] = list(chatbot[-1])
|
||||||
chatbot[-1][0] = self.buffered_sentence + self.parsed_text
|
chatbot[-1][0] = self.buffered_sentence + self.parsed_text
|
||||||
@ -144,7 +144,11 @@ class InterviewAssistant(AliyunASR):
|
|||||||
# called when a sentence has ended
|
# called when a sentence has ended
|
||||||
self.event_on_entence_end.clear()
|
self.event_on_entence_end.clear()
|
||||||
self.parsed_text = self.parsed_sentence
|
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():
|
if self.event_on_commit_question.is_set():
|
||||||
# called when a question should be commited
|
# called when a question should be commited
|
||||||
|
Loading…
x
Reference in New Issue
Block a user