forked from mozilla/DeepSpeech
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes mozilla#79
- Loading branch information
Alexandre Lissy
committed
Nov 29, 2016
1 parent
36f4883
commit 4e7f626
Showing
14 changed files
with
927 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FILES=bootstrap.js chrome.manifest dbg.html install.rdf main.js mic-off.png mic-on.png recorder.js visualize.js | ||
|
||
ADDON_VERSION ?= 0.1 | ||
|
||
XPI_NAME=ds-addon-$(ADDON_VERSION).xpi | ||
|
||
define build-install | ||
echo "build install.rdf"; | ||
sed -e 's#@@ADDON_VERSION@@#$(ADDON_VERSION)#' \ | ||
install.rdf.tmpl > install.rdf | ||
endef | ||
|
||
$(XPI_NAME): $(FILES) | ||
zip -r0 $@ $^ | ||
|
||
install.rdf: | ||
$(call build-install) | ||
|
||
all: $(XPIS) | ||
|
||
clean: | ||
rm -f $(XPI_NAME)*.xpi | ||
rm -f install.rdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
"use strict"; | ||
|
||
const Ci = Components.interfaces; | ||
const Cu = Components.utils; | ||
const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); | ||
|
||
Cu.import("resource://gre/modules/Services.jsm"); | ||
|
||
const REASON = [ "unknown", "startup", "shutdown", "enable", "disable", | ||
"install", "uninstall", "upgrade", "downgrade" ]; | ||
|
||
// Usefull piece of code from :bent | ||
// http://mxr.mozilla.org/mozilla-central/source/dom/workers/test/extensions/bootstrap/bootstrap.js | ||
function registerAddonResourceHandler(data) { | ||
let file = data.installPath; | ||
dump("IN registerAddonResourceHandler WITH file=" + file.path); | ||
let fileuri = file.isDirectory() ? | ||
Services.io.newFileURI(file) : | ||
Services.io.newURI("jar:" + file.path + "!/", null, null); | ||
let resourceName = encodeURIComponent(data.id.replace("@", "at")); | ||
|
||
Services.io.getProtocolHandler("resource"). | ||
QueryInterface(Ci.nsIResProtocolHandler). | ||
setSubstitution(resourceName, fileuri); | ||
|
||
return "resource://" + resourceName + "/"; | ||
} | ||
|
||
let mainModule; | ||
let loader; | ||
let unload; | ||
|
||
function install(data, reason) {} | ||
|
||
function startup(data, reason) { | ||
for (var p in data) { | ||
let value = null; | ||
|
||
if (data[p] && data[p].toString) { | ||
value = "=" + data[p].toString(); | ||
} else { | ||
value = " can not be dumped as a string\n"; | ||
} | ||
|
||
dump("data." + p + value + "\n"); | ||
} | ||
|
||
let uri = registerAddonResourceHandler(data); | ||
|
||
let loaderModule = | ||
Cu.import("resource://gre/modules/commonjs/toolkit/loader.js").Loader; | ||
let { Loader, Require, Main } = loaderModule; | ||
unload = loaderModule.unload; | ||
|
||
let loaderOptions = { | ||
paths: { | ||
"./": uri, | ||
"": "resource://gre/modules/commonjs/" | ||
}, | ||
modules: { | ||
"toolkit/loader": loaderModule | ||
}, | ||
id: "ds-addon@mozilla.org" | ||
}; | ||
|
||
/** | ||
* setup a console object that only dumps messages if | ||
* LOGPREF is true | ||
*/ | ||
|
||
const LOGPREF = "extensions.ds-addon@mozilla.org.debug"; | ||
const LOGPREFIX = "DeepSpeech:"; | ||
|
||
try { | ||
Services.prefs.getBoolPref(LOGPREF); | ||
} catch(e) { | ||
// Doesn't exist yet | ||
Services.prefs.setBoolPref(LOGPREF, false); | ||
} | ||
|
||
function canLog() { | ||
return Services.prefs.getBoolPref(LOGPREF); | ||
} | ||
|
||
// In Firefox 44 and later, many DevTools modules were relocated. | ||
// See https://bugzil.la/912121 | ||
const { ConsoleAPI } = Cu.import("resource://gre/modules/Console.jsm"); | ||
let _console = new ConsoleAPI(); | ||
loaderOptions.globals = { | ||
console: { | ||
log: function(...args) { | ||
canLog() && _console.log(LOGPREFIX, new Date(), ...args); | ||
}, | ||
warn: function(...args) { | ||
canLog() && _console.warn(LOGPREFIX, new Date(), ...args); | ||
}, | ||
error: function(...args) { | ||
canLog() && _console.error(LOGPREFIX, new Date(), ...args); | ||
}, | ||
debug: function(...args) { | ||
canLog() && _console.debug(LOGPREFIX, new Date(), ...args); | ||
}, | ||
exception: function(...args) { | ||
canLog() && _console.debug(LOGPREFIX, new Date(), ...args); | ||
}, | ||
} | ||
} | ||
|
||
loader = Loader(loaderOptions); | ||
let require_ = Require(loader, { id: "./addon" }); | ||
mainModule = require_("./main.js"); | ||
} | ||
|
||
function shutdown(data, reasonCode) { | ||
let reason = REASON[reasonCode]; | ||
if (loader) { | ||
unload(loader, reason); | ||
unload = null; | ||
} | ||
if (mainModule && mainModule.shutdown) { | ||
mainModule.shutdown(); | ||
} | ||
} | ||
|
||
function uninstall(data, reason) {} | ||
|
||
/* vim: set et ts=2 sw=2 : */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
content deepspeech ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<html> | ||
<head> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1"> | ||
<meta charset="utf-8" /> | ||
<title>DeepSpeech debug viz</title> | ||
<script type="application/javascript" src="visualize.js"></script> | ||
<script type="application/javascript"> | ||
"use strict"; | ||
|
||
Cu.import("resource://gre/modules/Services.jsm"); | ||
|
||
Services.obs.notifyObservers(null, "deepspeech-debug-page-opened", "YOLO"); | ||
</script> | ||
<style> | ||
body { | ||
font-size: 18px; | ||
font-family: sans-serif; | ||
max-width: 480px; /* no wider than 480px, narrower on phones */ | ||
margin: 20px auto 0 auto; /* center body within window */ | ||
text-align: center; /* center text within the body */ | ||
} | ||
|
||
.screen p { | ||
margin: 8px; | ||
} | ||
|
||
#sensitivity { | ||
width: 80%; | ||
} | ||
|
||
#levels { | ||
width: 600px; | ||
height: 300px; | ||
margin: 0 auto 0 auto; | ||
} | ||
|
||
#values { | ||
margin: 0 auto 0 auto; | ||
padding: 0; | ||
} | ||
|
||
#values li { | ||
display: inline; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
<div id="record-screen" class="screen"> | ||
<canvas id="levels" width=300 height=150></canvas> | ||
<ul id="values"> | ||
</ul> | ||
</div> | ||
<audio controls id="recorded-file"></audio> | ||
</body> | ||
</html> |
Oops, something went wrong.