Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Fix #162, avoid error message when you don't speak
Browse files Browse the repository at this point in the history
This adds onProcessing and onNoVoice callbacks. This also restores displaying a progress indicator when the voice is recorded and being sent to the server.
  • Loading branch information
ianb committed Sep 19, 2019
1 parent f2efa22 commit 12038f7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
7 changes: 7 additions & 0 deletions extension/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ this.popup = (function() {
ui.setState("error");
clearInterval(intervalId);
};
recorder.onProcessing = () => {
ui.setState("processing");
};
recorder.onNoVoice = () => {
log.debug("Closing popup because of no voice input");
window.close();
};
recorder.startRecording();
}

Expand Down
12 changes: 11 additions & 1 deletion extension/popup/vad.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ this.vad = (function() {
exports.stm_vad;
exports.stm_vad_ready = util.makeNakedPromise();

exports.onProcessing = () => {
// Can be overridden
};

exports.onNoVoice = () => {
// Can be overridden
};

exports.SpeakToMeVad = class SpeakToMeVad {
constructor() {
this.webrtc_main = Module.cwrap("main");
Expand Down Expand Up @@ -157,10 +165,12 @@ this.vad = (function() {
this.stopGum();
// FIXME: maybe we need to signal the UI here?
if (why === "GoCloud finishedvoice") {
exports.onProcessing();
if (typeof ui !== "undefined") {
// FIXME: needs updating for shim
ui.setState("processing"); // TODO: send a message through voice.js to popup.js to ui.js to set the processing state
}
} else if (why === "Raise novoice") {
exports.onNoVoice();
}
}
};
Expand Down
15 changes: 15 additions & 0 deletions extension/popup/voice.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ this.voice = (function() {
this.sourceNode.disconnect(this.analyzerNode);
this.analyzerNode.disconnect(this.outputNode);
};
// FIXME: this is a bad pattern, but all I got for now...
vad.onProcessing = () => {
this.onProcessing();
};
vad.onNoVoice = () => {
this.onNoVoice();
};
// connect stream to our recorder
this.sourceNode.connect(this.scriptprocessor);
// MediaRecorder initialization
Expand Down Expand Up @@ -94,6 +101,14 @@ this.voice = (function() {
// Can be overridden
}

onProcessing() {
// Can be overridden
}

onNoVoice() {
// Can be overridden
}

/** Returns 0.0-1.0, based on our estimation of volume */
getVolumeLevel() {
const MIN_DB_LEVEL = -85; // The dB level that is 0 in the levels display
Expand Down
11 changes: 10 additions & 1 deletion extension/popup/voiceShim.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ this.voiceShim = (function() {
// override
}

onProcessing(exception) {
// override
}
onNoVoice(exception) {
// override
}

getVolumeLevel() {
browser.runtime
.sendMessage({
Expand All @@ -85,7 +92,9 @@ this.voiceShim = (function() {
const args = message.args || [];
if (
activeRecorder._cancelled &&
["onEnd", "onError"].includes(message.method)
["onEnd", "onError", "onProcessing", "onNoVoice"].includes(
message.method
)
) {
return null;
}
Expand Down
24 changes: 24 additions & 0 deletions extension/recorder/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ this.recorder = (function() {
}
}

onProcessing() {
if (this._destroyed) {
log.error("onProcessing called after ShimRecorder destroyed");
} else {
browser.runtime.sendMessage({
type: "onVoiceShimForward",
method: "onProcessing",
args: [],
});
}
}

onNoVoice() {
if (this._destroyed) {
log.error("onNoVoice called after ShimRecorder destroyed");
} else {
browser.runtime.sendMessage({
type: "onVoiceShimForward",
method: "onNoVoice",
args: [],
});
}
}

destroy() {
this._destroyed = true;
}
Expand Down

0 comments on commit 12038f7

Please sign in to comment.