@@ -148,33 +148,29 @@ Now you can load it and recognize it with:
148148``` js
149149let audio = await fs .readFile (" goforward.raw" );
150150decoder .start ();
151- decoder .process (audio, false , true );
151+ decoder .process_audio (audio, false , true );
152152decoder .stop ();
153153```
154154
155- The results can be obtained with ` get_hyp() ` or in a more detailed
156- format with time alignments using ` get_hypseg() ` . These are not
157- asynchronous methods, as they do not depend on or change the state of
158- the decoder:
155+ The text result can be obtained with ` get_text() ` or in a more detailed format
156+ with time alignments using ` get_alignment() ` . These are not asynchronous
157+ methods, as they do not depend on or change the state of the decoder:
159158
160159``` js
161- console .log (decoder .get_hyp ());
162- console .log (decoder .get_hypseg ());
160+ console .log (decoder .get_text ());
161+ console .log (decoder .get_alignment ());
163162```
164163
165- If you want even more detailed segmentation (phone and HMM state
166- level) you can use ` get_alignment_json ` . For more detail on this
167- format, see [ the PocketSphinx
168- documentation] ( https://github.com/cmusphinx/pocketsphinx#usage ) as it
169- is borrowed from there. Since this is JSON, you can create an object
170- from it and iterate over it:
164+ For more detail on the alignment format, see [ the PocketSphinx
165+ documentation] ( https://github.com/cmusphinx/pocketsphinx#usage ) as it is
166+ borrowed from there. For example:
171167
172168``` js
173- const result = JSON . parse ( decoder .get_alignment_json () );
174- for (const word of result .w ) {
175- console .log (` word ${ word . t } at ${ word . b } has duration ${ word . d } ` );
176- for (const phone of word . w ) {
177- console .log (` phone ${ phone . t } at ${ phone . b } has duration ${ phone . d } ` );
169+ const result = decoder .get_alignment_json ({ align_level : 1 } );
170+ for (const { w , t , b , d } of result .w ) {
171+ console .log (` word ${ t} at ${ b} has duration ${ d } and probability ${ p } ` );
172+ for (const { t , b , d } of w) {
173+ console .log (` phone ${ t} at ${ b} has duration ${ d} ` );
178174 }
179175}
180176```
@@ -224,7 +220,7 @@ from a JavaScript string and set it in the decoder like this (a
224220hypothetical pizza-ordering grammar):
225221
226222``` js
227- decoder .set_jsgf (` #JSGF V1.0;
223+ decoder .set_grammar (` #JSGF V1.0;
228224grammar pizza;
229225public <order> = [<greeting>] [<want>] [<quantity>] [<size>] [pizza] <toppings>;
230226<greeting> = hi | hello | yo | howdy;
@@ -261,6 +257,7 @@ from [the
261257documentation] ( https://soundswallower.readthedocs.io/en/latest/soundswallower.js.html#Endpointer.get_in_speech ) :
262258
263259``` js
260+ const ep = new Endpointer ({ samprate: decoder .get_config (" samprate" } });
264261let prev_in_speech = ep .get_in_speech ();
265262let frame_size = ep .get_frame_size ();
266263// Presume `frame` is a Float32Array of frame_size or less
0 commit comments