Skip to content

[JS] Implement ASRPipeline#4132

Draft
Retribution98 wants to merge 1 commit into
openvinotoolkit:masterfrom
Retribution98:js_asr_pipeline
Draft

[JS] Implement ASRPipeline#4132
Retribution98 wants to merge 1 commit into
openvinotoolkit:masterfrom
Retribution98:js_asr_pipeline

Conversation

@Retribution98

@Retribution98 Retribution98 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

Add Node.js (N-API) bindings for ov::genai::ASRPipeline, the automatic speech
recognition pipeline that dispatches to the concrete model implementation
(Whisper or Qwen3-ASR) based on the model's config.json.

What's included

  • Native wrapper (src/js/src/asr_pipeline/*, src/js/include/asr_pipeline/*):
    ASRPipelineWrapper (async init, threaded generate with optional streamer,
    getTokenizer, get/setGenerationConfig), ASRInitWorker, and
    ASRPerfMetricsWrapper.
  • TypeScript API (src/js/lib/pipelines/asrPipeline.ts + index.ts):
    ASRPipeline factory with generate(), stream() (async iterator),
    getTokenizer(), get/setGenerationConfig().
  • Types: ASRDecodedResults (texts, scores, detected languages, nested
    segment/word timestamps), ASRDecodedResultChunk, ASRPerfMetrics
    (features-extraction / word-timestamps / encode / decode durations),
    ASRGenerationConfig (Whisper + Qwen3-ASR context), ASRPipelineProperties.
  • Marshalling (src/js/src/helper.cpp, include/helper.hpp):
    cpp_to_js<ASRGenerationConfig>, to_asr_decoded_result, ASRPerfMetrics
    unwrap, and registration in addon.cpp / addon.hpp.
  • Sample (samples/js/automatic_speech_recognition/) with WAV decoding
    helper and README.
  • Docs: site/docs/bindings/node-js.md lists ASRPipeline.

Implementation notes

  • The audio buffer is moved once into AudioInputs to avoid an extra full-size
    copy from the implicit std::vector<float>std::variant conversion.
  • suppress_tokens / begin_suppress_tokens are marshalled as
    std::vector<int64_t>, so empty arrays (used to clear suppression) no longer
    throw during config conversion.

CVS-190146

Checklist:

  • This PR follows GenAI Contributing guidelines.
  • Tests have been updated or added to cover the new code.
    • Added src/js/tests/asrPipeline.test.js (creation, generate/stream,
      streamer, tokenizer, get/set generation config, segment/word timestamps,
      ASRPerfMetrics, empty suppress-token arrays). Whisper-specific features are
      validated against a Whisper model; a dedicated block validates Qwen3-ASR
      dispatch and its context option.
    • src/js/tests/setup.py adds the ASR_MODEL (tiny-random-qwen3-asr) test model.
    • tests/python_tests/samples/test_automatic_speech_recognition.py points to
      the new JS sample.
  • This PR fully addresses the ticket.
  • I have made corresponding changes to the documentation.

Signed-off-by: Kirill Suvorov <kirill.suvorov@intel.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Node.js (N-API + TypeScript) support for ov::genai::ASRPipeline, exposing a JS/TS ASRPipeline that dispatches to Whisper or Qwen3-ASR based on model config.json, including streaming, tokenizer access, generation config access, decoded-result marshalling, and ASR-specific performance metrics.

Changes:

  • Introduces native N-API wrappers for ASRPipeline + ASRPerfMetrics, plus JS/TS API, decoded results/types, and addon registration.
  • Adds JS sample for automatic speech recognition (WAV decoding helper + README) and updates Python sample test to run the new JS sample.
  • Adds JS tests covering creation, generate/stream, tokenizer, get/set generation config, timestamps, perf metrics, and Qwen3-ASR dispatch; adds a tiny-random Qwen3-ASR model to JS test setup.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/python_tests/samples/test_automatic_speech_recognition.py Switches JS sample invocation to the new ASR JS sample.
src/js/tests/setup.py Adds tiny-random Qwen3-ASR model download/conversion for JS tests.
src/js/tests/asrPipeline.test.js Adds ASRPipeline JS test coverage (Whisper + Qwen3-ASR dispatch).
src/js/src/helper.cpp Adds ASR config marshalling, decoded-result conversion, and ASR perf-metrics unwrap.
src/js/src/asr_pipeline/pipeline_wrapper.cpp Implements N-API wrapper for ASRPipeline (async init, threaded generate + streamer).
src/js/src/asr_pipeline/perf_metrics.cpp Implements N-API wrapper for ASRPerfMetrics with ASR-specific metrics accessors.
src/js/src/asr_pipeline/init_worker.cpp Adds async init worker creating ov::genai::ASRPipeline.
src/js/src/addon.cpp Registers ASRPipeline + ASRPerfMetrics in the addon module.
src/js/lib/utils.ts Adds ASRGenerationConfig and ASRPipelineProperties TS types.
src/js/lib/pipelines/asrPipeline.ts Adds TS ASRPipeline class + factory-facing API (generate, stream, config/tokenizer access).
src/js/lib/perfMetrics.ts Adds TS types/interfaces for ASR perf metrics and raw metrics.
src/js/lib/index.ts Exposes ASRPipeline + related decoded results and perf metrics from the public JS entrypoint.
src/js/lib/decodedResults.ts Adds ASRDecodedResults + timestamp chunk types.
src/js/lib/addon.ts Adds TS addon interface typing for native ASRPipeline binding.
src/js/include/helper.hpp Declares ASR perf-metrics unwrap and ASR decoded-result conversion helpers.
src/js/include/asr_pipeline/pipeline_wrapper.hpp Declares ASRPipeline N-API wrapper.
src/js/include/asr_pipeline/perf_metrics.hpp Declares ASRPerfMetrics N-API wrapper.
src/js/include/asr_pipeline/init_worker.hpp Declares ASRInitWorker.
src/js/include/addon.hpp Extends AddonData with ASR pipeline + perf metrics prototypes.
site/docs/bindings/node-js.md Documents ASRPipeline availability in Node.js bindings.
samples/js/automatic_speech_recognition/wav_utils.js Adds WAV PCM16 mono/stereo 16 kHz reader for sample.
samples/js/automatic_speech_recognition/README.md Adds documentation for the new JS ASR sample usage.
samples/js/automatic_speech_recognition/automatic_speech_recognition.js Adds runnable JS ASR sample using ASRPipeline + WAV helper.

Comment on lines +204 to +208
context->callback_tsfn =
Napi::ThreadSafeFunction::New(env, callback, "ASR_generate_callback", 0, 1, [context](Napi::Env) {
context->native_thread.join();
delete context;
});
Comment on lines +143 to +146
async return() {
streamingStatus = StreamingStatus.CANCEL;
return { done: true, value: "" };
},

## Prepare audio file

Prepare audio file in wav format with sampling rate 16k Hz.

:::warning API Coverage
Node.js bindings currently provide a subset of the full OpenVINO GenAI API available in C++ and Python. The focus is on core text generation (`LLMPipeline`), vision language models (`VLMPipeline`), text embedding (`TextEmbeddingPipeline`), text reranking (`TextRerankPipeline`), speech recognition (`WhisperPipeline`), speech generation (`Text2SpeechPipeline`), and image generation (`Text2ImagePipeline`, `Image2ImagePipeline`, `InpaintingPipeline`) functionality.
Node.js bindings currently provide a subset of the full OpenVINO GenAI API available in C++ and Python. The focus is on core text generation (`LLMPipeline`), vision language models (`VLMPipeline`), text embedding (`TextEmbeddingPipeline`), text reranking (`TextRerankPipeline`), speech recognition (`WhisperPipeline`, `ASRPipeline`), speech generation (`Text2SpeechPipeline`), and image generation (`Text2ImagePipeline`, `Image2ImagePipeline`, `InpaintingPipeline`) functionality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants