Rate this page:

VoiceAgentAPIClient

Methods

addEventListener

Copy URL
addEventListener(event: 

Events

|

VoiceAgentAPIEvents

,
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

Returns

  • type:

    void

clearMediaBuffer

Copy URL
clearMediaBuffer(parameters: 

ClearMediaBufferParameters

):

void

Clears the Grok WebSocket media buffer.

Parameters

Returns

  • type:

    void

close

Copy URL
close(): 

void

Closes the Grok connection (over WebSocket) or connection attempt.

Returns

  • type:

    void

conversationItemCreate

Copy URL
conversationItemCreate(parameters: 

Object

):

void

Parameters

  • parameters:

    Object

Returns

  • type:

    void

id

Copy URL
id(): 

string

Returns the VoiceAgentAPIClient id.

Returns

  • type:

    string

inputAudioBufferClear

Copy URL
inputAudioBufferClear(parameters: 

Object

):

void

Parameters

  • parameters:

    Object

Returns

  • type:

    void

removeEventListener

Copy URL
removeEventListener(event: 

Events

|

VoiceAgentAPIEvents

,
callback:

Function

):

void

Removes a handler for the specified Grok.VoiceAgentAPIEvents or Grok.Events event.

Parameters

Returns

  • type:

    void

responseCreate

Copy URL
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

Copy URL
sendMediaTo(mediaUnit: 

VoxMediaUnit

,
parameters:

SendMediaParameters

):

void

Starts sending media from the Grok (via WebSocket) to the media unit. Grok works in real time.

Parameters

Returns

  • type:

    void

sessionUpdate

Copy URL
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

Copy URL
stopMediaTo(mediaUnit: 

VoxMediaUnit

):

void

Stops sending media from the Grok (via WebSocket) to the media unit.

Parameters

Returns

  • type:

    void

webSocketId

Copy URL
webSocketId(): 

string

Returns the Grok WebSocket id.

Returns

  • type:

    string