You can pass an uploaded audio file's name to TTSChunk
, allowing any API that takes a text-to-speech parameter to pass and play your audio file. A sports app, for example, could play a distinctive audio chime to notify the user of a score update alongside an Alert
request.
On Manticore, audio indications work best in Google Chrome, Mozilla Firefox, or Microsoft Edge. Audio indications do not work in Apple Safari at this time.
The first step is to make sure the audio file is available on the remote system. To upload the file use the FileManager
.
const audioFile = new SDL.manager.file.filetypes.SdlFile('Audio file name', SDL.rpc.enums.FileType.AUDIO_MP3, fileData, true); const success = await sdlManager.getFileManager().uploadFile(audioFile)
For more information about uploading files, see the Uploading Files guide.
Now that the file is uploaded to the remote system, it can be used in various RPCs, such as Speak
, Alert
, and AlertManeuver
. To use the audio file in an alert, you simply need to construct a TTSChunk
referring to the file's name.
const alert = new SDL.rpc.messages.Alert(); alert.setAlertText1('Alert Text 1'); alert.setAlertText2('Alert Text 2'); alert.setDuration(5000); alert.setTtsChunks([new SDL.rpc.structs.TTSChunk().setText('Audio file name').setType(SDL.rpc.enums.SpeechCapabilities.FILE)]); // sdl_javascript_suite v1.1+ sdlManager.sendRpcResolve(alert); // Pre sdl_javascript_suite v1.1 sdlManager.sendRpc(alert);