API: Read Text to Visitors
Allows you to prompt the device to read text strings out loud. Optional parameters allow you to define the desired language and region of the voice used, as well as voice quality, volume, pitch, rate and timing.
Requirements
- Integration of our JavaScript API into your webpage
- Sample code to run within the app and download for integration into your own project is available here.
- Best practices for working with the JavaScript API are available here.
- App Settings
- Content > JavaScript API > Access JavaScript API = By Import
Triggers via API Functions
Read Text String
This function prompts the device to read the text string that has been passed.
Format | kp_Speech_speak(textToSpeak, speechConfig); |
Parameters |
|
Triggers | kp_Speech_didStartSpeechUtterance immediately. When the speech is complete, triggers kp_Speech_didFinishSpeechUtterance |
Example
This function speaks "Hello world!" with a specific configuration:
function speak() { var speechConfig = '{\ "rate": 0.5,\ "pitchMultiplier": 1,\ "volume": 1,\ "preUtteranceDelay": 0,\ "postUtteranceDelay": 0,\ "voice": {\ "languageCode": "en-US",\ }\ }'; kp_Speech_speak('Hello world', speechConfig); }
Pause Speaking
This function pauses any speech currently ongoing. The place at which the speech is paused is saved and speech can be resumed from that point by triggering kp_Speech_continue.
kp_Speech_pause(); |
|
Triggers | kp_Speech_didPauseSpeechUtterance |
Continue Speaking
This function continues speech that has been paused using kp_Speech_pause.
Format | kp_Speech_continue(); |
Triggers | kp_Speech_didContinueSpeechUtterance |
Stop Speaking
This function immediately stops any speech currently ongoing. Speech ended using this function cannot be resumed, but instead would need to be restarted from the beginning using a new Read Text String command.
Format | kp_Speech_stop(); |
Triggers | kp_Speech_didCancelSpeechUtterance |
Check Default Language Code
This function triggers a callback returning the default language code for the device. For example, "en-US".
Format | kp_Speech_requestCurrentLanguageCode(callback); |
Parameters | callback - [string] the name of the callback to be triggered after the function has been executed |
Callback format | callback(currentLanguageCode); |
Callback return values | currentLanguageCode - [string] the default language code for the device |
Check Language Code Options
This function triggers a callback containing a list of available language codes.
Format | kp_Speech_requestListOfLanguageCodes(callback); |
Parameters | callback - [string] the name of the callback to be triggered after the function has been executed |
Callback format | callback(langCodes); |
Callback return values | langCodes - [array] containing a list of available language codes |
Check Voice Library Options
This function triggers a callback returning a list of voice libraries available on the device. Additional voice libraries can be downloaded in iOS/iPadOS Settings under Accessibility > Spoken Content > Voices.
Format | kp_Speech_requestListOfVoiceIdentifiers(callback); |
Parameters | callback - [string] the name of the callback to be triggered after the function has been executed |
Callback format | callback(voiceIDs); |
Callback return values | voiceIDs [array] containing a list of voice libraries available on the device |
Notifications via API Callbacks
When Speech Starts
This callback is triggered when a speech successfully starts.
Format | kp_Speech_didStartSpeechUtterance(speechString); |
Parameters | speechString - [string] the text currently in use by the API |
When Speech Completes
This callback is triggered when a speech successfully finishes.
Format | kp_Speech_didFinishSpeechUtterance(speechString); |
Parameters | speechString - [string] the text currently in use by the API |
When Speech Pauses
This callback is triggered when a speech is paused.
Format | kp_Speech_didPauseSpeechUtterance(speechString); |
Parameters | speechString - [string] the text currently in use by the API |
When Speech Continues
This callback is triggered when a paused speech is continued.
Format | kp_Speech_didContinueSpeechUtterance(speechString); |
Parameters | speechString - [string] the text currently in use by the API |
When Speech Is Stopped
This callback is triggered when a speech is stopped.
Format | kp_Speech_didCancelSpeechUtterance(speechString); |
Parameters | speechString - [string] the text currently in use by the API |
Sample Code
- This sample code relies on the JavaScript APIs built into Kiosk Pro and will not run successfully in other browsers or within our in-app help interface.
- To run sample code, set the app's homepage to kioskgroup.com/read-text-api
- To download a .zip of sample code, click here.
Change Log
- Added in version 9.3