From d4f7eb97c8a0f2b289d071c8e70daddf6bb22639 Mon Sep 17 00:00:00 2001 From: Jimmy Shimizu Date: Tue, 1 Aug 2017 23:27:19 +0200 Subject: [PATCH] fix: Escape non-ascii characters as xml entities for Microsoft TTS --- lib/tts-providers/microsoft.js | 6 +++++- package.json | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tts-providers/microsoft.js b/lib/tts-providers/microsoft.js index 945d5b4b..1afde6fe 100644 --- a/lib/tts-providers/microsoft.js +++ b/lib/tts-providers/microsoft.js @@ -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'); @@ -34,7 +37,8 @@ function generateBearerToken(apiKey) { } function format(lang, gender, name, text) { - return `${text}`; + const escapedText = xmlEntities.encodeNonUTF(text); + return `${escapedText}`; } function microsoft(phrase, voiceName) { diff --git a/package.json b/package.json index bd01eb60..a96dbd5d 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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",