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)
|
||||
current_sentence = ''
|
||||
return result, current_sentence, is_first
|
||||
|
||||
def vad_preprocess(audio):
|
||||
if len(audio)<1280:
|
||||
return ('A'*1280)
|
||||
return audio[:1280],audio[1280:]
|
||||
#--------------------------------------------------------
|
||||
|
||||
# 创建新聊天
|
||||
|
@ -461,6 +466,8 @@ async def streaming_chat_lasting_handler(ws,db,redis):
|
|||
async def voice_call_audio_producer(ws,audio_queue,future,input_finished_event):
|
||||
logger.debug("音频数据生产函数启动")
|
||||
is_future_done = False
|
||||
audio_data = ""
|
||||
try:
|
||||
while not input_finished_event.is_set():
|
||||
voice_call_data_json = json.loads(await ws.receive_text())
|
||||
if not is_future_done: #在第一次循环中读取session_id
|
||||
|
@ -470,7 +477,12 @@ async def voice_call_audio_producer(ws,audio_queue,future,input_finished_event):
|
|||
input_finished_event.set()
|
||||
break
|
||||
else:
|
||||
await audio_queue.put(voice_call_data_json["audio"]) #将音频数据存入audio_q
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue