Skip to content

Commit 78e2cdb

Browse files
committed
Merge PR #403, adding google as default TTS
When no other TTS provider is configured, use Google TTS Allow VoiceId spec in URL for AWS Polly
1 parent 6980261 commit 78e2cdb

File tree

8 files changed

+43
-15
lines changed

8 files changed

+43
-15
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ Experimental support for TTS. Today the following providers are available:
365365
* voicerss
366366
* Microsoft Cognitive Services (Bing Text to Speech API)
367367
* AWS Polly
368-
* Google
368+
* Google (default)
369369

370370
It will use the one you configure in settings.json. If you define settings for multiple TTS services, it will not be guaranteed which one it will choose!
371371

@@ -488,7 +488,21 @@ If you have your credentials elsewhere and want to stick with the default voice,
488488
}
489489
```
490490

491-
This is the current list of voice names and their corresponding language and accent
491+
Action is:
492+
493+
/[Room name]/say/[phrase][/[name]][/[announce volume]]
494+
/sayall/[phrase][/[name]][/[announce volume]]
495+
496+
Example:
497+
498+
/Office/say/Hello, dinner is ready
499+
/Office/say/Hej, maten är klar/Joanna
500+
/sayall/Hello, dinner is ready
501+
/Office/say/Hello, dinner is ready/90
502+
/Office/say/Hej, maten är klar/Russell/90
503+
504+
This is the current list of voice names and their corresponding language and accent (as of Dec 2016).
505+
To get a current list of voices, you would need to use the AWS CLI and invoke the describe-voices command.
492506

493507
| Language | Code | Gender | Name |
494508
| --------- | ---- | ------ | ---- |
@@ -538,11 +552,11 @@ This is the current list of voice names and their corresponding language and acc
538552
| US Spanish | es-US | Female | Penelope |
539553
| US Spanish | es-US | Male | Miguel |
540554
| Welsh | cy-GB | Female | Gwyneth |
541-
| Welsh | English | en-GB-WLS | Male | Geraint |
555+
| Welsh English | en-GB-WLS | Male | Geraint |
542556

543-
#### Google
557+
#### Google (default if no other has been configured)
544558

545-
Does not require any API keys. Please note that Google has been known in the past to change the requirements for its Text-to-Speech API, and this may stop working in the future.
559+
Does not require any API keys. Please note that Google has been known in the past to change the requirements for its Text-to-Speech API, and this may stop working in the future. There is also limiations to have many request one is allowed to do in a specific time period.
546560

547561
The following language codes are supported
548562

lib/actions/say.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function say(player, values) {
1818
if (/^\d+$/i.test(values[1])) {
1919
// first parameter is volume
2020
announceVolume = values[1];
21-
language = 'en-gb';
21+
// language = 'en-gb';
2222
} else {
23-
language = values[1] || 'en-gb';
23+
language = values[1];
2424
announceVolume = values[2] || settings.announceVolume || 40;
2525
}
2626

lib/actions/sayall.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ function sayAll(player, values) {
1414
if (/^\d+$/i.test(values[1])) {
1515
// first parameter is volume
1616
announceVolume = values[1];
17-
language = 'en-gb';
17+
// language = 'en-gb';
1818
} else {
19-
language = values[1] || 'en-gb';
19+
language = values[1];
2020
announceVolume = values[2] || settings.announceVolume || 40;
2121
}
2222

lib/helpers/try-download-tts.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ requireDir(path.join(__dirname, '../tts-providers'), (provider) => {
77
providers.push(provider);
88
});
99

10+
providers.push(require('../tts-providers/default/google'));
11+
1012
function tryDownloadTTS(phrase, language) {
1113
let path;
1214
return providers.reduce((promise, provider) => {

lib/tts-providers/aws-polly.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@ const DEFAULT_SETTINGS = {
1212
TextType: 'text'
1313
};
1414

15-
function polly(phrase, language) {
15+
function polly(phrase, voiceName) {
1616
if (!settings.aws) {
1717
return Promise.resolve();
1818

1919
}
2020

2121
// Construct a filesystem neutral filename
2222
const dynamicParameters = { Text: phrase };
23+
const synthesizeParameters = Object.assign({}, DEFAULT_SETTINGS, dynamicParameters);
2324
if (settings.aws.name) {
24-
dynamicParameters.VoiceId = settings.aws.name;
25+
synthesizeParameters.VoiceId = settings.aws.name;
2526
}
26-
const synthesizeParameters = Object.assign({}, DEFAULT_SETTINGS, dynamicParameters);
27+
if (voiceName) {
28+
synthesizeParameters.VoiceId = voiceName;
29+
}
30+
2731
const phraseHash = crypto.createHash('sha1').update(phrase).digest('hex');
2832
const filename = `polly-${phraseHash}-${synthesizeParameters.VoiceId}.mp3`;
2933
const filepath = path.resolve(settings.webroot, 'tts', filename);

lib/tts-providers/google.js renamed to lib/tts-providers/default/google.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ const crypto = require('crypto');
33
const fs = require('fs');
44
const http = require('http');
55
const path = require('path');
6-
const settings = require('../../settings');
6+
const settings = require('../../../settings');
77

88
function google(phrase, language) {
9+
if (!language) {
10+
language = 'en';
11+
}
12+
913
// Use Google tts translation service to create a mp3 file
10-
const ttsRequestUrl = 'http://translate.google.com/translate_tts?client=tw-ob&tl=' + language + '&q=' + phrase;
14+
const ttsRequestUrl = 'http://translate.google.com/translate_tts?client=tw-ob&tl=' + language + '&q=' + encodeURIComponent(phrase);
1115

1216
// Construct a filesystem neutral filename
1317
const phraseHash = crypto.createHash('sha1').update(phrase).digest('hex');

lib/tts-providers/voicerss.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function voicerss(phrase, language) {
1010
return Promise.resolve();
1111

1212
}
13+
14+
if (!language) {
15+
language = 'en-gb';
16+
}
1317
// Use voicerss tts translation service to create a mp3 file
1418
const ttsRequestUrl = `http://api.voicerss.org/?key=${settings.voicerss}&f=22khz_16bit_mono&hl=${language}&src=${encodeURIComponent(phrase)}`;
1519

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sonos-http-api",
3-
"version": "1.2.5",
3+
"version": "1.2.6",
44
"description": "A simple node app for controlling a Sonos system with basic HTTP requests",
55
"scripts": {
66
"start": "node server.js"

0 commit comments

Comments
 (0)