@jskit-ai/assistant-voice-sherpa 0.1.136 → 0.1.138

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -211,13 +211,19 @@ model paths. Speaker IDs are specific to the selected model. Unknown IDs and
211
211
  invalid/duplicate catalogue entries fail explicitly. Voices do not change a
212
212
  conversation's reasoning model. Tail padding supplies recognizer lookahead when a
213
213
  recording ends immediately after a word; it does not wait for wall-clock silence.
214
- Its default is 0.45 seconds; an explicit value from 0 to 3 seconds overrides it.
214
+ Its default is 0.75 seconds, the least that keeps the last word when a recording
215
+ ends on it with the default pack (0.45 seconds dropped it: "the latest version"
216
+ was heard as "the latest vers"); an explicit value from 0 to 3 seconds overrides it.
215
217
  The RMS floor is disabled by default (`0`), preserving native silence handling
216
218
  and finalization. An explicit positive value up to 0.1 gates the initial input;
217
219
  `0.001` (−60 dBFS) is the opt-in example above. After onset, all frames reach the
218
220
  recognizer until the utterance ends. With a floor enabled, finalizing an utterance
219
221
  that never reached the floor returns no words without feeding native lookahead.
220
222
  This is an input-level check, not a classifier for speech versus noise.
223
+ Every sample fed to the recognizer, the lookahead included, gets noise of at
224
+ most one 16-bit step (a dither, from a fixed sequence, so the same recording
225
+ gives the same words): exact zeros, a muted microphone's digital silence, made
226
+ the default pack hear words that were never said.
221
227
 
222
228
  The synthesis worker has a separate 60-second operation watchdog for model load
223
229
  and generation. A timeout fails the operation and releases the worker process;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/assistant-voice-sherpa",
3
- "version": "0.1.136",
3
+ "version": "0.1.138",
4
4
  "type": "module",
5
5
  "description": "Optional native Sherpa speech engine and explicit model preparation for assistant voice.",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "tooling"
20
20
  ],
21
21
  "dependencies": {
22
- "@jskit-ai/assistant-voice": "0.2.89",
22
+ "@jskit-ai/assistant-voice": "0.2.91",
23
23
  "sherpa-onnx-node": "1.13.6"
24
24
  },
25
25
  "jskit": {
@@ -7,6 +7,25 @@ import {
7
7
  /** A listener that does not follow the recognized words ignores them. */
8
8
  function ignoreRecognizedText() {}
9
9
 
10
+ // Digital silence, exact zeros (a muted microphone, finish()'s lookahead), is outside what the model learned from: on
11
+ // ten seconds of it the default pack's recognizer heard "And" and "I am". As Kaldi's dither does, every sample a session
12
+ // feeds the recognizer gets noise of at most one 16-bit step, from a fixed sequence, so the same input gives the same
13
+ // words.
14
+ const DITHER_STEP = 1 / 32768;
15
+
16
+ function createDither() {
17
+ let state = 0x9e3779b9;
18
+ return samples => {
19
+ for (let index = 0; index < samples.length; index += 1) {
20
+ state ^= state << 13;
21
+ state ^= state >>> 17;
22
+ state ^= state << 5;
23
+ samples[index] += ((state >>> 0) / 0xffffffff * 2 - 1) * DITHER_STEP;
24
+ }
25
+ return samples;
26
+ };
27
+ }
28
+
10
29
  function decodeAvailable(recognizer, stream, vocabulary) {
11
30
  while (recognizer.isReady(stream)) {
12
31
  recognizer.decode(stream);
@@ -29,12 +48,13 @@ function decodeAvailable(recognizer, stream, vocabulary) {
29
48
  function createRecognitionSession(recognizer, {
30
49
  vocabulary = {},
31
50
  minimumRms = 0,
32
- tailPaddingSeconds = 0.45,
51
+ tailPaddingSeconds = 0.75,
33
52
  onPartial = ignoreRecognizedText,
34
53
  onEndpoint = ignoreRecognizedText,
35
54
  continuous = false
36
55
  } = {}) {
37
56
  const stream = recognizer.createStream();
57
+ const dither = createDither();
38
58
  let acceptedSamples = 0;
39
59
  let closed = false;
40
60
  let latestText = "";
@@ -55,7 +75,7 @@ function createRecognitionSession(recognizer, {
55
75
  acceptedSamples += samples.length;
56
76
  stream.acceptWaveform({
57
77
  sampleRate: VOICE_INPUT_SAMPLE_RATE,
58
- samples
78
+ samples: dither(samples)
59
79
  });
60
80
  const text = decodeAvailable(recognizer, stream, vocabulary);
61
81
  if (text && text !== latestText) {
@@ -88,7 +108,7 @@ function createRecognitionSession(recognizer, {
88
108
  stream.acceptWaveform({
89
109
  sampleRate: VOICE_INPUT_SAMPLE_RATE,
90
110
  // Supply the model's lookahead when push-to-talk ends on the final word.
91
- samples: new Float32Array(Math.floor(VOICE_INPUT_SAMPLE_RATE * tailPaddingSeconds))
111
+ samples: dither(new Float32Array(Math.floor(VOICE_INPUT_SAMPLE_RATE * tailPaddingSeconds)))
92
112
  });
93
113
  stream.inputFinished();
94
114
  const finalText = decodeAvailable(recognizer, stream, vocabulary);
@@ -138,7 +138,7 @@ async function createSherpaSpeechEngine({
138
138
  return value;
139
139
  }
140
140
  configuration = modelPaths(configuration);
141
- const tailPaddingSeconds = configuration.recognizerTailPaddingSeconds ?? 0.45;
141
+ const tailPaddingSeconds = configuration.recognizerTailPaddingSeconds ?? 0.75;
142
142
  if (!Number.isFinite(tailPaddingSeconds) || tailPaddingSeconds < 0 || tailPaddingSeconds > 3) {
143
143
  throw new TypeError("Recognizer tail padding must be between zero and three seconds.");
144
144
  }