SIGN UP
Navigation

Player

The Player module allows to send audio (loaded from specified URL) or speech (generated by TTS) to any object that can receive media Call, Conference, Recorder) by using Player.sendMediaTo function. Audio will be mixed automatically if sent from a few players to one stream.

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.

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);
	});
  • Player
  • VoxEngine.createTTSPlayer
    Create new audio player with specified text. TTS is used to play this text. Media streams can later be attached using the [Call.sendMediaTo] method etc.
    If text length exceeds 1500 characters the [Player.PlaybackFinished] event is triggered with error description.
  • VoxEngine.createToneScriptPlayer
    Create new audio player with specified ToneScript sequence. Media streams can later be attached using the [Call.sendMediaTo] method etc.
  • VoxEngine.createURLPlayer
    Creates a new audio player with specified audio file URL. Media streams can later be attached using the [Call.sendMediaTo] method etc. Supported formats are: mp3, ogg & flac (mp3, speex, vorbis and flac codecs respectively). After the very first playing each file is cached in the Voximplant cloud. The cached file is available for all applications and further sessions. After the 3600 sec from the last request (i.e. last playing) the file will be deleted from the cache.
  • Events

functions

VoxEngine.createTTSPlayer(text: String, language: String, ttsoptions: TTSOptions): Player

Create new audio player with specified text. TTS is used to play this text. Media streams can later be attached using the Call.sendMediaTo method etc.
If text length exceeds 1500 characters the Player.PlaybackFinished event is triggered with error description.

Parameters

  • text:

    String

    Text to say

  • language:

    String

    TTS language. List of all supported languages: Language.

  • Optional parameters for TTS. Note that support of the TTSOptions.pitch parameter depends on the language and dictionary used. For unsupported combinations the PlaybackFinished event will be triggered with error 400.

Returns

VoxEngine.createToneScriptPlayer(script: String, loop: Boolean): Player

Create new audio player with specified ToneScript sequence. Media streams can later be attached using the Call.sendMediaTo method etc.

Parameters

  • script:

    String

    ToneScript string

  • loop:

    Boolean

    Looped playback

Returns

Examples

request:

 var player = VoxEngine.createToneScriptPlayer("425@-19;5(1/4/1)");
VoxEngine.createURLPlayer(url: String, loop: Boolean): Player

Creates a new audio player with specified audio file URL. Media streams can later be attached using the Call.sendMediaTo method etc. Supported formats are: mp3, ogg & flac (mp3, speex, vorbis and flac codecs respectively). After the very first playing each file is cached in the Voximplant cloud. The cached file is available for all applications and further sessions. After the 3600 sec from the last request (i.e. last playing) the file will be deleted from the cache.

Parameters

  • url:

    String

    URL of media file

  • loop:

    Boolean

    Looped playback

Returns

Examples

request:

 var player = VoxEngine.createURLPlayer("https://direct/link/to/the/file.mp3", true);