Skip to main content

Voice control using Whisper.cpp with LangChain cleanup

Project description

Whisper Chain

Whisper Chain Logo

Overview

Typing is boring, let's use voice to speed up your workflow. This project combines:

  • Real-time speech recognition using Whisper.cpp
  • Transcription cleanup using LangChain
  • Global hotkey support for voice control
  • Automatic clipboard integration for the cleaned transcription

Requirements

  • Python 3.8+
  • OpenAI API Key
  • For MacOS:
    • ffmpeg (for audio processing)
    • portaudio (for audio capture)

Installation

  1. Install system dependencies (MacOS):
# Install ffmpeg and portaudio using Homebrew
brew install ffmpeg portaudio
  1. Install the project:
pip install whisperchain

Configuration

WhisperChain will look for configuration in the following locations:

  1. Environment variables
  2. .env file in the current directory
  3. ~/.whisperchain/.env file

On first run, if no configuration is found, you will be prompted to enter your OpenAI API key. The key will be saved in ~/.whisperchain/.env for future use.

You can also manually set your OpenAI API key in any of these ways:

# Option 1: Environment variable
export OPENAI_API_KEY=your-api-key-here

# Option 2: Create .env file in current directory
echo "OPENAI_API_KEY=your-api-key-here" > .env

# Option 3: Create global config
mkdir -p ~/.whisperchain
echo "OPENAI_API_KEY=your-api-key-here" > ~/.whisperchain/.env

Usage

  1. Start the application:
# Run with default settings
whisperchain

# Run with custom configuration
whisperchain --config config.json

# Override specific settings
whisperchain --port 8080 --hotkey "<ctrl>+<alt>+t" --model "large" --debug
  1. Use the global hotkey (<ctrl>+<alt>+r by default. <ctrl>+<option>+r on MacOS):
    • Press and hold to start recording
    • Speak your text
    • Release to stop recording
    • The cleaned transcription will be copied to your clipboard automatically
    • Paste (Ctrl+V) to paste the transcription

Development

Streamlit UI

streamlit run src/whisperchain/ui/streamlit_app.py

If there is an error in the Streamlit UI, you can run the following command to kill all running Streamlit processes:

lsof -ti :8501 | xargs kill -9

Running Tests

Install test dependencies:

pip install -e ".[test]"

Run tests:

pytest tests/

Run tests with microphone input:

# Run specific microphone test
TEST_WITH_MIC=1 pytest tests/test_stream_client.py -v -k test_stream_client_with_real_mic

# Run all tests including microphone test
TEST_WITH_MIC=1 pytest tests/

Building the project

python -m build
pip install .

Publishing to PyPI

python -m build
twine upload --repository pypi dist/*

License

LICENSE

Acknowledgments

Architecture

graph TB
    subgraph "Client Options"
        K[Key Listener]
        A[Audio Stream]
        C[Clipboard]
    end

    subgraph "Streamlit Web UI :8501"
        WebP[Prompt]
        WebH[History]
    end

    subgraph "FastAPI Server :8000"
        WS[WebSocket /stream]
        W[Whisper Model]
        LC[LangChain Processor]
        H[History]
    end

    K -->|"Hot Key"| A
    A -->|"Audio Stream"| WS
    WS --> W
    W --> LC
    WebP --> LC
    LC --> C
    LC --> H
    H --> WebH

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whisperchain-0.1.3.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whisperchain-0.1.3-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file whisperchain-0.1.3.tar.gz.

File metadata

  • Download URL: whisperchain-0.1.3.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for whisperchain-0.1.3.tar.gz
Algorithm Hash digest
SHA256 088ec97c71bbe93b9826efe2781d65754a5ef3932691e88526ba2c311f31048e
MD5 5cf31a0757ec3af6466a3664a23b730d
BLAKE2b-256 b1aa091fefc96ab72566824ebef37067ae462f219f78104965a97a9379c90d89

See more details on using hashes here.

File details

Details for the file whisperchain-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: whisperchain-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for whisperchain-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 91e607ea8cdf2143c9552acb322a8fc7b5cb3ab78f2c61bbc6d37653bff68e2d
MD5 90310768c632e7b3332185b15d47506d
BLAKE2b-256 91bf0eac79291464b354cb23548026ae05d2becff917c1262b27931cece24cd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page