flat: 语音对接
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user