2025-12-26 17:26:32 +08:00
|
|
|
import { post, urlAddBaseUrl } from "./https";
|
|
|
|
|
|
2026-01-12 10:59:13 +08:00
|
|
|
const playVoice = (src: string, text: string) => {
|
2025-12-26 17:26:32 +08:00
|
|
|
const innerAudioContext = wx.createInnerAudioContext({
|
|
|
|
|
useWebAudioImplement: true,
|
|
|
|
|
});
|
|
|
|
|
innerAudioContext.src = src;
|
|
|
|
|
innerAudioContext.play();
|
|
|
|
|
innerAudioContext.onError(() => {
|
|
|
|
|
innerAudioContext.destroy();
|
|
|
|
|
console.log("Audio Error");
|
|
|
|
|
// wx.removeStorageSync(text);
|
|
|
|
|
});
|
|
|
|
|
innerAudioContext.onEnded(() => {
|
|
|
|
|
innerAudioContext.destroy();
|
|
|
|
|
console.log("Audio End");
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-12 10:59:13 +08:00
|
|
|
export const voiceRequest = (text: string, cacheVoice?: boolean) => {
|
2025-12-26 17:26:32 +08:00
|
|
|
post(
|
|
|
|
|
"/Tools/voice",
|
2026-01-14 16:54:47 +08:00
|
|
|
{ txt: text, per: 3, spd: 5, pit: 5, vol: 9 },
|
2025-12-26 17:26:32 +08:00
|
|
|
{ showLoading: false }
|
2026-01-12 10:59:13 +08:00
|
|
|
).then((res: any) => {
|
2025-12-26 17:26:32 +08:00
|
|
|
if (res.err_code == 0) {
|
|
|
|
|
playVoice(urlAddBaseUrl(res.data), text);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|