update: 语音优化

This commit is contained in:
2026-08-20 16:56:34 +08:00
parent bb224c9f29
commit 6363dda204
5 changed files with 128 additions and 25 deletions
+43 -1
View File
@@ -14,6 +14,10 @@ import {
getDistanceCheckAudioKey,
getInvalidShotAudioKey,
} from "@/util";
import {
getPrecisionShotAudioKeys,
getTrainingStartAudioKey,
} from "@/audioManager";
import {
normalizeId,
normalizeMatchInfo,
@@ -145,6 +149,15 @@ function buildBusinessMessage(message) {
matchInfo.status = 0;
}
const practiceInfo = normalizePracticeInfo(message.practice_info);
const trainingType = String(
practiceInfo.trainingType ||
matchInfo.trainingType ||
currentContext?.trainingType ||
""
).trim();
if (currentContext && trainingType) {
currentContext.trainingType = trainingType;
}
const businessType = getBusinessType(message, matchInfo);
if (!businessType) return null;
@@ -197,11 +210,15 @@ function buildBusinessMessage(message) {
matchWsType: message.type,
matchWsTypeName: getServerMessageTypeName(message.type),
isSecondHalfStart,
...(trainingType ? { trainingType } : {}),
};
}
function buildPracticeSyncMessage(message) {
const practiceInfo = normalizePracticeInfo(message.practice_info);
if (currentContext && practiceInfo.trainingType) {
currentContext.trainingType = String(practiceInfo.trainingType).trim();
}
const matchId = normalizeId(
pickField(message, "matchId", "match_id") ||
practiceInfo.id ||
@@ -368,7 +385,16 @@ function getTestDistanceAudioKeys(shootData) {
function getAckAudioKeys(message, businessMessage) {
switch (message.type) {
case ServerMessageType.SERVER_MSG_MATCH_START:
return [businessMessage?.isSecondHalfStart ? "下半场开始" : "比赛开始"];
if (businessMessage?.isSecondHalfStart) return ["下半场开始"];
// 个人训练在开始接口成功后主动播报,不再等待 MATCH_START 触发语音。
if (
getTrainingStartAudioKey(
businessMessage?.trainingType || currentContext?.trainingType
)
) {
return [];
}
return ["比赛开始"];
case ServerMessageType.SERVER_MSG_NOW_YOU:
if (isMeleeMessage(message, businessMessage)) return [];
return getNowYouAudioKeys(businessMessage);
@@ -379,6 +405,17 @@ function getAckAudioKeys(message, businessMessage) {
) {
return [];
}
if (
(businessMessage?.trainingType || currentContext?.trainingType) ===
"precision"
) {
const shootData = businessMessage?.shootData;
const directionText =
shootData?.angle !== null && shootData?.angle !== undefined
? getDirectionText(shootData.angle)
: "";
return getPrecisionShotAudioKeys(shootData, directionText);
}
return getShootResultAudioKeys(businessMessage?.shootData);
case ServerMessageType.SERVER_MSG_MATCH_END:
return ["比赛结束"];
@@ -865,6 +902,7 @@ export function connectMatchWebSocket(options = {}) {
requestPracticeInfoOnOpen = false,
appHideResumable = false,
practiceEndAudioKey = "",
trainingType = "",
force = false,
reconnecting = false,
reconnectReason = "",
@@ -872,6 +910,7 @@ export function connectMatchWebSocket(options = {}) {
const normalizedMatchId = normalizeId(matchId);
const normalizedUserId = normalizeId(userId);
const normalizedMode = Number(mode);
const normalizedTrainingType = String(trainingType || "").trim();
const incomingUrl = normalizeServerUrl(serverAddr, token);
const currentUrlToken = getUrlToken(currentContext?.url);
const shouldKeepAuthenticatedUrl = !!(
@@ -938,6 +977,9 @@ export function connectMatchWebSocket(options = {}) {
requestPracticeInfoOnOpen: requestPracticeInfoOnOpen === true,
appHideResumable: appHideResumable === true,
practiceEndAudioKey: String(practiceEndAudioKey || "").trim(),
trainingType:
normalizedTrainingType ||
(isSameContext ? currentContext?.trainingType || "" : ""),
meleeHalfRest: isSameContext
? currentContext?.meleeHalfRest === true
: false,