Player module lets developers send media (loaded from specified URL) or speech (generated by TTS) to calls and conferences by using sendMediaTo function. Audio will be mixed automatically if sent from a few players to one sink.

Add the following line to your scenario code to use the module:

 require(Modules.Player);

All functions, events and classes of the module can be used only after this line.

Events

PlayerEvents.PlaybackFinished

Dispatched when playback has finished successfully or in case of playback error

Properties
  • error: string

    Error message

  • player: Player

    Player that generated the event

PlayerEvents.PlaybackMarkerReached

Dispatched when playback marker is reached

Properties
  • offset: Number

    The marker offset

  • player: Player

    Player that generated the event

Functions

VoxEngine.createTTSPlayer(text, language, ttsoptions)

Player

Create new audio player with specified text. TTS is used to play this text.

Media sinks can later be attached using sendMediaTo() etc.
If text length exceeds 1500 characters Player.PlaybackFinished event is fired with error description.
Parameters
  • text: String

    Text to say

  • language: String (optional)

    TTS language

  • ttsoptions: VoxEngine.TTSOptions (optional)

    Optional parameters for TTS

Returns

VoxEngine.createToneScriptPlayer(script, loop)

Player

Create new audio player with specified ToneScript sequence

Media sinks can later be attached using sendMediaTo() etc.
Parameters
  • script: String

    ToneScript string

  • loop: Boolean (optional)

    Looped playback

Returns

VoxEngine.createURLPlayer(url, loop)

Player

Create new audio player with specified audio file URL

Media sinks can later be attached using sendMediaTo() etc.
Parameters
  • url: String

    URL of media file

  • loop: Boolean (optional)

    Looped playback

Returns

Example

 require(Modules.Player);

 var call,
 player;

 VoxEngine.addEventListener(AppEvents.CallAlerting, function(e) {
		call = e.call;
	  	call.answer();
		call.addEventListener(CallEvents.Connected, function(callevent) {
	      	// Play intro speech
	    	player = VoxEngine.createTTSPlayer("Hello, you have called VoxImplant Player demo", Language.US_ENGLISH_FEMALE);
	      	player.sendMediaTo(call);
	      	// When playback finished
	      	player.addEventListener(PlayerEvents.PlaybackFinished, function(playerevent) {
	          // Play mp3 file
	          player = VoxEngine.createURLPlayer("http://cdn.voximplant.com/yodl.mp3", true);
	          player.sendMediaTo(call);
	          setTimeout(VoxEngine.terminate, 10000); // end the session in 10 sec
	      	});
	  	});
	  	call.addEventListener(CallEvents.Disconnected, VoxEngine.terminate);
	});