Skip to content

[Python] Fix audio bindings and document the public audio API - #4954

Open
ZhuoenX wants to merge 2 commits into
alibaba:masterfrom
ZhuoenX:feature/add-audio-example
Open

ZhuoenX wants to merge 2 commits into
alibaba:masterfrom
ZhuoenX:feature/add-audio-example

Conversation

@ZhuoenX

@ZhuoenX ZhuoenX commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

The public audio wrappers supply all optional arguments to the native extension, but the spectrogram, mel_spectrogram, and melscale_fbanks parsing formats do not match those arguments. Correct the formats and parse boolean arguments into int temporaries before assigning bool fields, preventing adjacent-field corruption. Also fix hanning_window to call the registered native hann_window function.

Document the public Python API, its keyword support, real window constants, WAV I/O, and current spectral-feature behavior. Add a runnable WAV feature-extraction demo with optional output saving and explicit failures.

Validation on macOS arm64/Python 3.9.6:

  • Eight compiled parser regression checks covering defaults, all arguments, and independent boolean fields.
  • Rebuilt MNN and the actual _mnncengine extension from this branch; ran WAV loading/saving, spectrogram, mel, fbank, and Whisper features successfully.
  • Two numerical checks covering center padding, normalization, and nondefault mel options against an explicit filter-bank projection.
  • Python 3.8 grammar, local documentation links, git diff whitespace, and changed-line C++ formatting checks pass.

Older packages with the affected bindings need a build containing these fixes. The existing sampe_rate keyword remains unchanged for compatibility.

@CLAassistant

CLAassistant commented Oct 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

- Add audio_demo.py with corrected API calls (all positional parameters)
- Add complete audio.md API documentation
- Fix: Remove MNN.numpy import (module does not exist)
- Fix: Use positional parameters for all audio functions (METH_VARARGS)
- Fix: Correct function names (hann_window not hanning_window)
- Fix: mel_spectrogram limited to 4 int parameters due to binding bug
- Fix: Remove fake constants (audio.HANNING, window type enums)
- Fix: Correct all typos (sampe_rate -> sample_rate)
@ZhuoenX
ZhuoenX force-pushed the feature/add-audio-example branch from b62911a to bc11cf4 Compare October 11, 2026 17:46
@ZhuoenX ZhuoenX changed the title [Python] Add audio module example and complete documentation [Python] Fix audio bindings and document the public audio API Oct 11, 2026
@wangzhaode wangzhaode self-assigned this Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants