When initialized, returns a number of properties to check, update, and manage the state (with voice).

The main one is newRequest function that’s used instead of agent.run to run the agent… it takes the same arguments and provides better state management.

It also provides methods to manage the agent voice player, and user voice recorder.

Props

All properties retruned from useChatState, plus:

newRequest
Function

The newRequest in the voice state is not the same one used in the text chat state, here passing inputs is optional, as the inputs are extracted from the recorded user voice.

voicePlaying
boolean

Whether the agent voice is currently playing or not. This is set to true even of the player is paused, and it indicates that the latest agent run voice response has not finished playing yet.

recorderState
"stopped" | "recording" | "paused"
default: "stopped"

The user voice recorder state.

supportRecognition
boolean

Wether the browser supports in-browser speech recognition. as Scoopika will try to use in-browser recognition if available for better performance.

This will be set to true if speech recognition is supported, if not the feature will still work but Scoopika will send the voice to the cloud to be processed (done for you under the hood).

recognizedText
"string" | undefined

If in browser speech recognition is supported, this variable will hold the latest recognized text the user said to the recorder.

Useful to display the recognized text to the user.

updateRecognizedText
(text: string) => void

Used to update the recognized text. helpful to give the user the ability to update the recognized text manually.

Only available if in-browser speech recognition is supported.

working
boolean

In the useChatState you see loading, and generating. this one here is set to true as long as the agent is loading OR generating response OR the agent voice response is still playing and hasn’t finished yet.

agentVoicePaused
boolean

Set to true if the agent voice is currently paused.

pauseAgentVoice
() => void

Used to pause the agent voice player.

resumeAgentVoice
() => void

Used to resume the agent voice player after being paused.

agentVoicePlayer
RunAudioPlayer

The agent voice player. in normal use cases you won’t need to use this, but in case you need refer to the RunAudioPlayer documentation.

voiceRecorder
VoiceRecorder

The user voice recorder. in normal use cases, you won’t need to use this, but in case you need refer to the VoiceRecorder documentation.

visualizer
Visualizer

The agent voice visualizer that’s used to visualize the agent voice in the canvas if provided.