Inworld
Inworld provides a real-time TTS player that can send generated audio to calls, WebSockets, and other VoxEngine media units.
Use Inworld.createRealtimeTTSPlayer(...) to create a RealtimeTTSPlayer for the current scenario. After the player is created, call methods such as send, sendMediaTo, and addEventListener on that player instance.
Related guides
Use Inworld as the realtime TTS layer in an OpenAI voice pipeline.
See where realtime speech synthesis fits into VoxEngine call flows.
Contents
- Usage: required module import and basic flow.
- Factory functions: create the realtime TTS player.
- RealtimeTTSPlayerParameters: API key, provider context, and WebSocket options.
- RealtimeTTSPlayer: runtime player object returned by the factory.
- Methods: direct Inworld player methods.
- Inherited Methods: playback and media methods inherited from the shared player base.
- PlayerEvents: player event names and playback lifecycle events.
Usage
Add the module before using the namespace:
Create a player, send provider messages, and bridge playback with sendMediaTo or VoxEngine.sendMediaBetween.
Factory functions
createRealtimeTTSPlayer
Creates a new Inworld.RealtimeTTSPlayer instance. You can attach media streams later via the Inworld.RealtimeTTSPlayer.sendMediaTo or VoxEngine.sendMediaBetween methods.
The optional parameters object is typed as Inworld.RealtimeTTS.
Parameters
Returns
RealtimeTTSPlayer
Methods
clearBuffer
Clears an Inworld.RealtimeTTSPlayer buffer.
Parameters
This method does not accept parameters.
Returns
send
Send message object to the Inworld provider context.
Parameters
Returns
Example parameters:
Inherited Methods
Inworld.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 Inworld.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.
Event constant: PlayerEvents.AudioChunksPlaybackFinished
Payload