feat: 添加 TTS 引擎配置,更新阿里巴巴语音接口,支持实时语音合成

This commit is contained in:
EvanWu
2025-07-30 21:30:49 +08:00
parent 557a2cce35
commit 9990a89698
9 changed files with 241 additions and 45 deletions

View File

@@ -13,13 +13,17 @@ export function createTTSPlayer(): TTSPlayer {
audioContext.suspend();
};
const play = async (audioBuffer: ArrayBuffer, onended: () => void | null) => {
const play = async (audioBuffer: ArrayBuffer | AudioBuffer, onended: () => void | null) => {
if (audioBufferSourceNode) {
audioBufferSourceNode.stop();
audioBufferSourceNode.disconnect();
}
const buffer = await audioContext!.decodeAudioData(audioBuffer);
let buffer: AudioBuffer;
if (audioBuffer instanceof AudioBuffer) {
buffer = audioBuffer;
} else {
buffer = await audioContext!.decodeAudioData(audioBuffer);
}
audioBufferSourceNode = audioContext!.createBufferSource();
audioBufferSourceNode.buffer = buffer;
audioBufferSourceNode.connect(audioContext!.destination);
@@ -42,4 +46,4 @@ export function createTTSPlayer(): TTSPlayer {
};
return { init, play, stop };
}
}