Skip to content

Commit

Permalink
fix: Escape non-ascii characters as xml entities for Microsoft TTS
Browse files Browse the repository at this point in the history
  • Loading branch information
jishi committed Aug 1, 2017
1 parent 59d8d43 commit d4f7eb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/tts-providers/microsoft.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const request = require('sonos-discovery/lib/helpers/request');
const logger = require('sonos-discovery/lib/helpers/logger');
const path = require('path');
const globalSettings = require('../../settings');
const XmlEntities = require('html-entities').XmlEntities;

const xmlEntities = new XmlEntities();

const APP_ID = '9aa44d9e6ec14da99231a9166fd50b0f';
const INSTANCE_ID = crypto.randomBytes(16).toString('hex');
Expand Down Expand Up @@ -34,7 +37,8 @@ function generateBearerToken(apiKey) {
}

function format(lang, gender, name, text) {
return `<speak version='1.0' xml:lang='en-us'><voice xml:lang='${lang}' xml:gender='${gender}' name='${name}'>${text}</voice></speak>`;
const escapedText = xmlEntities.encodeNonUTF(text);
return `<speak version='1.0' xml:lang='${lang}'><voice xml:lang='${lang}' xml:gender='${gender}' name='${name}'>${escapedText}</voice></speak>`;
}

function microsoft(phrase, voiceName) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sonos-http-api",
"version": "1.4.2",
"version": "1.4.3",
"description": "A simple node app for controlling a Sonos system with basic HTTP requests",
"scripts": {
"start": "node server.js"
Expand All @@ -15,6 +15,7 @@
"aws-sdk": "^2.12.0",
"basic-auth": "~1.1.0",
"fuse.js": "^2.5.0",
"html-entities": "^1.2.1",
"json5": "^0.5.1",
"node-static": "~0.7.0",
"request-promise": "~1.0.2",
Expand Down

0 comments on commit d4f7eb9

Please sign in to comment.