fix: WeChat login Content-Type header, ASR tiny model, re-upload mini-program v1.0.11

This commit is contained in:
yuzhiran
2026-06-15 10:00:02 +08:00
parent 4fa620f0a2
commit 18c50726cd
22 changed files with 311 additions and 128 deletions
+14 -6
View File
@@ -27,6 +27,8 @@
ref="dhRef"
:text="aiSpeechText"
:audio-url="aiAudioUrl"
:amplitude-data="aiAmplitudeData"
:position="position"
:auto-play="true"
@speaking-start="onAvatarSpeaking"
@speaking-end="onAvatarSilent"
@@ -53,7 +55,7 @@
</scroll-view>
<view class="input-bar" v-if="!isComplete">
<view class="mic-btn" :class="{ recording: isRecording }" @touchstart="startRecord" @touchend="stopRecord" @touchcancel="stopRecord">
<view class="mic-btn" :class="{ recording: isRecording }" @touchstart="startRecord" @touchend="stopRecord" @touchcancel="stopRecord" @mousedown="startRecord" @mouseup="stopRecord" @mouseleave="stopRecord">
<text class="mic-icon">🎤</text>
</view>
<view class="input-box">
@@ -89,6 +91,7 @@ const position = ref('')
const avatarMode = ref(true)
const aiSpeechText = ref('')
const aiAudioUrl = ref('')
const aiAmplitudeData = ref([])
const isSpeaking = ref(false)
const dhRef = ref(null)
const isRecording = ref(false)
@@ -179,8 +182,8 @@ const sendAnswer = async () => {
if (res.statusCode === 200 && res.data?.messages) {
const aiMsg = res.data.messages.find(m => m.role === 'ai')
messages.value.push(...res.data.messages)
if (avatarMode.value && aiMsg) {
await speakAiText(aiMsg.content, res.data.ttsHash)
if (avatarMode.value && aiMsg) {
await speakAiText(aiMsg.content, res.data.ttsHash, res.data.ttsAmplitude)
}
answeredCount.value = res.data.questionCount || answeredCount.value + 1
if (res.data.ttsHash && !avatarMode.value) {
@@ -195,8 +198,9 @@ const sendAnswer = async () => {
}
}
async function speakAiText(text, ttsHash) {
async function speakAiText(text, ttsHash, ttsAmplitude) {
aiSpeechText.value = text
aiAmplitudeData.value = ttsAmplitude || []
if (ttsHash) {
aiAudioUrl.value = api(API_ENDPOINTS.TTS.AUDIO(ttsHash))
} else {
@@ -208,6 +212,7 @@ async function speakAiText(text, ttsHash) {
})
if (synthRes.statusCode === 200 && synthRes.data?.hash) {
aiAudioUrl.value = api(API_ENDPOINTS.TTS.AUDIO(synthRes.data.hash))
aiAmplitudeData.value = synthRes.data?.amplitudeData || []
}
} catch {}
}
@@ -252,11 +257,12 @@ function stopRecord() {
const audioPath = res.tempFilePath
try {
const uploadRes = await uni.uploadFile({
url: api('/asr/recognize'),
url: api(API_ENDPOINTS.TTS.ASR),
filePath: audioPath,
name: 'audio',
header: { 'Authorization': `Bearer ${token.value}` },
})
console.log('[ASR] upload response:', uploadRes.statusCode, typeof uploadRes.data === 'string' ? uploadRes.data.slice(0, 200) : JSON.stringify(uploadRes.data).slice(0, 200))
if (uploadRes.statusCode === 200 && uploadRes.data) {
const data = typeof uploadRes.data === 'string' ? JSON.parse(uploadRes.data) : uploadRes.data
if (data.text) {
@@ -265,7 +271,9 @@ function stopRecord() {
return
}
}
} catch {}
} catch (e) {
console.error('[ASR] upload error:', e?.message || e)
}
uni.showToast({ title: '语音识别失败,请手动输入', icon: 'none' })
})
}