From 8cce64b0051dd252cc118053edf3ef292116b68a Mon Sep 17 00:00:00 2001 From: Apcallover <1503963513@qq.com> Date: Mon, 22 Dec 2025 09:28:24 +0800 Subject: [PATCH] =?UTF-8?q?flat:=20=E8=AF=AD=E9=9F=B3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.js | 9 ++++----- hook/piper-bundle.js | 2 +- hook/useTTSPlayer-web.js | 22 +++++++++++++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/config.js b/config.js index 19932f8..4d64e59 100644 --- a/config.js +++ b/config.js @@ -4,12 +4,11 @@ export default { // baseUrl: 'http://192.168.3.29:8081', // baseUrl: 'http://10.213.6.207:19010/api', // 语音转文字 - // vioceBaseURl: 'wss://qd.zhaopinzao8dian.com/api/app/asr/connect', // 自定义 - vioceBaseURl: 'wss://fw.rc.qingdao.gov.cn/rgpp-api/api/app/asr/connect', // 内网 + // vioceBaseURl: 'wss://qd.zhaopinzao8dian.com/api/app/asr/connect', // 测试 + vioceBaseURl: 'wss://fw.rc.qingdao.gov.cn/rgpp-api/api/app/asr/connect', // 正式 // 语音合成 - // speechSynthesis: 'wss://qd.zhaopinzao8dian.com/api/speech-synthesis', - // speechSynthesis2: 'wss://resource.zhuoson.com/synthesis/', //直接替换即可 - speechSynthesis2: 'http://39.98.44.136:19527', //直接替换即可 + // speechSynthesis: 'wss://qd.zhaopinzao8dian.com/api/speech-synthesis', // 测试 + speechSynthesis: 'wss://fw.rc.qingdao.gov.cn/rgpp-api/api/app/tts/connect', // 正式 // indexedDB DBversion: 3, // 只使用本地缓寸的数据 diff --git a/hook/piper-bundle.js b/hook/piper-bundle.js index b9e58ef..892adcf 100644 --- a/hook/piper-bundle.js +++ b/hook/piper-bundle.js @@ -364,7 +364,7 @@ class PiperTTS { this.isRecording = true; this.onStart(); - const wsUrl = this.baseUrl.replace(/^http/, 'ws') + '/ws/synthesize'; + const wsUrl = this.baseUrl.replace(/^http/, 'ws'); this.worker.postMessage({ type: 'connect', data: { diff --git a/hook/useTTSPlayer-web.js b/hook/useTTSPlayer-web.js index 039857a..3fa0187 100644 --- a/hook/useTTSPlayer-web.js +++ b/hook/useTTSPlayer-web.js @@ -18,12 +18,28 @@ export function useTTSPlayer() { // 单例 Piper 实例 let piper = null + /** + * 获取 WebSocket 地址 (含 Token) + */ + const getWsUrl = async () => { + let wsUrl = config.speechSynthesis + + // 拼接 Token + const token = uni.getStorageSync('token') || ''; + if (token) { + const separator = wsUrl.includes('?') ? '&' : '?'; + wsUrl = `${wsUrl}${separator}token=${encodeURIComponent(token)}`; + } + return wsUrl; + } + /** * 获取或创建 SDK 实例 */ - const getPiperInstance = () => { + const getPiperInstance = async () => { if (!piper) { - let baseUrl = config.speechSynthesis2 || '' + + let baseUrl = await getWsUrl() baseUrl = baseUrl.replace(/\/$/, '') piper = new PiperTTS({ @@ -61,7 +77,7 @@ export function useTTSPlayer() { const processedText = extractSpeechText(text) if (!processedText) return - const instance = getPiperInstance() + const instance = await getPiperInstance() // 重置状态 isLoading.value = true