update:语音优化

This commit is contained in:
2026-08-19 14:04:12 +08:00
parent 75cfcd66ee
commit bb224c9f29
13 changed files with 153 additions and 86 deletions
+11 -9
View File
@@ -22,7 +22,12 @@ import {
} from "@/apis";
import { connectMatchWebSocket, closeMatchWebSocket } from "@/matchWebsocket";
import { sharePractiseData } from "@/canvas";
import { wxShare, debounce } from "@/util";
import {
wxShare,
debounce,
getDistanceCheckAudioKey,
getShootValidation,
} from "@/util";
import { MESSAGETYPESV2 } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -154,14 +159,11 @@ async function onReceiveMessage(msg) {
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
setTimeout(() => onOver(msg), 1500);
} else if (msg.type === MESSAGETYPESV2.TestDistance && step.value === 3) {
const rawDistance = Number(msg.shootData?.distance);
if (rawDistance === 0) {
audioManager.play("未发现靶纸,请瞄准靶纸射箭");
} else if (rawDistance / 100 >= 5) {
audioManager.play("距离合格");
btnDisabled.value = false;
showGuide.value = true;
} else audioManager.play("距离不足");
const result = getShootValidation(msg.shootData);
const isQualified = result.distanceOk && result.targetOk;
audioManager.play(getDistanceCheckAudioKey(msg.shootData));
btnDisabled.value = !isQualified;
showGuide.value = isQualified;
}
// messages.forEach((msg) => {
// if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
@@ -6,6 +6,7 @@ import Avatar from "./Avatar.vue";
import audioManager from "@/audioManager";
import { simulShootAPI } from "@/apis";
import { MESSAGETYPESV2 } from "@/constants";
import { getDistanceCheckAudioKey, getDistanceCheckText } from "@/util";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
@@ -26,6 +27,7 @@ const props = defineProps({
});
const arrow = ref({});
const distance = ref(0);
const statusText = ref("");
const showsimul = ref(false);
const count = ref(props.count);
const timer = ref(null);
@@ -34,7 +36,7 @@ const updateTimer = (value) => {
count.value = Math.round(value);
};
onMounted(() => {
audioManager.play("请射箭测试距离");
audioManager.play("请射箭测试站距与靶纸");
if (props.isBattle) {
timer.value = setInterval(() => {
count.value -= 1;
@@ -51,14 +53,12 @@ onBeforeUnmount(() => {
async function onReceiveMessage(msg) {
if (Array.isArray(msg)) return;
if (msg.type === MESSAGETYPESV2.TestDistance) {
const rawDistance = Number(msg.shootData?.distance);
const rawDistance = Number(msg.shootData?.distance ?? msg.shootData?.dst);
distance.value = Number.isFinite(rawDistance)
? Number((rawDistance / 100).toFixed(2))
: 0;
if (rawDistance === 0) {
audioManager.play("未发现靶纸,请瞄准靶纸射箭");
} else if (distance.value >= 5) audioManager.play("距离合格");
else audioManager.play("距离不足");
statusText.value = getDistanceCheckText(msg.shootData);
audioManager.play(getDistanceCheckAudioKey(msg.shootData));
}
}
@@ -101,13 +101,12 @@ onBeforeUnmount(() => {
模拟射箭
</button>
<view class="warnning-text">
<block v-if="distance > 0">
<text>当前距离{{ distance }}</text>
<text v-if="distance >= 5">已达到距离要求</text>
<text v-else>请调整站位</text>
<block v-if="statusText">
<text v-if="distance > 0">当前距离{{ distance }}</text>
<text>{{ statusText }}</text>
</block>
<block v-else>
<text>请射箭测试站距</text>
<text>请射箭测试站距与靶纸</text>
</block>
</view>
<view class="user-row">
+6 -2
View File
@@ -20,7 +20,11 @@ import {
MATCH_WS_STATE_EVENT,
} from "@/matchWebsocket";
import { MESSAGETYPESV2 } from "@/constants";
import { getDirectionText, getInvalidShotAudioKey } from "@/util";
import {
getDirectionText,
getInvalidShotAudioKey,
getInvalidShotText,
} from "@/util";
import { takeMatchReturnSnapshot } from "@/utils/matchReturn";
import audioManager, {
AUDIO_INTERRUPTION_BEGIN_EVENT,
@@ -1133,7 +1137,7 @@ async function runBattleEndTask(task, runId) {
async function runInvalidShotTask(task, runId) {
if (!isQueueAlive(runId)) return;
uni.showToast({
title: "距离不足,无效",
title: getInvalidShotText(task.message?.shootData),
icon: "none",
});
await playAudioKeys(getInvalidShotAudioKey(task.message?.shootData), {
@@ -2,7 +2,11 @@
import { ref, watch, onMounted, onBeforeUnmount, computed } from "vue";
import audioManager from "@/audioManager";
import { MESSAGETYPESV2 } from "@/constants";
import { getDirectionText, getInvalidShotAudioKey } from "@/util";
import {
getDirectionText,
getInvalidShotAudioKey,
getInvalidShotText,
} from "@/util";
import Avatar from "@/components/Avatar.vue";
import useStore from "@/store";
@@ -238,7 +242,7 @@ async function onReceiveMessage(msg) {
audioManager.play("中场休息");
} else if (msg.type === MESSAGETYPESV2.InvalidShot) {
uni.showToast({
title: "距离不足,无效",
title: getInvalidShotText(msg.shootData),
icon: "none",
});
audioManager.play(getInvalidShotAudioKey(msg.shootData));
+10 -11
View File
@@ -6,6 +6,7 @@ import Avatar from "@/components/Avatar.vue";
import audioManager from "@/audioManager";
import { simulShootAPI } from "@/apis";
import { MESSAGETYPESV2 } from "@/constants";
import { getDistanceCheckAudioKey, getDistanceCheckText } from "@/util";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
@@ -30,6 +31,7 @@ const props = defineProps({
});
const arrow = ref({});
const distance = ref(0);
const statusText = ref("");
const showsimul = ref(false);
const count = ref(props.count);
const timer = ref(null);
@@ -38,7 +40,7 @@ const updateTimer = (value) => {
count.value = Math.round(value);
};
onMounted(() => {
audioManager.play("请射箭测试距离");
audioManager.play("请射箭测试站距与靶纸");
if (props.isBattle) {
timer.value = setInterval(() => {
count.value -= 1;
@@ -55,14 +57,12 @@ onBeforeUnmount(() => {
async function onReceiveMessage(msg) {
if (Array.isArray(msg)) return;
if (msg.type === MESSAGETYPESV2.TestDistance) {
const rawDistance = Number(msg.shootData?.distance);
const rawDistance = Number(msg.shootData?.distance ?? msg.shootData?.dst);
distance.value = Number.isFinite(rawDistance)
? Number((rawDistance / 100).toFixed(2))
: 0;
if (rawDistance === 0) {
audioManager.play("未发现靶纸,请瞄准靶纸射箭");
} else if (distance.value >= 5) audioManager.play("距离合格");
else audioManager.play("距离不足");
statusText.value = getDistanceCheckText(msg.shootData);
audioManager.play(getDistanceCheckAudioKey(msg.shootData));
}
}
@@ -100,13 +100,12 @@ onBeforeUnmount(() => {
</button>
<view class="warnning-text">
<view class="target-tip">当前靶纸为<text class="text-yellow">{{ targetType }}cm</text>全环靶</view>
<block v-if="distance > 0">
<text>当前距离<text class="text-yellow">{{ distance }}</text></text>
<text v-if="distance >= 5">已达到距离要求</text>
<text v-else>请调整站位</text>
<block v-if="statusText">
<text v-if="distance > 0">当前距离<text class="text-yellow">{{ distance }}</text></text>
<text>{{ statusText }}</text>
</block>
<block v-else>
<text>请射箭测试站距</text>
<text>请射箭测试站距与靶纸</text>
</block>
</view>
<view class="user-row">