Comments (12)
For future reference here is a repo containing example using multiple keywords https://github.com/miguelmota/pocketsphinxjs-multiple-keywords
from pocketsphinx.js.
You can package your file keyphrase.list
as explained in the docs (https://github.com/syl22-00/pocketsphinx.js#ii-package-model-files-outside-the-main-javascript), include the JavaScript file, and either load it in the recognizer at init time with -kws
in a config object, or at runtime. For runtime loading, you'll need to make a wrapper around ps_set_kws
(defined in ps_search.h
).
from pocketsphinx.js.
@syl22-00 Thanks for the tips. I'm still having trouble however, hoping you can help.
generating keyphrase-list.js
cd pocketsphinx.js
python ../emscripten/tools/file_packager.py ./pocketsphinx.js --embed keyphrase.list --js-output=keyphrase-list.js
outputs keyphrase-list.js
var Module;
if (typeof Module === 'undefined') Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()');
if (!Module.expectedDataFileDownloads) {
Module.expectedDataFileDownloads = 0;
Module.finishedDataFileDownloads = 0;
}
Module.expectedDataFileDownloads++;
(function() {
var loadPackage = function(metadata) {
function runWithFS() {
function assert(check, msg) {
if (!check) throw msg + new Error().stack;
}
fileData0 = [];
fileData0.push.apply(fileData0, [111, 104, 32, 109, 105, 103, 104, 116, 121, 32, 99, 111, 109, 112, 117, 116, 101, 114, 32, 47, 49, 101, 45, 52, 48, 47, 10, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 47, 49, 101, 45, 51, 48, 47, 10, 111, 116, 104, 101, 114, 32, 112, 104, 114, 97, 115, 101, 32, 47, 49, 101, 45, 50, 48, 47]);
Module['FS_createDataFile']('/', 'keyphrase.list', fileData0, true, true);
}
if (Module['calledRun']) {
runWithFS();
} else {
if (!Module['preRun']) Module['preRun'] = [];
Module["preRun"].push(runWithFS); // FS is not initialized yet, wait for it
}
}
loadPackage();
})();
index.html
script order
<script src="audioRecorder.js"></script>
<script src="callbackManager.js"></script>
<script src="keyphrase-list.js"></script>
<script src="main.js"></script>
main.js
// code
postRecognizerJob({
command: 'initialize',
data: [
['-kws', 'keyphrase-list.js'] // what path do I put here?
]
}, initCallback);
// code
browser console log errors
pocketsphinx.js:1 ERROR: "kws_search.c", line 354: Failed to open keyword file 'keyphrase-list.js': No such file or directory
pocketsphinx.js:1 ERROR: "kws_search.c", line 427: Failed to create kws search
full browser console logs
INFO: pocketsphinx.c(145): Parsed model-specific feature parameters from rm1_200/feat.params
pocketsphinx.js:1 Current configuration:
pocketsphinx.js:1 [NAME] [DEFLT] [VALUE]
pocketsphinx.js:1 -agc none none
pocketsphinx.js:1 -agcthresh 2.0 2.000000e+00
pocketsphinx.js:1 -allphone
pocketsphinx.js:1 -allphone_ci no no
pocketsphinx.js:1 -alpha 0.97 9.700000e-01
pocketsphinx.js:1 -ascale 20.0 2.000000e+01
pocketsphinx.js:1 -aw 1 1
pocketsphinx.js:1 -backtrace no no
pocketsphinx.js:1 -beam 1e-48 1.000000e-48
pocketsphinx.js:1 -bestpath yes yes
pocketsphinx.js:1 -bestpathlw 9.5 9.500000e+00
pocketsphinx.js:1 -ceplen 13 13
pocketsphinx.js:1 -cmn current current
pocketsphinx.js:1 -cmninit 8.0 8.0
pocketsphinx.js:1 -compallsen no no
pocketsphinx.js:1 -debug 0
pocketsphinx.js:1 -dict
pocketsphinx.js:1 -dictcase no no
pocketsphinx.js:1 -dither no no
pocketsphinx.js:1 -doublebw no no
pocketsphinx.js:1 -ds 1 1
pocketsphinx.js:1 -fdict rm1_200/noisedict
pocketsphinx.js:1 -feat 1s_c_d_dd s2_4x
pocketsphinx.js:1 -featparams rm1_200/feat.params
pocketsphinx.js:1 -fillprob 1e-8 1.000000e-08
pocketsphinx.js:1 -frate 100 100
pocketsphinx.js:1 -fsg
pocketsphinx.js:1 -fsgusealtpron yes yes
pocketsphinx.js:1 -fsgusefiller yes yes
pocketsphinx.js:1 -fwdflat yes yes
pocketsphinx.js:1 -fwdflatbeam 1e-64 1.000000e-64
pocketsphinx.js:1 -fwdflatefwid 4 4
pocketsphinx.js:1 -fwdflatlw 8.5 8.500000e+00
pocketsphinx.js:1 -fwdflatsfwin 25 25
pocketsphinx.js:1 -fwdflatwbeam 7e-29 7.000000e-29
pocketsphinx.js:1 -fwdtree yes yes
pocketsphinx.js:1 -hmm rm1_200
pocketsphinx.js:1 -input_endian little little
pocketsphinx.js:1 -jsgf
pocketsphinx.js:1 -keyphrase
pocketsphinx.js:1 -kws keyphrase-list.js
pocketsphinx.js:1 -kws_delay 10 10
pocketsphinx.js:1 -kws_plp 1e-1 1.000000e-01
pocketsphinx.js:1 -kws_threshold 1 2.000000e+00
pocketsphinx.js:1 -latsize 5000 5000
pocketsphinx.js:1 -lda
pocketsphinx.js:1 -ldadim 0 0
pocketsphinx.js:1 -lifter 0 0
pocketsphinx.js:1 -lm
pocketsphinx.js:1 -lmctl
pocketsphinx.js:1 -lmname
pocketsphinx.js:1 -logbase 1.0001 1.000100e+00
pocketsphinx.js:1 -logfn
pocketsphinx.js:1 -logspec no no
pocketsphinx.js:1 -lowerf 133.33334 1.333334e+02
pocketsphinx.js:1 -lpbeam 1e-40 1.000000e-40
pocketsphinx.js:1 -lponlybeam 7e-29 7.000000e-29
pocketsphinx.js:1 -lw 6.5 6.500000e+00
pocketsphinx.js:1 -maxhmmpf 30000 30000
pocketsphinx.js:1 -maxwpf -1 -1
pocketsphinx.js:1 -mdef rm1_200/mdef
pocketsphinx.js:1 -mean rm1_200/means
pocketsphinx.js:1 -mfclogdir
pocketsphinx.js:1 -min_endfr 0 0
pocketsphinx.js:1 -mixw
pocketsphinx.js:1 -mixwfloor 0.0000001 1.000000e-07
pocketsphinx.js:1 -mllr
pocketsphinx.js:1 -mmap yes yes
pocketsphinx.js:1 -ncep 13 13
pocketsphinx.js:1 -nfft 512 512
pocketsphinx.js:1 -nfilt 40 40
pocketsphinx.js:1 -nwpen 1.0 1.000000e+00
pocketsphinx.js:1 -pbeam 1e-48 1.000000e-48
pocketsphinx.js:1 -pip 1.0 1.000000e+00
pocketsphinx.js:1 -pl_beam 1e-10 1.000000e-10
pocketsphinx.js:1 -pl_pbeam 1e-10 1.000000e-10
pocketsphinx.js:1 -pl_pip 1.0 1.000000e+00
pocketsphinx.js:1 -pl_weight 3.0 3.000000e+00
pocketsphinx.js:1 -pl_window 5 5
pocketsphinx.js:1 -rawlogdir
pocketsphinx.js:1 -remove_dc no no
pocketsphinx.js:1 -remove_noise yes no
pocketsphinx.js:1 -remove_silence yes no
pocketsphinx.js:1 -round_filters yes yes
pocketsphinx.js:1 -samprate 16000 1.600000e+04
pocketsphinx.js:1 -seed -1 -1
pocketsphinx.js:1 -sendump rm1_200/sendump
pocketsphinx.js:1 -senlogdir
pocketsphinx.js:1 -senmgau
pocketsphinx.js:1 -silprob 0.005 5.000000e-03
pocketsphinx.js:1 -smoothspec no no
pocketsphinx.js:1 -svspec
pocketsphinx.js:1 -tmat rm1_200/transition_matrices
pocketsphinx.js:1 -tmatfloor 0.0001 1.000000e-04
pocketsphinx.js:1 -topn 4 4
pocketsphinx.js:1 -topn_beam 0 0
pocketsphinx.js:1 -toprule
pocketsphinx.js:1 -transform legacy legacy
pocketsphinx.js:1 -unit_area yes yes
pocketsphinx.js:1 -upperf 6855.4976 6.855498e+03
pocketsphinx.js:1 -uw 1.0 1.000000e+00
pocketsphinx.js:1 -vad_postspeech 50 50
pocketsphinx.js:1 -vad_prespeech 20 20
pocketsphinx.js:1 -vad_startspeech 10 10
pocketsphinx.js:1 -vad_threshold 2.0 2.000000e+00
pocketsphinx.js:1 -var rm1_200/variances
pocketsphinx.js:1 -varfloor 0.0001 1.000000e-04
pocketsphinx.js:1 -varnorm no no
pocketsphinx.js:1 -verbose no no
pocketsphinx.js:1 -warp_params
pocketsphinx.js:1 -warp_type inverse_linear inverse_linear
pocketsphinx.js:1 -wbeam 7e-29 7.000000e-29
pocketsphinx.js:1 -wip 0.65 6.500000e-01
pocketsphinx.js:1 -wlen 0.025625 2.562500e-02
pocketsphinx.js:1
pocketsphinx.js:1 INFO: feat.c(715): Initializing feature stream to type: 's2_4x', ceplen=13, CMN='current', VARNORM='no', AGC='none'
pocketsphinx.js:1 INFO: cmn.c(143): mean[0]= 12.00, mean[1..12]= 0.0
pocketsphinx.js:1 INFO: mdef.c(518): Reading model definition: rm1_200/mdef
pocketsphinx.js:1 INFO: mdef.c(531): Found byte-order mark BMDF, assuming this is a binary mdef file
pocketsphinx.js:1 INFO: bin_mdef.c(336): Reading binary model definition: rm1_200/mdef
pocketsphinx.js:1 INFO: bin_mdef.c(516): 45 CI-phone, 30080 CD-phone, 3 emitstate/phone, 135 CI-sen, 335 Sen, 199 Sen-Seq
pocketsphinx.js:1 INFO: tmat.c(206): Reading HMM transition probability matrices: rm1_200/transition_matrices
pocketsphinx.js:1 INFO: acmod.c(117): Attempting to use PTM computation module
pocketsphinx.js:1 INFO: ms_gauden.c(198): Reading mixture gaussian parameter: rm1_200/means
pocketsphinx.js:1 INFO: ms_gauden.c(292): 1 codebook, 4 feature, size:
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x12
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x24
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x3
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x12
pocketsphinx.js:1 INFO: ms_gauden.c(198): Reading mixture gaussian parameter: rm1_200/variances
pocketsphinx.js:1 INFO: ms_gauden.c(292): 1 codebook, 4 feature, size:
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x12
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x24
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x3
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x12
pocketsphinx.js:1 INFO: ms_gauden.c(354): 0 variance values floored
pocketsphinx.js:1 INFO: ptm_mgau.c(805): Number of codebooks doesn't match number of ciphones, doesn't look like PTM: 1 != 45
pocketsphinx.js:1 INFO: acmod.c(119): Attempting to use semi-continuous computation module
pocketsphinx.js:1 INFO: ms_gauden.c(198): Reading mixture gaussian parameter: rm1_200/means
pocketsphinx.js:1 INFO: ms_gauden.c(292): 1 codebook, 4 feature, size:
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x12
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x24
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x3
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x12
pocketsphinx.js:1 INFO: ms_gauden.c(198): Reading mixture gaussian parameter: rm1_200/variances
pocketsphinx.js:1 INFO: ms_gauden.c(292): 1 codebook, 4 feature, size:
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x12
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x24
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x3
pocketsphinx.js:1 INFO: ms_gauden.c(294): 256x12
pocketsphinx.js:1 INFO: ms_gauden.c(354): 0 variance values floored
pocketsphinx.js:1 INFO: s2_semi_mgau.c(904): Loading senones from dump file rm1_200/sendump
pocketsphinx.js:1 INFO: s2_semi_mgau.c(928): BEGIN FILE FORMAT DESCRIPTION
pocketsphinx.js:1 INFO: s2_semi_mgau.c(991): Rows: 256, Columns: 335
pocketsphinx.js:1 INFO: s2_semi_mgau.c(1023): Using memory-mapped I/O for senones
pocketsphinx.js:1 INFO: s2_semi_mgau.c(1294): Maximum top-N: 4 Top-N beams: 0 0 0 0
pocketsphinx.js:1 INFO: phone_loop_search.c(114): State beam -225 Phone exit beam -225 Insertion penalty 0
pocketsphinx.js:1 INFO: dict.c(320): Allocating 4099 * 20 bytes (80 KiB) for word entries
pocketsphinx.js:1 INFO: dict.c(358): Reading filler dictionary: rm1_200/noisedict
pocketsphinx.js:1 INFO: dict.c(213): Allocated 0 KiB for strings, 0 KiB for phones
pocketsphinx.js:1 INFO: dict.c(361): 3 words read
pocketsphinx.js:1 INFO: dict2pid.c(396): Building PID tables for dictionary
pocketsphinx.js:1 INFO: dict2pid.c(406): Allocating 45^3 * 2 bytes (177 KiB) for word-initial triphones
pocketsphinx.js:1 INFO: dict2pid.c(132): Allocated 24480 bytes (23 KiB) for word-final triphones
pocketsphinx.js:1 INFO: dict2pid.c(196): Allocated 24480 bytes (23 KiB) for single-phone word triphones
pocketsphinx.js:1 INFO: kws_search.c(423): KWS(beam: -1080, plp: -23, default threshold 6, delay 10)
pocketsphinx.js:1 ERROR: "kws_search.c", line 354: Failed to open keyword file 'keyphrase-list.js': No such file or directory
pocketsphinx.js:1 ERROR: "kws_search.c", line 427: Failed to create kws search
main.js:79 Audio recorder ready
from pocketsphinx.js.
Also looks like runWithFS
is never called
from pocketsphinx.js.
If you use recognizer.js
, pocketsphinx.js will be loaded in a web worker, so any additional file needs to be loaded in that worker. So instead of loading your generated js file directly in the html, you should load it in the worker, using the convenience function we provide, see docs:
https://github.com/syl22-00/pocketsphinx.js/#h-loading-files-such-as-acoustic-models-packaged-outside-pocketsphinxjs
Otherwise you seem to be doing right. Another thing you might be forgetting though is the dictionary. If you use the provided pocketsphinx.js
, it include an acoustic model but no dictionary, you can either recompile it with an embedded dictionary or generate and load it just as you do for your keyphrase-list
file.
from pocketsphinx.js.
@syl22-00 that did the trick, thank you.
from pocketsphinx.js.
@miguelmota
So, did you ever get multiple key phrases working with pocketsphinx.js? If so, could you provide the code you used to achieve it?
Thanks,
Mr. Villmer
from pocketsphinx.js.
I'm trying to modify the live_kws.html file to load multiple keyphrases. So far, no success...
Here is what I've done so far:
- Created keyphrase.list file:
oh mighty computer /1e-40/
hello world /1e-30/
other phrase /1e-20/ - Created keyphrase-list.js file using the Pythod script:
var Module;
if (typeof Module === 'undefined') Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()');
if (!Module.expectedDataFileDownloads) {
Module.expectedDataFileDownloads = 0;
Module.finishedDataFileDownloads = 0;}
Module.expectedDataFileDownloads++;
(function() {
var loadPackage = function(metadata) {
function runWithFS() {
function assert(check, msg) {
if (!check) throw msg + new Error().stack; }
var fileData0 = [];
fileData0.push.apply(fileData0, [111, 104, 32, 109, 105, 103, 104, 116, 121, 32, 99, 111, 109, 112, 117, 116, 101, 114, 32, 47, 49, 101, 45, 52, 48, 47, 10, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 47, 49, 101, 45, 51, 48, 47, 10, 111, 116, 104, 101, 114, 32, 112, 104, 114, 97, 115, 101, 32, 47, 49, 101, 45, 50, 48, 47]);
Module['FS_createDataFile']('/', 'keyphrase.list', fileData0, true, true); }
if (Module['calledRun']) {
runWithFS(); } else {
if (!Module['preRun']) Module['preRun'] = [];
Module["preRun"].push(runWithFS); // FS is not initialized yet, wait for it } }
loadPackage({"files": []});
})();
from pocketsphinx.js.
-
Changed the initRecognizer function in my html file.
The console reads..
initialize √
keyphrase √ERROR: "pocketsphinx.c", line 968: No search module is selected, did you forget to specify a language model or grammar?
var initRecognizer = function() {
// You can pass parameters to the recognizer, such as : {command: 'initialize', data: [["-hmm", "my_model"], ["-fwdflat", "no"]]}
postRecognizerJob({command: 'initialize', data: []},
function() {
console.log('initialize √')
postRecognizerJob({command: 'load',
callbackId: 0,
data: ["keyphrase-list.js"]},
function(){
console.log('keyphrase √')
if (recorder) recorder.consumers = [recognizer];
// feedWords(wordList);
recognizerReady();
});
});};
from pocketsphinx.js.
You need to give as argument to the recognizer your key phrase file:
postRecognizerJob({command: 'initialize', data: [["-kws", "keyphrase-list"]]},...
Also you need a dictionary file, as explained earlier.
from pocketsphinx.js.
Two quick questions:
- What does -DDICT_BASE refer to? Is this a folder containing something? What needs to be at this location?
- I'm on OSX and entering cmake in the Terminal windows does not work. I've downloaded the binary of CMake - but is there a way to install it via the terminal?
Here's what I've tried (without success)
cmake -DEMSCRIPTEN=1 -DCMAKE_TOOLCHAIN_FILE=emscripten/cmake/Modules/Platform/Emscripten.cmake -DDICT_BASE=./dicts -DDICT_FILES= keyphrase.dict
Miguel Mota (from this original post) has been trying to assist me but I've not had success yet. It's definitely not a simple, straightforward process just to get multi-key phrases to work.
Thanks again for taking the time to assist me with this. Highly appreciated.
V
from pocketsphinx.js.
- It's a CMake parameter you can use if you want to package a dictionary file inside the generated JavaScript, it's explained in the docs: https://github.com/syl22-00/pocketsphinx.js#i-embedding-the-files-into-one-large-javascript-file. Since you are packaging your key phrase file outside the main JavaScript, you might as well do the same with the dictionary. In your command you seem to have an extra space before "keyphrase.dict"
- This is not related to pocketsphinx.js. I guess I'd use MacPorts or Homebrew to install it.
from pocketsphinx.js.
Related Issues (20)
- lazyLoading, Module.FS_createPath not found (emscripten compilation without accoustic model) HOT 1
- some time when click on start i am getting Cannot change search while decoding, end utterance first HOT 1
- FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory HOT 2
- Words.push_back accept 1 arguments only HOT 1
- Trying to build but submodules fail HOT 2
- BindingError with self-compiled pocketsphinx.js HOT 2
- Change threshold to increase accuracy detection HOT 2
- in web form asp.net? HOT 2
- Can't install with npm HOT 1
- Webapp.js file is missing HOT 1
- Buffer in recognizer uses obsolete data on multiple "process"-requests
- issue with make
- Web Worker Lazy Load Command - Outgoing Message is Empty HOT 1
- Compilation Failed In Custom Acoustic Model
- Grammar for numbers? HOT 5
- Pocketsphinx within web worker
- live.html demo no longer works in Chrome, only Firefox
- Compilation into WebAssembly fails HOT 1
- Sorry if I laugh HOT 1
- Local host not working with chrome
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pocketsphinx.js.