From 1fd6418628b33d4659fd3d740a6b0f219fad45c4 Mon Sep 17 00:00:00 2001 From: Patrick Gniza Date: Tue, 12 May 2026 19:35:28 +0200 Subject: [PATCH] Update Readme.md + Documentaion.md --- Documentation.md | 15 +++++++++------ README.md | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Documentation.md b/Documentation.md index a43761e..879d752 100644 --- a/Documentation.md +++ b/Documentation.md @@ -8,7 +8,7 @@ ## ```Module``` object | Function/Object | Description | |-|-| -| ```Promise createModel(url: string, path: string, id: string)```

```Promise createSpkModel(url: string, path: string, id: string)``` | Create a ```Model``` or ```SpkModel```, model files must be directly under the model root, and compressed model must be in ```.tar.gz```/```.tgz``` format. Tar format must be USTAR. If:
- ```path``` contains valid model files and ```id``` is the same, there will not be a fetch from ```url```.
- ```path``` doesn't contain valid model files, or if it contains valid model files but ```id``` is different, there will be a fetch from ```url```, and the model is stored with ```id```. Models are thread-safe and reusable across recognizers. | +| ```Promise createModel(url: string, path: string, id: string)```

```Promise createSpkModel(url: string, path: string, id: string)``` | Create a ```Model``` or ```SpkModel```, model files must be directly under the model root, and compressed model must be in ```.tar.gz```/```.tgz``` format. Tar format must be USTAR. If:
- ```path``` contains valid model files and ```id``` is the same, there will not be a fetch from ```url```.
- ```path``` doesn't contain valid model files, or if it contains valid model files but ```id``` is different, there will be a fetch from ```url```, and the model is stored with ```id```. Models are thread-safe and reusable across recognizers. Compressed `.tar.gz` models are automatically decompressed before caching. The browser cache stores validated uncompressed USTAR tar archives internally. Invalid cache entries are removed automatically. | | ```Promise createRecognizer(model: Model, sampleRate: float)```

```Promise createRecognizerWithSpkModel(model: Model, sampleRate: float, spkModel: spkModel)```

```Promise createRecognizerWithGrm(model: Model, grammar: string, sampleRate: float)``` | Create a ```Recognizer``` | | ```setLogLevel(lvl: int)``` | Set log level for Kaldi messages (default: ```0```: Info)
```-2```: Error
```-1```: Warning
```1```: Verbose
```2```: More verbose
```3```: Debug | | ```Promise createTransferer(ctx: AudioContext, bufferSize: int)``` | Create a node that transfer its inputs back to the main thread with custom buffer size (must be multiple of 128). Its port's ```onmessage``` handler can be set to get audio data. Has 1 input with 1 channel and no output. The the higher the size, the lesser the audio breaks up, but the higher the latency. Recomended value is around ```128 * 150```. | @@ -25,7 +25,9 @@ ## ```Recognizer``` object | Function/Object | Description | |-|-| -| ```acceptWaveform(audioData: Float32Array)``` | Enqueue an audio block for recognition as a ```Float32Array``` of numbers between ```-1.0``` and ```1.0``` | +| ```acceptWaveform(audioData: Float32Array): string``` | Processes an audio block and returns a JSON string containing either: +- a partial result (`{"partial":"..."}`) +- or a finalized result (`{"text":"..."}`) | | ```setWords(words: bool)``` | Enables words with times in the output (default: ```false```) | | ```setPartialWords(partialWords: bool)``` | Like above return words and confidences in partial results (default: ```false```) | | ```setNLSML(nlsml: bool)``` | Set NLSML output (default: ```false```) | @@ -36,10 +38,11 @@ | ```setEndpointerDelays(tStartMax: float, tEnd: float, tMax: float)``` | Set endpointer delays | | ```Promise delete(processCurrent: bool)``` | Delete the recognizer right after it processes its current block if ```processCurrent``` is ```true```; or after processing all remaining blocks if ```processCurrent``` is ```false``` (default: ```false```) | -| Event | Description | -|-|-| -| ```partialResult``` | Partial recognition result (stored in the event's ```detail``` property). This is fired while silence is not detected, ie. still speaking. Its words maybe updated and change in later ```partialResult```s until a ```result``` is fired. | -| ```result``` | Full, finalized recognition result (stored in the event's ```detail``` property). This is fired when silence is detected. Its words are finalized and won't ever change | +## Events (legacy / optional) + +The `partialResult` and `result` events are still available for compatibility, +but direct processing of the `acceptWaveform()` return value is recommended +for lower latency and simpler integration. --- # HTTP Remarks diff --git a/README.md b/README.md index 4725167..6146507 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,21 @@ let transferer = await module.createTransferer(ctx, 128 * 150); // Recognize data on arrival - transferer.port.onmessage = ev => recognizer.acceptWaveform(ev.data); + transferer.port.onmessage = ev => { + const raw = recognizer.acceptWaveform(ev.data); + + if (!raw) return; + + const msg = JSON.parse(raw); + + if (msg.partial) { + console.log("Partial:", msg.partial); + } + + if (msg.text) { + console.log("Result:", msg.text); + } + }; // Connect transferer to microphone micNode.connect(transferer);