mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 00:53:54 +08:00
update: 唤醒音频兼容
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
@@ -119,17 +120,31 @@ async def wakeupWordsResponse(conn):
|
|||||||
if result is None or result == "":
|
if result is None or result == "":
|
||||||
return
|
return
|
||||||
|
|
||||||
opus_datas = await asyncio.to_thread(conn.tts.to_tts, result)
|
tts_result = await asyncio.to_thread(conn.tts.to_tts, result)
|
||||||
if not opus_datas:
|
if conn.tts.delete_audio_file:
|
||||||
return
|
# 返回的是opus数据流
|
||||||
|
if not tts_result:
|
||||||
wav_bytes = opus_datas_to_wav_bytes(opus_datas, sample_rate=16000)
|
return
|
||||||
file_path = os.path.join(
|
wav_bytes = opus_datas_to_wav_bytes(tts_result, sample_rate=16000)
|
||||||
WAKEUP_CONFIG["dir"], "my_" + WAKEUP_CONFIG["file_name"] + ".wav"
|
file_path = os.path.join(
|
||||||
)
|
WAKEUP_CONFIG["dir"], "my_" + WAKEUP_CONFIG["file_name"] + ".wav"
|
||||||
# 写入wav数据
|
)
|
||||||
with open(file_path, "wb") as f:
|
with open(file_path, "wb") as f:
|
||||||
f.write(wav_bytes)
|
f.write(wav_bytes)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# 返回为文件
|
||||||
|
if tts_result is not None and os.path.exists(tts_result):
|
||||||
|
file_type = os.path.splitext(tts_result)[1]
|
||||||
|
if file_type:
|
||||||
|
file_type = file_type.lstrip(".")
|
||||||
|
old_file = getWakeupWordFile("my_" + WAKEUP_CONFIG["file_name"])
|
||||||
|
if old_file is not None:
|
||||||
|
os.remove(old_file)
|
||||||
|
"""将文件挪到wakeup_words目录下"""
|
||||||
|
shutil.move(
|
||||||
|
tts_result,
|
||||||
|
WAKEUP_CONFIG["dir"] + "my_" + WAKEUP_CONFIG["file_name"] + '.' + file_type,
|
||||||
|
)
|
||||||
WAKEUP_CONFIG["create_time"] = time.time()
|
WAKEUP_CONFIG["create_time"] = time.time()
|
||||||
WAKEUP_CONFIG["text"] = result
|
WAKEUP_CONFIG["text"] = result
|
||||||
|
|||||||
Reference in New Issue
Block a user