Skip to content

fix(asr)cache-aware streaming: mono audio and variables UnboundLocalError - #16167

Open
YCmove wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
YCmove:fix/single-audio-file-for-cache-aware-streaming-speech-to-text
Open

fix(asr)cache-aware streaming: mono audio and variables UnboundLocalError#16167
YCmove wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
YCmove:fix/single-audio-file-for-cache-aware-streaming-speech-to-text

Conversation

@YCmove

@YCmove YCmove commented Aug 29, 2026

Copy link
Copy Markdown

What does this PR do ?

  • Several variables are not properly initialized in the single-input audio case.
  • Stereo audio is not converted to mono, causing the downstream error.

Collection: asr

Changelog

  • Initialize variables correctly: all_streaming_tran, all_offline_tran, all_refs_text, and start_time
  • Add an error message when output_path is specified without dataset_manifest.
  • Always read audio_file in mono.

Usage

Feed the mono or stereo audio_file to examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py.

python speech_to_text_cache_aware_streaming_infer.py model_path={path to nemotron-3.5-asr-streaming-0.6b.nemo} audio_file={path to any mono or stereo audio in wav or flac} compare_vs_offline={true/flase} amp={true/flase} debug_mode={true/flase} target_lang={target language}

Test Environments: RTX 3090, CUDA Version: 13.2, Ubuntu 26.04, torch 2.12.0+cu132

Verification

Following tests are passed without warning:

uv run pytest tests/collections/asr/utils/test_streaming_utils.py
uv run pytest tests/collections/asr/test_preprocessing_segment.py
uv run pytest tests/collections/asr/inference/test_cache_aware_pipeline_builder.py

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

Trusted PRs run automatically through copy-pr-bot. For an untrusted PR, a maintainer can trigger CI by commenting
/ok to test <head-sha>; repeat this after a new push if the PR remains untrusted.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
  • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

Who can review?

@nithinraok or the previous author @artbataev
Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

None

@copy-pr-bot

copy-pr-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the ASR label Aug 29, 2026
@YCmove
YCmove force-pushed the fix/single-audio-file-for-cache-aware-streaming-speech-to-text branch from 62b1ba2 to 4ab8634 Compare August 29, 2026 13:59
samples = librosa.core.resample(samples, orig_sr=f.samplerate, target_sr=target_sr)
samples = samples.transpose()
return samples
return librosa.load(audio_file, sr=target_sr, mono=True, dtype=dtype)[0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

revert this, we used soundfile as its multiple times faster than librosa. What is the motivation for this change?

@YCmove YCmove Aug 31, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is more about the stereo audio not being handled correctly.

  1. librosa resamples the stereo audio in the wrong dimension
    resample takes input format as np.ndarray [shape=(n,) or shape=(2, n)], whereas soundfile reads stereo as a two-dimensional array in (n, 2). This works fine for mono because soundfile reads mono as a one-dimensional array (n,) by default.
    samples = samples.transpose() seems to be unnecessary, the transpose of (n,) is still (n,)

  2. This causes errors downstream in streaming_utils.py,

    1. audio_signal_len=2 instead of n
    2. incorrect format for audio_signal to pass into the preprocessor: (1, 2, n) instead of (batch, n)

I roll back to the original sf.SoundFile but add code to convert stereo to mono.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Aug 31, 2026
YCmove added 2 commits August 31, 2026 16:16
…hen single audio_file is used

Signed-off-by: yuc <y8765gd@gmail.com>
Signed-off-by: yuc <y8765gd@gmail.com>
@YCmove
YCmove force-pushed the fix/single-audio-file-for-cache-aware-streaming-speech-to-text branch from c448480 to f7f2aa9 Compare August 31, 2026 14:17
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants