RealtimeTTSPlayer
XAI provides a real-time Grok TTS player that streams generated audio to calls, WebSockets, and other VoxEngine media units.
Use XAI.createRealtimeTTSPlayer(...) to create a RealtimeTTSPlayer. Send text.delta, text.done, and text.clear messages to stream utterances and handle barge-in without reconnecting.
VoxEngine uses PCM audio at 16000 Hz. Keep the adapter audio format when configuring the xAI connection.
Related guides
Contents
- RealtimeTTSPlayerParameters: API key, xAI connection options, and WebSocket controls.
- RealtimeTTSPlayer: runtime player object returned by the factory.
- Methods: send streaming text and clear the provider buffer.
- Inherited Methods: playback and media methods inherited from the shared player base.
- PlayerEvents: player event names, payloads, and playback timing.
RealtimeTTSPlayer
Methods
clearBuffer
Clears a XAI.RealtimeTTSPlayer buffer.
Parameters
This method does not accept parameters.
Returns
send
Send message object to the xAI provider context.
Parameters
Returns
Example parameters messages:
text.delta
text.done
text.clear
Inherited Methods
XAI.RealtimeTTSPlayer extends the shared player base (BasePlayer in the typings). Those base methods use the same playback contract documented on the public Player page, and they emit PlayerEvents.
addEventListener
Inherited from the shared player base. See Player.addEventListener.
Adds a handler for the specified PlayerEvents event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.
Parameters
Returns
id
Inherited from the shared player base. See Player.id.
Returns the player’s id.
Parameters
This method does not accept parameters.
Returns
pause
Inherited from the shared player base. See Player.pause.
Pauses playback. To continue the playback use the Player.resume method.
Parameters
This method does not accept parameters.
Returns
removeEventListener
Inherited from the shared player base. See Player.removeEventListener.
Removes a handler for the specified PlayerEvents event.
Parameters
Returns
resume
Inherited from the shared player base. See Player.resume.
Resumes playback after the Player.pause method is called.
Parameters
This method does not accept parameters.
Returns
sendMediaTo
Inherited from the shared player base. See Player.sendMediaTo.
Starts sending media from the player to the media unit.
Parameters
Returns
stop
Inherited from the shared player base. See Player.stop.
Stops playback. The current player’s instance is destroyed.
Parameters
This method does not accept parameters.
Returns
stopMediaTo
Inherited from the shared player base. See Player.stopMediaTo.
Stops sending media from the player to the media unit.
Parameters
Returns
PlayerEvents
These are inherited PlayerEvents. Event callbacks receive the shared player event object; player is the XAI.RealtimeTTSPlayer instance that emitted the event. Some events include additional playback fields noted below.
Created
PlaybackReady
Triggers by the createURLPlayer and createTTSPlayer methods when
- the audio file download to the Voximplant cache is finished;
- the audio file is found in the cache (i.e., it is in the cache before).
Event constant: PlayerEvents.PlaybackReady
Payload
Started
Triggered when playback is started. Note that if the createURLPlayer method is called with the onPause parameter set to true, the event is not triggered; it is triggered after the Player.resume method call.
Event constant: PlayerEvents.Started
Payload
Stopped
Triggers as a result of the Player.stop method call.
Event constant: PlayerEvents.Stopped
Payload
PlaybackFinished
Triggered when playback has finished successfully or with an error.
Event constant: PlayerEvents.PlaybackFinished
Payload
Error
Triggered when playback has finished with an error.
Event constant: PlayerEvents.Error
Payload
PlaybackMarkerReached
Triggered when Player.addMarker is reached.
Event constant: PlayerEvents.PlaybackMarkerReached
Payload
PlaybackBuffering
Triggered when an audio file is playing faster than it is being loaded.
Event constant: PlayerEvents.PlaybackBuffering
Payload
AudioChunksPlaybackFinished
Triggered when an audio chunk playback is finished. Note that this event is triggered only for RealtimeTTSPlayer instances.
For VoxTTS.RealtimeTTSPlayer, the optional final field indicates whether the completed flush ends the current phrase or is an intermediate auto-flush.
Event constant: PlayerEvents.AudioChunksPlaybackFinished
Payload