LifecycleCallbacks

Event Handling

Listen to lifecycle events to build reactive interfaces.

Event List

Hook into the JSVoice lifecycle by passing callbacks to the constructor.

CallbackTrigger
onSpeechStartMicrophone is active and listening
onSpeechEndMicrophone has stopped
onCommandRecognizedPhrase matched a known command
onWakeWordDetectedWake word valid, awaiting command
onErrorError occurred (permissions, no speech)

Example Implementation

javascript
1const voice = new JSVoice({
2  onSpeechStart: () => {
3    document.getElementById('indicator').classList.add('recording');
4  },
5  
6  onCommandRecognized: (phrase, raw) => {
7    console.log("Matched:", phrase);
8    showToast(`Executed: ${phrase}`);
9  },
10  
11  onError: (err) => {
12    console.error("Voice Error", err);
13  }
14});