forked from killua/TakwayPlatform
vad预处理
This commit is contained in:
parent
054514d654
commit
20363bf9a1
|
@ -69,6 +69,11 @@ def split_string_with_punctuation(current_sentence,text,is_first):
|
||||||
result.append(current_sentence)
|
result.append(current_sentence)
|
||||||
current_sentence = ''
|
current_sentence = ''
|
||||||
return result, current_sentence, is_first
|
return result, current_sentence, is_first
|
||||||
|
|
||||||
|
def vad_preprocess(audio):
|
||||||
|
if len(audio)<1280:
|
||||||
|
return ('A'*1280)
|
||||||
|
return audio[:1280],audio[1280:]
|
||||||
#--------------------------------------------------------
|
#--------------------------------------------------------
|
||||||
|
|
||||||
# 创建新聊天
|
# 创建新聊天
|
||||||
|
@ -461,16 +466,23 @@ async def streaming_chat_lasting_handler(ws,db,redis):
|
||||||
async def voice_call_audio_producer(ws,audio_queue,future,input_finished_event):
|
async def voice_call_audio_producer(ws,audio_queue,future,input_finished_event):
|
||||||
logger.debug("音频数据生产函数启动")
|
logger.debug("音频数据生产函数启动")
|
||||||
is_future_done = False
|
is_future_done = False
|
||||||
while not input_finished_event.is_set():
|
audio_data = ""
|
||||||
voice_call_data_json = json.loads(await ws.receive_text())
|
try:
|
||||||
if not is_future_done: #在第一次循环中读取session_id
|
while not input_finished_event.is_set():
|
||||||
future.set_result(voice_call_data_json['meta_info']['session_id'])
|
voice_call_data_json = json.loads(await ws.receive_text())
|
||||||
is_future_done = True
|
if not is_future_done: #在第一次循环中读取session_id
|
||||||
if voice_call_data_json["is_close"]:
|
future.set_result(voice_call_data_json['meta_info']['session_id'])
|
||||||
input_finished_event.set()
|
is_future_done = True
|
||||||
break
|
if voice_call_data_json["is_close"]:
|
||||||
else:
|
input_finished_event.set()
|
||||||
await audio_queue.put(voice_call_data_json["audio"]) #将音频数据存入audio_q
|
break
|
||||||
|
else:
|
||||||
|
audio_data += voice_call_data_json["audio"]
|
||||||
|
while len(audio_data) > 1280:
|
||||||
|
vad_frame,audio_data = vad_preprocess(audio_data)
|
||||||
|
await audio_queue.put(vad_frame) #将音频数据存入audio_q
|
||||||
|
except KeyError as ke:
|
||||||
|
logger.info(f"收到心跳包")
|
||||||
|
|
||||||
#音频数据消费函数
|
#音频数据消费函数
|
||||||
async def voice_call_audio_consumer(audio_q,asr_result_q,input_finished_event,asr_finished_event):
|
async def voice_call_audio_consumer(audio_q,asr_result_q,input_finished_event,asr_finished_event):
|
||||||
|
|
Loading…
Reference in New Issue