fix: 唤醒机制

This commit is contained in:
Sakura-RanChen
2025-09-02 11:18:04 +08:00
parent b4f4995ff9
commit c428a9ddee
15 changed files with 848 additions and 145 deletions
+28
View File
@@ -2,6 +2,7 @@ import re
import os
import json
import copy
import wave
import socket
import requests
import subprocess
@@ -292,6 +293,33 @@ def play_audio_frames(conn, file_path):
callback=handle_audio_frame
)
def opus_datas_to_wav_bytes(opus_datas, sample_rate=16000, channels=1):
"""
将opus帧列表解码为wav字节流
"""
decoder = opuslib_next.Decoder(sample_rate, channels)
pcm_datas = []
frame_duration = 60 # ms
frame_size = int(sample_rate * frame_duration / 1000) # 960
for opus_frame in opus_datas:
# 解码为PCM(返回bytes,2字节/采样点)
pcm = decoder.decode(opus_frame, frame_size)
pcm_datas.append(pcm)
pcm_bytes = b"".join(pcm_datas)
# 写入wav字节流
wav_buffer = BytesIO()
with wave.open(wav_buffer, "wb") as wf:
wf.setnchannels(channels)
wf.setsampwidth(2) # 16bit
wf.setframerate(sample_rate)
wf.writeframes(pcm_bytes)
return wav_buffer.getvalue()
def check_vad_update(before_config, new_config):
if (
new_config.get("selected_module") is None