Skip to main content

speechgate-rs

Rust implementation of the FASR energy speech gate with Python bindings.

Install

Install the package from PyPI after a release is published:

pip install speechgate-rs

Install the latest version directly from GitHub:

pip install "git+https://github.com/di-osc/speechgate-rs.git"

For local development, install an editable release build with maturin:

uv sync
env -u CONDA_PREFIX VIRTUAL_ENV=.venv maturin develop --release

Usage

import numpy as np
from speechgate_rs import EnergySpeechGate

audio = np.zeros(16000, dtype=np.float32)
gate = EnergySpeechGate(base_thresh=0.008, max_thresh=0.035)
mask = gate.compute_keep_mask(audio, sample_rate=16000)
gated = gate.apply_array(audio, sample_rate=16000)

For streaming audio, keep one stateful gate per stream:

from speechgate_rs import StreamingEnergySpeechGate

stream_gate = StreamingEnergySpeechGate(stream_context_ms=3000, fade_ms=5)
for chunk in chunks:
    gated_chunk = stream_gate.process_chunk(
        chunk,
        sample_rate=16000,
        is_last=False,
    )

For realtime services that process interleaved streams, use the multi-stream wrapper:

from speechgate_rs import MultiStreamEnergySpeechGate

gate = MultiStreamEnergySpeechGate()
gated_chunk = gate.process_chunk(
    "session-1",
    chunk,
    sample_rate=16000,
    is_last=False,
)

The binding keeps the same energy-gate semantics as the Python EnergySpeechGate implementation in fasr-service-realtime: adaptive RMS thresholding, short voice-burst removal, short silence-gap filling, padding, silence pass windows, streaming context, cross-chunk fade continuity, and fade envelopes.

Parameters

Parameter Default Suggested range Meaning Increase / decrease effect
enabled True True or False Enables the gate. When False, apply_array returns the input audio unchanged. Turn on to filter silence/noise; turn off to bypass the gate completely.
window_ms 10 5-30 ms Analysis window length. RMS energy is computed once per window. Larger is steadier but slower to react; smaller reacts faster but is more sensitive to clicks and short spikes.
base_thresh 0.008 0.001-0.03 RMS Minimum RMS threshold. The adaptive threshold will never go below this value. Larger rejects more quiet speech/noise; smaller keeps softer speech but may pass more background noise.
threshold_ratio 2.0 1.0-5.0 Multiplier applied to the estimated noise floor before clamping. Larger makes the gate stricter in noisy audio; smaller opens the gate more easily.
max_thresh 0.035 0.01-0.1 RMS Maximum RMS threshold. The adaptive threshold will never go above this value. Larger allows the adaptive threshold to become stricter in loud noise; smaller protects quieter speech from being rejected.
smooth_alpha 0.2 0.01-1.0 Exponential smoothing factor for per-window RMS values. Larger follows energy changes faster but may flicker; smaller is steadier but can lag at speech boundaries.
min_voice_windows 5 1-20 windows Minimum consecutive voice windows required to keep a speech region. Larger removes more short bursts but can drop very short words; smaller keeps brief sounds but may pass clicks.
attenuation 0.0 0.0-1.0 gain Gain applied to rejected audio. 0.0 fully mutes it. Larger keeps more background ambience; smaller makes rejected regions quieter.
noise_floor_percentile 20.0 1.0-50.0 Percentile of smoothed RMS values used as the adaptive noise floor estimate. Larger estimates a higher noise floor and becomes stricter; smaller estimates quieter background and opens more easily.
max_silence_gap_windows 8 0-30 windows Maximum silent gap to fill between two voice regions. Larger preserves pauses inside speech but may keep noise between phrases; smaller cuts internal pauses more aggressively.
fade_ms 5 0-50 ms Fade length when switching between kept and rejected audio. Larger makes transitions smoother but may smear boundaries; smaller is tighter but can click or sound abrupt.
stream_context_ms 3000 0-10000 ms Context duration used by streaming integrations to preserve recent audio history. Stateless array APIs keep it for config parity. Larger gives streaming code more history but uses more memory; smaller is lighter but has less context.
pad_voice_windows 2 0-20 windows Windows added before and after detected voice regions. Larger protects speech starts/ends but keeps more surrounding noise; smaller trims tighter but can clip onsets or offsets.
pass_windows 0 0-20 windows Non-voice windows kept after a voice region as a trailing hold. Larger makes streaming output less abrupt; smaller removes trailing silence sooner.

Verify

For performance-sensitive checks, build the native extension in release mode before running tests:

env -u CONDA_PREFIX VIRTUAL_ENV=.venv maturin develop --release
uv run pytest tests -q

The test suite includes a NumPy reference implementation and verifies that the Rust binding returns identical masks/gated output/compacted output while running faster than the NumPy reference on the benchmark audio.

Metadata

Release files for speechgate-rs 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for speechgate-rs 0.1.3
File Size Uploaded
speechgate_rs-0.1.3.tar.gz 34.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for speechgate-rs 0.1.3
File
speechgate_rs-0.1.3-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
speechgate_rs-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
speechgate_rs-0.1.3-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
speechgate_rs-0.1.3-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
speechgate_rs-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
speechgate_rs-0.1.3-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
speechgate_rs-0.1.3-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
speechgate_rs-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
speechgate_rs-0.1.3-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details

Total release size: 2.5 MB

Release files / speechgate_rs-0.1.3.tar.gz

Download URL speechgate_rs-0.1.3.tar.gz
Size 34.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e972672475d3d79130d2887cfa66d210d6fbd1f72ae5c46367ad3179ec22519e
BLAKE2b-256 checksum
How to use checksums
1a445847a6b48804af74ca7aa2ffe5c8f08984c580329745ec8a11fd982ca969
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / speechgate_rs-0.1.3-cp312-cp312-win_amd64.whl

Download URL speechgate_rs-0.1.3-cp312-cp312-win_amd64.whl
Size 184.8 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
d14858a017ba3a48f9b335cede9d0d9c146c2544b166bea0a3dc173bf42a5353
BLAKE2b-256 checksum
How to use checksums
4b2b029469205649939484b8daed58bad22ae261fee4843e26de5792fa6c8a0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / speechgate_rs-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL speechgate_rs-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 334.4 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c18a2e1c91b9dae9a18fd39cd9ffa28245e46c89fe080b4508c225cf9810ee85
BLAKE2b-256 checksum
How to use checksums
5d2fab95d3501c95f219d247a7d3f942fa16b8396cd08186dca68a0f1df3e973
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / speechgate_rs-0.1.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL speechgate_rs-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Size 292.7 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
92e11a234092be838bbf4fa68b9cba308b8a6a839059199f90be704c35c92938
BLAKE2b-256 checksum
How to use checksums
daf60f598778ae64b38f07058477000bd404e1f51753ba4ff320b0660907e34e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / speechgate_rs-0.1.3-cp311-cp311-win_amd64.whl

Download URL speechgate_rs-0.1.3-cp311-cp311-win_amd64.whl
Size 186.2 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
4e6f21e384978240807909d9e9e75a9ac72d78e605d12343eb543cee2b382acf
BLAKE2b-256 checksum
How to use checksums
b0a00676cc37d0ae6da1ae3b193fff9d27e03246c61b97ce96f1f8a085c976c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / speechgate_rs-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL speechgate_rs-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 337.3 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a717f14a536c7e430b1fa215d0b84649fc5e2d07d812c7f326bc1b4db82a7e44
BLAKE2b-256 checksum
How to use checksums
085f9c5fabff450d8c67aba760c7466b797e9b6c9af96e58ea2b235310ade6d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / speechgate_rs-0.1.3-cp311-cp311-macosx_11_0_arm64.whl

Download URL speechgate_rs-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Size 294.7 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e7a14f80ef5d87ce4df3896c07f91c69fc4a54d70d97196819e05a86e1445bf2
BLAKE2b-256 checksum
How to use checksums
471517c8a05a8f0641a487fcbd62d96047339595a35bfdebab8bdf5a247c7e53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / speechgate_rs-0.1.3-cp310-cp310-win_amd64.whl

Download URL speechgate_rs-0.1.3-cp310-cp310-win_amd64.whl
Size 186.0 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
52590eabbaf93732e0dae58e2b6e993a95044bac3c7ceb1c8fb0761efa96a002
BLAKE2b-256 checksum
How to use checksums
4adf55ecddbb90aa044541811133a6a54abafd74f6d2e9af18102f796449b3de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / speechgate_rs-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL speechgate_rs-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 337.4 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
0bee55ee2f4dc96938e9f4bc38030517c47ee295b272177d909043370ef56905
BLAKE2b-256 checksum
How to use checksums
6a00a56d2f7d9cb80dfda023e565a9bde0e599d594d45bca90d143ecfb1ec358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / speechgate_rs-0.1.3-cp310-cp310-macosx_11_0_arm64.whl

Download URL speechgate_rs-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Size 294.8 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
32922e9f837ef07ecc5453174824b06c0f9282627002f316b5e842dac47e301a
BLAKE2b-256 checksum
How to use checksums
9f57519b2e0c5169ba61d56c3c9f2813394da0d3b69c27b9b7e412cf5691df74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.1.3 This release

10 release files

0.1.2

10 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page