aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-12 23:59:21 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-13 12:21:19 -0400
commit7bae3824e74461fbd5c9f66f921b05a47a40cbf4 (patch)
treed0cdc8580497e447e05a31ab1e4806c4f325390b /ext/bg
parent69b28571bdf8fb4c13198223e8a5668cf490840c (diff)
Add support for text-to-speech playback
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/audio.js18
-rw-r--r--ext/bg/settings.html4
2 files changed, 21 insertions, 1 deletions
diff --git a/ext/bg/js/audio.js b/ext/bg/js/audio.js
index 9508abf0..3efcce46 100644
--- a/ext/bg/js/audio.js
+++ b/ext/bg/js/audio.js
@@ -86,6 +86,24 @@ const audioUrlBuilders = {
throw new Error('Failed to find audio URL');
},
+ 'text-to-speech': async (definition, optionsContext) => {
+ const options = await apiOptionsGet(optionsContext);
+ const voiceURI = options.audio.textToSpeechVoice;
+ if (!voiceURI) {
+ throw new Error('No voice');
+ }
+
+ return `tts:?text=${encodeURIComponent(definition.expression)}&voice=${encodeURIComponent(voiceURI)}`;
+ },
+ 'text-to-speech-reading': async (definition, optionsContext) => {
+ const options = await apiOptionsGet(optionsContext);
+ const voiceURI = options.audio.textToSpeechVoice;
+ if (!voiceURI) {
+ throw new Error('No voice');
+ }
+
+ return `tts:?text=${encodeURIComponent(definition.reading || definition.expression)}&voice=${encodeURIComponent(voiceURI)}`;
+ },
'custom': async (definition, optionsContext) => {
const options = await apiOptionsGet(optionsContext);
const customSourceUrl = options.audio.customSourceUrl;
diff --git a/ext/bg/settings.html b/ext/bg/settings.html
index ffa5533e..15425b44 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -319,8 +319,10 @@
<div class="input-group-addon audio-source-prefix"></div>
<select class="form-control audio-source-select">
<option value="jpod101">JapanesePod101</option>
- <option value="jpod101-alternate">JapanesePod101 (alternate)</option>
+ <option value="jpod101-alternate">JapanesePod101 (Alternate)</option>
<option value="jisho">Jisho.org</option>
+ <option value="text-to-speech">Text-to-speech</option>
+ <option value="text-to-speech-reading">Text-to-speech (Kana reading)</option>
<option value="custom">Custom</option>
</select>
<div class="input-group-btn"><button class="btn btn-danger audio-source-remove" title="Remove"><span class="glyphicon glyphicon-remove"></span></button></div>