The usage is quite simple: you create an instance of a player and assign it to a variable. Then you can use the player's built-in methods to control the playback. Look at the simple example:
The scenario answers a call and greets a caller via the TTS player. After the TTS greeting is finished, another player starts to play audio for about 10 seconds, then the scenario terminates a session. These are the basics of the Player's module usage and they work in complicated scenarios in absolutely the same way, but there is a nuance – the cache.
All types of players cache their audio after the very first playing, the cache data of each player's instance is stored up to 2 weeks. But what if there could be an undesirable delay before the first playing? For example, you want the TTS player to pronounce quite a long phrase or the URL player has to download a file of a maximum available size (10mb). In such cases, you can use the cache too.
URL player's onPause parameter
URL player has the onPause parameter, it literally sets the player on pause right after its creation. If this parameter is set to true, a newly created player instance immediately starts file downloading to the cache. Eventually, when you need to play audio, you will use the resume method to start playback directly from the cache, without delays. Here are the changes to the first example:
The TTS player doesn't have any onPause-like parameter. Usually, there is no delay in TTS playback, but you can use the same hint as in the previous piece of code: create an instance in advance. The combination of pre-cached URL and TTS players looks like this:
Use the Force
We hope this small piece of advice can come in handy during your development journey. Have fun with Voximplant, see you there!