Documentation fix

This commit is contained in:
msqr1
2024-04-01 21:10:20 -07:00
parent 420f31b1d6
commit 9ac02167d2
6 changed files with 17 additions and 8 deletions

8
API.md
View File

@@ -12,7 +12,7 @@
## ```Module``` object
| Function/Object | Description |
|---|---|
| ```Promise<Model> createModel(path: string, url: string, id: string)```<br><br>```Promise<SpkModel> createSpkModel(path: string, url: string, id: string)``` | Create a ```Model``` or ```SpkModel```, model files must be directly under the model root, and compressed model must be in .tgz format. If:<br>- **path** contains valid model files and **id** is the same, there will not be a fetch from **url**.<br>- **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, reuse them as much as possible! |
| ```Promise<Model> createModel(url: string, path: string, id: string)```<br><br>```Promise<SpkModel> 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 .tgz format. If:<br>- **path** contains valid model files and **id** is the same, there will not be a fetch from **url**.<br>- **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, reuse them as much as possible! |
| ```Promise<Recognizer> createRecognizer(model: Model, sampleRate: float)```<br><br>```Promise<Recognizer> createRecognizerWithSpkModel(model: Model, spkModel: spkModel, sampleRate: float)```<br><br>```Promise<Recognizer> createRecognizerWithGrm(model: Model, grammar: string, sampleRate: float)``` | Create a ```Recognizer```, it will use **model**'s thread if it's the first user of **model**, else it will use a new thread. |
| ```setLogLevel(lvl: int)``` | Set Vosk's log level (default: ```0```: Info) <br>```-2```: Error<br>```-1```: Warning<br>```1```: Verbose<br>```2```: More verbose<br>```3```: Debug |
| ```Promise<AudioWorkletNode> 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 0 output. The the higher the size, the lesser the audio breaks up, but the higher the latency. Recomended value is around ```128 * 150```. |
@@ -46,16 +46,18 @@ Vosklet require SharedArrayBuffer to share threads' data, so these response head
If you can't set them, you may use a hacky workaround at *src/addCOI.js*.
# Compilation
- Requires ```autotools```'s commands in PATH
- Changing any option to non-default values requires recompilation
- To re-make a specific target, erase its directory in the repo root and run ```./make``` again
- To re-make a specific target, erase its directory in the repo root and run ```./make``` again. Doing this will also re-make the final JS
```
git clone --depth=1 https://github.com/msqr1/Vosklet &&
cd Vosklet/src &&
[Options] ./make
# Example: MAX_MEMORY=350mb MAX_THREADS=2 ./make
```
| Option | Description | Default value |
|---|---|---|
| MAX_MEMORY | Set max memory, valid suffixes: kb, mb, gb, tb or none (bytes) | ```375mb```, 300mb as [recommended](https://alphacephei.com/vosk/models) |
| MAX_MEMORY | Set max memory, valid suffixes: kb, mb, gb, tb or none (bytes) | ```300mb``` as [recommended](https://alphacephei.com/vosk/models) |
| MAX_THREADS | Set the max number of threads (>=1), this should be equal to the number of model or speaker model that is used in the program | ```1``` (1 recognizer, 1 model, 0 speaker model) |
| JOBS | Set the number of jobs (threads) when building | ```$(nproc)``` |
| EMSDK | Set EMSDK's path (will install EMSDK in root folder if unset) | ```../emsdk``` |

View File

@@ -2,6 +2,7 @@
- A speech recognizer built on Vosk that can be run on the browser, inspired by [vosk-browser](https://github.com/ccoreilly/vosk-browser), but built from scratch and no code taken!
- Designed with basic/nothrow exception safety
- See the *examples* folder for examples on using the API.
- See *API.md* for the API reference
- See the *devel* folder for the newest build (not guaranteed to work) and the JS build script
# Compared to vosk-browser
@@ -16,6 +17,7 @@
# Basic usage (microphone recognition)
- Result are logged to the console.
- Copied from *examples/fromMic.html*
```
<!DOCTYPE html>
<html>
@@ -52,9 +54,11 @@
transferer.port.onmessage = ev => {
recognizer.acceptWaveform(ev.data)
}
// Connect to microphone
micNode.connect(transferer)
}
</script>
<!-- Start and create audio context only as a result of user's action -->
<button onclick="start()">Start</button>
</head>
</html>

View File

@@ -1,7 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<script src="Vosklet.js" async defer></script>
<script src="https://cdn.jsdelivr.net/gh/msqr1/Vosklet@1.0.0/Vosklet.js" async defer></script>
<script>
async function start() {
// Make sure sample rate matches that in the training data
@@ -27,14 +26,17 @@
recognizer.addEventListener("partialResult", ev => {
console.log("Partial result: ", ev.detail)
})
// Create a transferer node to get audio data
// Create a transferer node to get audio data on the main thread
let transferer = await module.createTransferer(ctx, 128 * 150)
// Recognize data on arrival
transferer.port.onmessage = ev => {
recognizer.acceptWaveform(ev.data)
}
// Connect to microphone
micNode.connect(transferer)
}
</script>
<!-- Start and create audio context only as a result of user's action -->
<button onclick="start()">Start</button>
</head>
</html>

View File

@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="Vosklet.js" async defer></script>
<script src="https://cdn.jsdelivr.net/gh/msqr1/Vosklet@1.0.0/Vosklet.js" async defer></script>
<script>
async function start() {
// Make sure sample rate matches that in the training data
@@ -22,5 +22,6 @@
}
</script>
</head>
<!-- Start and create audio context only as a result of user's action -->
<button onclick="start()">Start</button>
</html>

View File

@@ -0,0 +1 @@
I have no idea how to do this. HELP!

View File

@@ -4,7 +4,6 @@ MAX_THREADS=${MAX_THREADS:-1}
EMSDK=${EMSDK:-../emsdk}
JOBS=${JOBS:-$(nproc)}
sudo apt install shtool libtool autogen autotools-dev pkg-config make &&
if [ $EMSDK != ../emsdk && ! -d $EMSDK ]; then
echo "Invalid emsdk path"
exit 1