asr-client-sdk
v0.1.0
Published
Zero-dependency client SDK for ASR WebSocket speech recognition.
Downloads
180
Maintainers
Readme
asr-client-sdk
Zero-dependency browser SDK for ASR WebSocket speech recognition.
This package wraps microphone capture, audio resampling, PCM streaming, recognition result normalization, state management, and resource cleanup for browser-based ASR integrations.
Install
npm install asr-client-sdkUsage
ESM
import { ASRClient } from 'asr-client-sdk'
const asr = new ASRClient({
wsUrl: 'wss://your-asr-server.example.com',
mode: '2pass',
onText(result) {
console.log(result.finalText + result.temporaryText)
},
onError(error) {
console.error(error.code, error.message, error.nativeError)
}
})
await asr.start()Browser Script
<script src="./asr-sdk.js"></script>
<script>
const asr = new window.ASR.ASRClient({
wsUrl: 'ws://127.0.0.1:10096',
mode: '2pass',
onText(result) {
console.log(result.finalText + result.temporaryText)
}
})
asr.start()
</script>API
new ASRClient(options?)
Creates a client instance.
connect(options?)
Opens the ASR WebSocket connection.
start(options?)
Starts microphone capture and streaming. If the socket is not connected yet, start() will connect first.
stop()
Stops recording and releases audio resources, but keeps the WebSocket connection alive.
destroy()
Stops recording, closes the WebSocket connection, and releases all resources.
setOptions(options)
Updates client options.
getState()
Returns the current client state: idle, connecting, connected, recording, closed, or error.
Import Targets
import { ASRClient } from 'asr-client-sdk'
import ASR from 'asr-client-sdk'
import { ASRClient } from 'asr-client-sdk/esm'UMD users can load asr-sdk.js and access window.ASR.
Environment Notes
- Browser-only SDK.
- Microphone access typically requires
localhostorhttps. - If your page uses
https, preferwssfor the ASR socket. - Browser permission prompts for microphone access cannot be bypassed.
Package Contents
asr-sdk.js: UMD buildasr-sdk.esm.mjs: ESM buildasr-sdk.d.ts: TypeScript declarations
Documentation
License
MIT
