Metadata-Version: 2.4
Name: microasr
Version: 0.1.2
Summary: Offline streaming RNN-T real-time speech recognition using ONNX Runtime
Author: SwaggyMacro
Project-URL: Homepage, https://github.com/SwaggyMacro/MicroASR
Project-URL: Repository, https://github.com/SwaggyMacro/MicroASR
Project-URL: Issues, https://github.com/SwaggyMacro/MicroASR/issues
Keywords: asr,speech-recognition,offline,streaming,rnnt,onnx
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: numpy>=1.26
Requires-Dist: onnxruntime>=1.20
Provides-Extra: audio
Requires-Dist: soundcard>=0.4.3; extra == "audio"

# MicroASR for Python

[中文](README.zh-CN.md) | English

Offline streaming RNN-T speech recognition for Python using the same plain ONNX model packages as the .NET implementation. Input audio is mono signed 16-bit little-endian PCM at exactly 16 kHz.

Models are not included in the Python package. Applications supply a compatible plain ONNX model directory at runtime.

## Install

From PyPI:

```shell
python -m pip install microasr
```

For local development from the repository root:

```shell
python -m pip install -e ./sdk/python
```

NumPy and ONNX Runtime are required. Install the optional audio capture backend to use the `system` command:

```shell
python -m pip install -e "./sdk/python[audio]"
```

## Commands

Recognize a WAV file on Windows, Linux, or macOS:

```shell
microasr wav models/en-US sample.wav
```

Read headerless mono PCM16 from standard input:

```shell
ffmpeg -i sample.mp3 -ac 1 -ar 16000 -f s16le - | microasr pcm models/en-US
```

Capture the default system output when the operating system exposes a loopback or monitor source:

```shell
microasr system models/en-US
```

System capture uses SoundCard. Windows normally exposes WASAPI loopback. Linux requires a PulseAudio/PipeWire monitor source. macOS may require a virtual audio device such as BlackHole.

## Library usage

```python
from microasr import RecognitionEventType, RnntRecognitionMode, StreamingRecognizer


def on_result(event):
    if event.type is RecognitionEventType.FINAL:
        print(event.text)


with StreamingRecognizer("models/en-US", RnntRecognitionMode.BALANCED) as recognizer:
    recognizer.add_result_handler(on_result)
    recognizer.write(pcm_chunk)
```

`write()` processes one PCM chunk synchronously and returns any events produced by that chunk. `complete()` flushes an active utterance. Partial and final events also go to registered handlers.

## Decoder profiles and parameters

The Accuracy, Balanced, and Performance profiles match the .NET package. Accuracy uses a fixed beam of 7, Balanced uses adaptive widths of 7/6/5, and Performance uses 7/5/3. All decoder and streaming segmentation parameters are public. Start from a profile and use `dataclasses.replace` to override only the values required by the application. The repository [tuning table](../../README.md#recognition-modes-and-tuning) documents every field and its effect.
