Skip to main content

Hearken

Robust speech recognition pipeline for Python that prevents audio drops during transcription.

The Problem

In typical speech detection programs, audio capture is blocked during transcription. This causes dropped frames when network I/O is slow, resulting in missed speech.

The Solution

Hearken decouples capture, voice activity detection (VAD), and transcription into independent threads with queue-based communication. The capture thread never blocks, preventing audio loss even during slow transcription.

Installation

# Basic installation (includes EnergyVAD)
pip install hearken

# With speech_recognition support
pip install hearken[sr]

# With WebRTC VAD support
pip install hearken[webrtc]

# With Silero VAD support (neural network)
pip install hearken[silero]

# All optional dependencies
pip install hearken[all]

Quick Start

import speech_recognition as sr
from hearken import Listener, EnergyVAD
from hearken.adapters.sr import SpeechRecognitionSource, SRTranscriber

# Setup
recognizer = sr.Recognizer()
mic = sr.Microphone()

with mic as source:
    recognizer.adjust_for_ambient_noise(source)

# Create listener
listener = Listener(
    source=SpeechRecognitionSource(mic),
    transcriber=SRTranscriber(recognizer),
    on_transcript=lambda text, seg: print(f"You said: {text}")
)

# Run
listener.start()
try:
    listener.wait()
except KeyboardInterrupt:
    listener.stop()

Features

  • No dropped frames: Capture thread never blocks on downstream processing
  • Two modes: Passive (callbacks) and active (wait_for_speech())
  • Clean abstractions: Bring your own audio source and transcriber
  • Production-ready FSM: Robust 4-state detector filters false starts and handles pauses

Voice Activity Detection (VAD)

  • EnergyVAD: Simple energy-based detection with dynamic threshold calibration
  • WebRTCVAD: Google WebRTC VAD for improved accuracy in noisy environments
    • Requires sample rates: 8000, 16000, 32000, or 48000 Hz
    • Configurable aggressiveness (0-3)
    • Install with: pip install hearken[webrtc]
  • SileroVAD: Neural network-based VAD for superior accuracy
    • Requires 16kHz audio
    • Configurable sensitivity threshold
    • Automatic model download and caching
    • Install with: pip install hearken[silero]

Architecture

Microphone → [Capture Thread] → Queue → [Detect Thread] → Queue → [Transcribe Thread] → Callback
                   ↓                          ↓                         ↓
            AudioChunk (30ms)      SpeechSegment (complete)    Text transcription

Active Mode

listener = Listener(
    source=SpeechRecognitionSource(mic),
    transcriber=SRTranscriber(recognizer),
)

listener.start()

while True:
    print("Waiting for speech...")
    segment = listener.wait_for_speech()

    if segment:
        try:
            text = listener.transcriber.transcribe(segment)
            print(f"You said: {text}")
        except sr.UnknownValueError:
            print("Could not understand")

Documentation

See examples/ for more usage patterns.

Development

# Clone repository
git clone https://github.com/hipsterbrown/hearken.git
cd hearken

# Install with dev dependencies
uv sync --all-extras

# Run tests
pytest

# Run tests with coverage
pytest --cov=hearken --cov-report=term-missing

# Format code
black hearken/ tests/

# Type checking
mypy hearken/

# Linting
ruff check hearken/ tests/

Roadmap

  • ✅ v0.1: EnergyVAD, core pipeline
  • ✅ v0.2: WebRTC VAD support
  • ✅ v0.3: Silero VAD (neural network)
  • v0.4: Async transcriber support

License

Apache 2.0

Contributing

Contributions welcome! Please open an issue or PR on GitHub.

Credits

Created by Nick Hehr (@hipsterbrown)

Metadata

Release files for hearken 0.4.0

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

Source distribution (sdist)

Source distribution for hearken 0.4.0
File Size Uploaded Provenance Actions
hearken-0.4.0.tar.gz 138.9 kB With provenance Details for hearken-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hearken 0.4.0
File Interpreter ABI Platform Actions
hearken-0.4.0-py3-none-any.whl Python 3 none any Details for hearken-0.4.0-py3-none-any.whl

Total release size: 161.1 kB

Release files / hearken-0.4.0.tar.gz

Download URL hearken-0.4.0.tar.gz
Size 138.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4ce10306d974c1e63231e7444374ce99516e8ad663bc6142adbdddb3bd69f5e9
BLAKE2b-256 checksum
How to use checksums
4ab0d1a6dd78e2efc8f666ee9d9e31499b0403a9b26ac761112cbe0c678a0420
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 16, 2025.

Transparency log

Release files / hearken-0.4.0-py3-none-any.whl

Download URL hearken-0.4.0-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bb3c13b4aa78eb00a7dcbe89cd4ac6691d06cd8e5e77670e034546de5c8b621
BLAKE2b-256 checksum
How to use checksums
4dc72f2f3b8c193284731e1eee70fc2390e2ded651253d603afc7029743c217b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 16, 2025.

Transparency log

Security for hearken 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hearken-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 16, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files Full provenance

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