VoiceAgentAPIClient
Methods
addEventListener
addEventListener(event: | , callback: Function
): void
Adds a handler for the specified Grok.VoiceAgentAPIEvents or Grok.Events event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.
Parameters
event:
Event class (i.e., Grok.VoiceAgentAPIEvents.ConversationCreated)
callback:
Function
Handler function. A single parameter is passed - object with event information
Returns
type:
void
clearMediaBuffer
clearMediaBuffer(parameters: ): void
Clears the Grok WebSocket media buffer.
Parameters
parameters:
OptionalOptional. Media buffer clearing parameters
Returns
type:
void
close
close(): void
Closes the Grok connection (over WebSocket) or connection attempt.
Returns
type:
void
conversationItemCreate
conversationItemCreate(parameters: Object
): void
Create a new user message. https://docs.x.ai/docs/guides/voice/agent#client
Parameters
parameters:
Object
Returns
type:
void
id
id(): string
Returns the VoiceAgentAPIClient id.
Returns
type:
string
inputAudioBufferClear
inputAudioBufferClear(parameters: Object
): void
Clear input audio buffer. https://docs.x.ai/docs/guides/voice/agent#client-1
Parameters
parameters:
Object
Returns
type:
void
removeEventListener
removeEventListener(event: | , callback: Function
): void
Removes a handler for the specified Grok.VoiceAgentAPIEvents or Grok.Events event.
Parameters
event:
Event class (i.e., Grok.VoiceAgentAPIEvents.ConversationCreated)
callback:
Function
OptionalOptional. Handler function. If not specified, all handler functions are removed
Returns
type:
void
responseCreate
responseCreate(parameters: Object
): void
Request the server to create a new assistant response when using client side vad. (This is handled automatically when using server side vad.) https://docs.x.ai/docs/guides/voice/agent#client-2
Parameters
parameters:
Object
Returns
type:
void
sendMediaTo
sendMediaTo(mediaUnit: , parameters: ): void
Starts sending media from the Grok (via WebSocket) to the media unit. Grok works in real time.
Parameters
mediaUnit:
Media unit that receives media
parameters:
OptionalOptional interaction parameters
Returns
type:
void
sessionUpdate
sessionUpdate(parameters: Object
): void
Send this event to update the session’s configuration. https://docs.x.ai/docs/guides/voice/agent#client-events-1
Parameters
parameters:
Object
Returns
type:
void
stopMediaTo
stopMediaTo(mediaUnit: ): void
Stops sending media from the Grok (via WebSocket) to the media unit.
Parameters
mediaUnit:
Media unit that stops receiving media
Returns
type:
void
webSocketId
webSocketId(): string
Returns the Grok WebSocket id.
Returns
type:
string