feat: 部分语音聊天功能

This commit is contained in:
2025-06-30 10:49:24 +08:00
parent 06e6b4a8c9
commit ac5e68f5a5
10 changed files with 594 additions and 25 deletions

View File

@@ -9,7 +9,7 @@ from typing import Dict, Any, Optional as OptionalType
from app.constants.tts import APP_ID, TOKEN, SPEAKER
# 协议常量保持不变...
# 协议常量
PROTOCOL_VERSION = 0b0001
DEFAULT_HEADER_SIZE = 0b0001
FULL_CLIENT_REQUEST = 0b0001
@@ -35,7 +35,7 @@ EVENT_TTSSentenceEnd = 351
EVENT_TTSResponse = 352
# 所有类定义保持不变...
# 所有类定义
class Header:
def __init__(self,
protocol_version=PROTOCOL_VERSION,
@@ -93,7 +93,7 @@ class Response:
self.payload_json = None
# 工具函数保持不变...
# 工具函数
def gen_log_id():
"""生成logID"""
ts = int(time.time() * 1000)
@@ -191,7 +191,7 @@ async def send_event(ws, header, optional=None, payload=None):
await ws.send(full_client_request)
# 修改:TTS状态管理类添加消息ID和任务追踪
# TTS状态管理类添加消息ID和任务追踪
class TTSState:
def __init__(self, message_id: str):
self.message_id = message_id

View File

@@ -5,7 +5,6 @@ from aip import AipSpeech
from app.constants.asr import APP_ID, API_KEY, SECRET_KEY
import json
# 导入修改后的TTS模块
from . import tts
router = APIRouter()
@@ -62,7 +61,7 @@ async def websocket_online_count(websocket: WebSocket):
await websocket.send_json({"type": "asr_result", "result": asr_text})
temp_buffer = bytes()
# 修改:TTS处理支持消息ID
# TTS处理
elif msg_type == "tts_text":
message_id = data.get("messageId")
text = data.get("text", "")