agent-zero/webui/js/speech.js
TerminallyLazy a100ee4143 Implement Kokoro TTS integration and settings updates
- Added Kokoro TTS support in preload and run_ui scripts.
- Introduced a new API endpoint for text-to-speech synthesis.
- Updated settings to include TTS enable/disable option.
- Refactored speech handling to utilize a centralized speech store.
- Enhanced UI with new speech button and SVG icon.
- Updated dependencies in requirements.txt for Kokoro TTS.
2025-06-28 22:48:37 -04:00

52 lines
No EOL
1.3 KiB
JavaScript

import { speechStore } from "./speech-store.js";
const microphoneButton = document.getElementById("microphone-button");
let isProcessingClick = false;
// Update microphone button UI based on store status
function updateMicrophoneButtonUI() {
const status = speechStore.micStatus;
microphoneButton.classList.remove('mic-inactive', 'mic-activating', 'mic-listening', 'mic-recording', 'mic-waiting', 'mic-processing');
microphoneButton.classList.add(`mic-${status.toLowerCase()}`);
microphoneButton.setAttribute("data-status", status);
}
// Watch store for status changes
document.addEventListener("alpine:init", () => {
Alpine.effect(() => {
updateMicrophoneButtonUI();
});
});
// Microphone button click handler
microphoneButton.addEventListener("click", async () => {
if (isProcessingClick) return;
isProcessingClick = true;
try {
await speechStore.toggleMicrophone();
} finally {
setTimeout(() => {
isProcessingClick = false;
}, 300);
}
});
// Create simplified Speech class for backward compatibility
class Speech {
async speak(text) {
return speechStore.speak(text);
}
stop() {
speechStore.stop();
}
isSpeaking() {
return speechStore.isSpeaking;
}
}
export const speech = new Speech();
window.speech = speech;