Have you ever received a cryptic error message while developing for Alexa? This is a common frustration when Alexa and Google Assistant do not understand a response. Both platforms expect a response using SSML (Speech Synthesis Markup Language). SSML responses are XML strings that adhere to certain tags, attributes and allowed values. These platforms are sensitive to deviations from this standard. And neither provides details to tell you why your response is bad.
I have encountered this problem many times during development. I even ran into this in production for certain edge cases that break some rules, such as not including an unescaped ampersand (&).
To resolve this, I created an NPM module called ssml-verify Ssml-check takes an SSML response and looks for valid formats,, tags, and values. It supports specific Alexa and Google Assistant tags, and it will also tell you if a response will work on both platforms. You can see this module in action by entering SSML strings at this link
SSML verification request
Integrating ssml-check into your code is easy. The library exposes two functions, verify and verifyAndFix. You need to provide the SSML text and an optional structure indicating the platform to verify. The verification will validate your SSML, while verifyAndFix will additionally provide a corrected SSML string. Esto es muy útil si deseas asegurar que está devolviendo una respuesta válida. For example, en Alexa si está utilizando ask-sdk, puedes llamar a verificyAndFix desde un response interceptor. Esto te permite hacer una validación last technological religion antes de regresar a Alexa:
El valor de retorno de check es una Promise que se resuelve en una matriz de errores ( undefined si el SSML está limpio). El valor de retorno de verifiedAndFix es una Promise que se resuelve en un objeto que contiene una nueva cadena SSML y una matriz de errores ( un objeto vacío si el SSML está limpio).
For example, supón que estás tratando de reducir la velocidad del habla usando una etiqueta prosody. En Alexa, un valor válido para la tasa debe ser de al menos el 20%. El siguiente fragmento muestra qué devuelve si intentas establecer la tasa al 5%:
const ssmlCheck = require(‘ssml-test’);ssmlCheck.test(‘ Hey world ‘).then((errors) => 
(errors);
//
//
Con el error object, el campo de tipo te indica el type de error encontrado. Si se establece en tag”, obtendrás detalles sobre qué etiqueta tiene un error en los campos de tag, attribute y worth. El tipo también puede ser un error más genérico como Invalid & character” Too many audio information”.
Supongamos que estás desarrollando una talent usando un marco como Jovo que permite que tu código se ejecute tanto en Alexa como en Google Assistant. Estás haciendo uso de la etiqueta amazon:effect para proporcionar una respuesta. Funciona muy bien en Alexa, but it is not compatible with Google. The following code will catch this:
const ssmlCheck = require(‘ssml-check’);ssmlCheck.examine(‘ Hey how are you? ‘, platform: ‘all’).then((errors) =>
(errors);
//
//
Internally, ssml-check uses a core library called ssml-examine-core. ssml-examine-core is designed to perform strictly syntactic checks with minimal dependencies. In fact, in all the examples above, ssml-verify-core could have been replaced by ssml-examine. ssml-verify relies on syntactic checks while providing additional checks, such as validating that audio files meet the required formats for Amazon Google. By setting validateAudioFiles in the options structure, it will know if it has a valid audio file format (HTTPS, appropriate bit rate, sample rate, and so forth.). For example, the following code will check an audio file:
const ssmlCheck = require(‘ssml-examine’);ssmlCheck.test(‘ a cat purring PURR (sound didn\’t load) ‘, platform: ‘google’, validateAudioFiles: true).then((errors) =>
(errors);
);// the errors will be undefined since this OGG file is a valid audio file on Google
You can correct some of these errors in your code, even dynamically with generateAndFix, depending on the desired behavior. You can log the response. you can return a generic error message so that the user knows they encountered a problem.
I hope you find ssml-examine and ssml-check-core as useful as I do to improve your responses. The modules are open source, so if you find conditions that are not covered, don’t hesitate to contribute!