From b07bcfaad2930872574b7c828b6f022749f8b05d Mon Sep 17 00:00:00 2001 From: admin <572701190@qq.com> Date: Mon, 20 Apr 2026 01:43:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=AF=E9=A3=9E=E9=89=B4=E6=9D=83?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E4=B8=8E=E5=AE=98=E6=96=B9demo=E5=AF=B9?= =?UTF-8?q?=E9=BD=90+=E7=BB=93=E6=9D=9F=E5=B8=A7+=E6=96=87=E5=AD=97?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ReportEditor: getXfAuthUrl signatureOrigin去掉引号,Base64改用CryptoJS.enc.Base64.stringify与demo完全一致 - ReportEditor: 第一帧增加dwa: wpgs动态修正参数 - ReportEditor: 停止录音时先发送status:2结束帧再关闭WebSocket - SystemSettings: 标题改为讯飞语音听写Websocket接口配置 --- src/pages/ReportEditor.tsx | 16 +++++++++++----- src/pages/SystemSettings.tsx | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pages/ReportEditor.tsx b/src/pages/ReportEditor.tsx index b5e22b3..e03e7a7 100644 --- a/src/pages/ReportEditor.tsx +++ b/src/pages/ReportEditor.tsx @@ -897,11 +897,11 @@ export default function ReportEditor() { async function getXfAuthUrl(apiKey: string, apiSecret: string): Promise { const host = 'iat-api.xfyun.cn'; const date = new Date().toUTCString(); - const signatureOrigin = `host: "${host}"\ndate: "${date}"\nGET /v2/iat HTTP/1.1`; - const signature = CryptoJS.HmacSHA256(signatureOrigin, apiSecret).toString(CryptoJS.enc.Base64); + const signatureOrigin = `host: ${host}\ndate: ${date}\nGET /v2/iat HTTP/1.1`; + const signature = CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(signatureOrigin, apiSecret)); const authorizationOrigin = `api_key="${apiKey}", algorithm="hmac-sha256", headers="host date request-line", signature="${signature}"`; - const authorization = btoa(authorizationOrigin); - return `wss://iat-api.xfyun.cn/v2/iat?authorization=${encodeURIComponent(authorization)}&date=${encodeURIComponent(date)}&host=${encodeURIComponent(host)}`; + const authorization = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(authorizationOrigin)); + return `wss://iat-api.xfyun.cn/v2/iat?authorization=${authorization}&date=${date}&host=${host}`; } function floatTo16BitPCM(input: Float32Array): ArrayBuffer { @@ -925,6 +925,12 @@ export default function ReportEditor() { const toggleListening = async () => { if (isListening) { setIsListening(false); + if (xfWsRef.current && xfWsRef.current.readyState === WebSocket.OPEN) { + try { + const endFrame = { data: { status: 2, format: 'audio/L16;rate=16000', encoding: 'raw', audio: '' } }; + xfWsRef.current.send(JSON.stringify(endFrame)); + } catch {} + } if (xfWsRef.current) { try { xfWsRef.current.close(); } catch {} xfWsRef.current = null; } if (xfAudioContextRef.current) { try { xfAudioContextRef.current.close(); } catch {} xfAudioContextRef.current = null; } if (xfMediaStreamRef.current) { xfMediaStreamRef.current.getTracks().forEach(t => t.stop()); xfMediaStreamRef.current = null; } @@ -955,7 +961,7 @@ export default function ReportEditor() { const pcmBuffer = floatTo16BitPCM(inputData); const base64Audio = arrayBufferToBase64(pcmBuffer); const frame: any = { data: { status: frameStatus, format: 'audio/L16;rate=16000', encoding: 'raw', audio: base64Audio } }; - if (frameStatus === 0) { frame.common = { app_id: xfConfig.appId }; frame.business = { language: 'zh_cn', domain: 'iat', accent: 'mandarin' }; } + if (frameStatus === 0) { frame.common = { app_id: xfConfig.appId }; frame.business = { language: 'zh_cn', domain: 'iat', accent: 'mandarin', dwa: 'wpgs' }; } ws.send(JSON.stringify(frame)); frameStatus = 1; }; diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index 38c2a6e..b510cde 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -429,7 +429,7 @@ export default function SystemSettings() {

- 讯飞语音配置 + 讯飞语音听写Websocket接口配置