feat: 完成大部分功能开发
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
# websocket_service.py
|
||||
import uuid
|
||||
|
||||
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
||||
from typing import Set
|
||||
from aip import AipSpeech
|
||||
@@ -6,6 +8,7 @@ from app.constants.asr import APP_ID, API_KEY, SECRET_KEY
|
||||
import json
|
||||
|
||||
from . import tts
|
||||
from .voice_conversation import process_voice_conversation
|
||||
|
||||
router = APIRouter()
|
||||
active_connections: Set[WebSocket] = set()
|
||||
@@ -58,7 +61,12 @@ async def websocket_online_count(websocket: WebSocket):
|
||||
|
||||
elif msg_type == "asr_end":
|
||||
asr_text = await asr_buffer(temp_buffer)
|
||||
await websocket.send_json({"type": "asr_result", "result": asr_text})
|
||||
# 从data中获取messageId,如果不存在则生成一个新的ID
|
||||
message_id = data.get("messageId", "voice_" + str(uuid.uuid4()))
|
||||
if data.get("voiceConversation"):
|
||||
await process_voice_conversation(websocket, asr_text, message_id)
|
||||
else:
|
||||
await websocket.send_json({"type": "asr_result", "result": asr_text})
|
||||
temp_buffer = bytes()
|
||||
|
||||
# TTS处理
|
||||
|
||||
Reference in New Issue
Block a user