feat(tts): integrate autonomous Piper neural TTS with zero-latency pre-warming for words and context
This commit is contained in:
1 parent
915d2784a2
commit
a6fb4349e9
12 files changed
+514
-27
No files matched your search
@@ -168,14 +168,34 @@ export function updateHeaderStats(total = 0, today = 0, srsCount = 0) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Audio Player Helper (Safe stub / audio stream)
|
||||
// Audio Player Helper (Safe stub / audio stream / Piper TTS)
|
||||
// -----------------------------------------------------------------------
|
||||
export function playAudio(url) {
|
||||
if (!url) return;
|
||||
let activeAudio = null;
|
||||
|
||||
export function playAudio(url, speed = 1.0) {
|
||||
if (!url) return null;
|
||||
try {
|
||||
if (activeAudio) {
|
||||
try {
|
||||
activeAudio.pause();
|
||||
activeAudio.currentTime = 0;
|
||||
} catch (e) {}
|
||||
}
|
||||
const audio = new Audio(url);
|
||||
if (speed && speed !== 1.0) {
|
||||
audio.playbackRate = speed;
|
||||
}
|
||||
activeAudio = audio;
|
||||
audio.play().catch(e => console.warn('Audio playback not supported or blocked:', e));
|
||||
return audio;
|
||||
} catch (e) {
|
||||
console.warn('Audio play error:', e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function playTextSpeech(text, lang = 'en', speed = 1.0) {
|
||||
if (!text || !text.trim()) return null;
|
||||
const url = `/api/tts?text=${encodeURIComponent(text.trim())}&lang=${lang}&speed=${speed}`;
|
||||
return playAudio(url, speed);
|
||||
}
|
||||
Reference in new issue
Block a user