Build Talking Apps for Alexa by Craig Walls
Author:Craig Walls [Craig Walls]
Language: eng
Format: epub
Publisher: Pragmatic Bookshelf
Published: 2022-04-25T00:00:00+00:00
Playing Music and Sound Effects
As we saw in the previous chapter, using sound effects and music in a response adds some flair beyond just speech. APL-Aâs Audio component serves that purpose, as shown here:
â {
â â"type"â: â"APLA"â,
â â"version"â: â"0.9"â,
â â"mainTemplate"â: {
â â"item"â: {
â â"type"â: â"Audio"â,
â â"source"â:
â â"soundbank://soundlibrary/scifi/amzn_sfx_scifi_small_zoom_flyby_01"â
â }
â }
â }
Here, the source property is set to reference one of the many sounds in the ASK sound library.
Although the ASK sound library has a vast selection of sound effects, you can also provide your own by supplying a URL to an MP3 file in the source property, as shown in the following APL-A template:
â {
â â"type"â: â"APLA"â,
â â"version"â: â"0.9"â,
â â"mainTemplate"â: {
â â"item"â: {
â â"type"â: â"Audio"â,
â â"source"â: â"https://starport75.dev/audio/SP75.mp3"â
â }
â }
â }
Itâs important that the given URL is accessible by the fulfillment code that backs your Alexa skill. It also must be an HTTPS URL because HTTP URLs will not work.
If youâre hosting your audio files in Amazon S3, then youâll either need to open up the security on the S3 bucket to allow access to the audio files or, even better, leave them locked down, but use a pre-signed S3 URL. To help you obtain a pre-signed URL, the util.js module that you got when initializing the skill project provides a getS3PreSignedUrl() function.
While you canât use the getS3PreSignedUrl() function in the APL-A template itself, you can call it from your fulfillment code and then pass the resulting URL as a parameter to the APL-A template.
Weâll look at how to pass parameters from the fulfillment code in section âReturning APL-A Responsesâ. But to give some idea of how you might pass a pre-signed S3 URL to the APL-A template, consider the following snippet of fulfillment code:
â âconstâ Util = require(â'./util'â);
â
â ...
â
â âconstâ LaunchRequestHandler = {
â canHandle(handlerInput) { ... },
â handle(handlerInput) {
â ...
â âconstâ mySoundUrl = Util.getS3PreSignedUrl(â'Media/sounds/my-sound.mp3'â);
â âreturnâ responseBuilder
â â â .addDirective({
â â ââ"type"â: â"Alexa.Presentation.APLA.RenderDocument"â,
â â ââ"document"â: {
â â ââ"type"â: â"Link"â,
â â ââ"src"â: â"doc://alexa/apla/documents/welcome"â
â â â},
â â"datasources"â: {
â â"sounds"â: {
â â"mySoundUrl"â: mySoundUrl
â }
â }
â â â})
â .getResponse()
â }
â };
The URL returned from getS3PreSignedUrl() includes token information to get through the S3 bucketâs security. But it is only valid for about one minute, which is plenty of time for the response to be sent to the device. Do not try to assign it to a module-level constant, though, because it will expire before it can be used.
You may be wondering why youâd use the Audio component instead of just using the Speech component to return SSML with the <audio> tag. While you could do that, it limits how the audio is presented in relation to speech and other sounds. As weâll see in section âMixing Soundsâ, the Audio component can be mixed with Speech or other Audio components such that they play at the same time, effectively offering background audio.
But before we get to that, letâs take a quick look at the silent partner of the Speech and Audio components: the Silence component.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Core Data Services for ABAP by Renzo Colle Ralf Dentzer Jan Hrastnik(545)
Data Visualization with Python and JavaScript, 2nd Edition by Kyran Dale(511)
ABAP Programming Model for SAP Fiori by Unknown(199)
Financial Accounting (FI) with SAP S/4HANA: Business User Guide (SAP PRESS) by Stefan Walz Reinhard Rupp Nertila Mucka Jonas Tritschler(181)
Python 3 Data Visualization Using ChatGPT GPT-4 by Oswald Campesato(133)
Data Visualization with Python and JavaScript, 2nd Edition by Unknown(130)
Data Visualization with Python for Beginners by AI Publishing(120)
Financial Reporting with SAP S4HANA by Korkmaz Aylin;(76)
The complete works of ralph waldo emerson . vol. 2 by 1873(71)
The complete works of ralph waldo emerson . vol. 1 by 1873(70)
GDPR and SAP: Data Privacy with SAP Business Suite and SAP S4HANA by Lehnert & Luther & Christoph & Pluder & Fernandes(63)
Logistics with SAP S4HANA by An Introduction(63)
Assembly Lines: The Book; A Beginner's Guide to 6502 Programming on the Apple ][ by Wagner Roger(60)
Materials Management with SAP S4HANA by Unknown(60)
SAP Lumira Discovery Edition by The Comprehensive Guide(55)
Introducing Production Planning and Detailed Shceduling (PP-DS) with SAP S4HANA by Unknown(52)
Upgrading SAP by The Comprehensive Guide(51)
Lease Accounting with SAP by IFRS 16 & ASC 842(49)
The SAP Green Book by A Business Guide for Effectively Managing the SAP Lifecycle(49)
