Browse Source

Added speech recognition as a setting, off by default

reviewable/pr190/r10
Samuel Attard 6 years ago
parent
commit
d8e306b087
  1. 14
      src/inject/GPMInject/interface/voiceControls/SpeechRecognizer.js
  2. 9
      src/inject/GPMInject/interface/voiceControls/index.js
  3. 10
      src/inject/settings/general.js
  4. 3
      src/main/features/core/desktopSettings.js
  5. 4
      src/public_html/desktop_settings.html

14
src/inject/GPMInject/interface/voiceControls/SpeechRecognizer.js

@ -6,6 +6,7 @@ export default class SpeechRecognizer {
constructor(hotwords = [], prefixes = []) {
this.hotwords = hotwords;
this.prefixes = prefixes;
this.enabled = false;
this.speech = new window.webkitSpeechRecognition(); // eslint-disable-line
this.speech.onresult = this._onSpeech.bind(this);
@ -13,14 +14,23 @@ export default class SpeechRecognizer {
this.speech.onerror = () => this.speech.stop();
this.speech.onnomatch = () => this.speech.stop();
this.speech.onend = () => {
if (Settings.get('speechControl', true)) {
if (this.enabled) {
this.speech.start();
}
};
this._handlers = {};
}
enable() {
this.speech.stop();
this.speech.start();
this.enabled = true;
}
this._handlers = {};
disable() {
this.enabled = false;
this.speech.stop();
}
_onSpeech(event) {

9
src/inject/GPMInject/interface/voiceControls/index.js

@ -8,6 +8,15 @@ window.wait(() => {
['Let\'s', 'can you', 'can you please', 'please'] // Command prefix
);
Emitter.on('speech:toggle', (event, details) => {
if (details.state) {
speech.enable();
} else {
speech.disable();
}
});
if (Settings.get('speechRecognition', false)) speech.enable();
// Play Playlist Handlers
speech.registerHandler(['play playlist', 'play the playlist'], playPlaylist);

10
src/inject/settings/general.js

@ -7,3 +7,13 @@ if (Settings.get('playbackAPI', false)) {
} else {
$('#playback-api').removeAttr('checked');
}
$('#voice-controls').change((e) => {
Emitter.fire('settings:set', { key: 'speechRecognition', value: $(e.currentTarget).is(':checked') });
});
if (Settings.get('speechRecognition', false)) {
$('#voice-controls').attr('checked', true);
} else {
$('#voice-controls').removeAttr('checked');
}

3
src/main/features/core/desktopSettings.js

@ -36,6 +36,9 @@ Emitter.on('settings:set', (event, details) => {
case 'miniAlwaysOnTop':
Emitter.sendToGooglePlayMusic('miniAlwaysOnTop', { state: details.value });
break;
case 'speechRecognition':
Emitter.sendToGooglePlayMusic('speech:toggle', { state: details.value });
break;
default:
break;
}

4
src/public_html/desktop_settings.html

@ -67,6 +67,10 @@
<div class="color-square brown"></div>
</div>
<div>
<p>
<input type="checkbox" class="filled-in" id="voice-controls" />
<label for="voice-controls">Enable Voice Controls <i>Hands free voice controls for GPMDP, this is experimental</i></label>
</p>
<p>
<input type="checkbox" class="filled-in" id="playback-api" />
<label for="playback-api">Enable Playback API <i>This allows other applications to interface with GPMDP</i></label>

Loading…
Cancel
Save