KeenASR React Native Plugin (v2.2)
    Preparing search index...

    KeenASR React Native Plugin (v2.2)

    React Native plugin for KeenASR offline speech recognition SDK (iOS & Android).

    KeenASR is an offline speech recognition SDK for iOS and Android. For a general overview of SDK concepts, FAQ, and support, please see the KeenASR documentation. This React Native plugin provides a TypeScript API that wraps the native SDK, giving you on-device speech recognition without requiring a network connection.

    import KeenASR, { onFinalResponse } from 'keenasr-react-native';

    // 1. Initialize with an ASR bundle from app resources
    await KeenASR.initialize('keenA1m-nnet3chain-en-us');

    // 2. Create a decoding graph with expected phrases
    await KeenASR.createDecodingGraphFromPhrases('greetings', [
    'YES', 'NO', 'HELLO', 'GOODBYE',
    ]);

    // 3. Prepare the recognizer with the 'greetings' graph
    await KeenASR.prepareForListening('greetings');

    // 4. Subscribe to results
    const unsubscribe = onFinalResponse((response) => {
    console.log('Recognized:', response.asrResult.text);

    // do something with the response/result

    // Always release the response to free native resources
    response.release();
    });

    // 5. Start listening
    await KeenASR.startListening();

    An ASR bundle is a language-specific asset containing a pre-trained speech recognition model. The plugin ships with a default ASR bundle that is automatically included in your app at build time.

    To initialize with the bundled model, pass its name to initialize:

    await KeenASR.initialize('keenA1m-nnet3chain-en-us');
    

    To use a different ASR bundle:

    • iOS: Add the bundle directory to your Xcode project so it is included in the app's main bundle (drag it into Xcode and ensure "Copy items if needed" and your app target are selected).
    • Android: Place the bundle directory in android/app/src/main/assets/.

    Then pass its name to initialize. Alternatively, if the bundle is downloaded at runtime (e.g., to the app's documents directory), use initializeWithPath with the full filesystem path.

    A decoding graph defines what the recognizer can recognize. Create one from a list of phrases using createDecodingGraphFromPhrases or createContextualDecodingGraphFromPhrases. Graphs are persisted on the device filesystem and can be referenced by name and reused across sessions.

    The recognizer progresses through these states (see RecognizerState):

    1. NeedsDecodingGraph: initialized, but no decoding graph loaded
    2. ReadyToListen: decoding graph loaded, ready to start recognition
    3. Listening: actively capturing and decoding audio
    4. FinalProcessing: transient state while computing the final result

    Listening stops in one of three ways:

    • VAD threshold triggered, e.g., end-silence or max duration (delivers final response via onFinalResponse)
    • Audio interrupt, such as a phone call, notification, or app backgrounded (emits onAudioInterruptStarted)
    • Explicit stopListening call: stops audio capture but does not trigger onFinalResponse. To get the final result, set short VAD timeouts instead so the recognizer stops naturally

    Results are delivered through two event listeners:

    • onPartialResult: called repeatedly during recognition with intermediate text
    • onFinalResponse: called when recognition completes, with an ASRResponse containing the full result, per-word timing, phoneme-level detail, and audio quality metrics

    Each ASRResponse holds a reference to native resources. The caller owns the response and must call release() when done. Failing to release will leak native memory.

    const unsubscribe = onFinalResponse((response) => {
    // Use the response
    const text = response.asrResult.cleanText;

    // Save audio/JSON if needed
    await response.saveAudioFile('/path/to/dir');
    await response.saveJsonFile('/path/to/dir');

    // Or queue for Dashboard upload
    await response.queueForUpload();

    // Always release when done
    response.release();
    });

    VAD parameters control when the recognizer automatically stops listening. See VadParameter for all options.

    import { VadParameter } from 'keenasr-react-native';

    await KeenASR.setVADParameter(VadParameter.TimeoutForNoSpeech, 5.0);
    await KeenASR.setVADParameter(VadParameter.TimeoutEndSilenceForGoodMatch, 0.5);

    VAD parameters can be set at any time, including while the recognizer is listening. For more details, see Start and Stop Listening.

    When computeGoP is set to true in prepareForListening, the final result includes phoneme-level pronunciation scores (0–1) in each word's phones array. This is useful for pronunciation assessment applications. The ASR bundle must support GoP scoring.

    await KeenASR.prepareForListening('greetings', true); // computeGoP = true

    onFinalResponse((response) => {
    for (const word of response.asrResult.words) {
    if (word.phones) {
    for (const phone of word.phones) {
    console.log(`${phone.text}: ${phone.pronunciationScore}`);
    }
    }
    }
    response.release();
    });

    To upload recognition responses to the KeenASR Dashboard for analysis, start the uploader with startDataUploader and queue responses via queueForUpload():

    // Start the uploader once during app setup
    await KeenASR.startDataUploader('YOUR_APP_KEY');

    // Queue individual responses for upload
    onFinalResponse((response) => {
    response.queueForUpload();
    response.release();
    });
    Feature iOS Android
    Initialization Synchronous Asynchronous
    Status Implemented Pending

    For platform-specific details, see the native SDK introduction docs:

    To fully release the SDK and all resources:

    await KeenASR.teardown();
    

    After teardown, the SDK can be re-initialized by calling initialize again.