Skip to content

Commit e8ee7c7

Browse files
committed
docs: fix for new API
1 parent 8fe7489 commit e8ee7c7

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

docs/source/soundswallower.js.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ Now run this with ``node``:
115115
// Start speech processing
116116
decoder.start();
117117
// Takes a typed array, as returned by readFile
118-
decoder.process(pcm);
118+
decoder.process_audio(pcm);
119119
// Finalize speech processing
120120
decoder.stop();
121121
// Get recognized text (NOTE: synchronous method)
122-
console.log(decoder.get_hyp());
122+
console.log(decoder.get_text());
123123
// We must manually release memory...
124124
decoder.delete();
125125
})();

js/README.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,33 +148,29 @@ Now you can load it and recognize it with:
148148
```js
149149
let audio = await fs.readFile("goforward.raw");
150150
decoder.start();
151-
decoder.process(audio, false, true);
151+
decoder.process_audio(audio, false, true);
152152
decoder.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
224220
hypothetical pizza-ordering grammar):
225221

226222
```js
227-
decoder.set_jsgf(`#JSGF V1.0;
223+
decoder.set_grammar(`#JSGF V1.0;
228224
grammar pizza;
229225
public <order> = [<greeting>] [<want>] [<quantity>] [<size>] [pizza] <toppings>;
230226
<greeting> = hi | hello | yo | howdy;
@@ -261,6 +257,7 @@ from [the
261257
documentation](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"} });
264261
let prev_in_speech = ep.get_in_speech();
265262
let frame_size = ep.get_frame_size();
266263
// Presume `frame` is a Float32Array of frame_size or less

0 commit comments

Comments
 (0)