Skip to main content

Record voice and insert as inline code comments across any language and IDE

Project description

VoiceComment

Record voice and insert as inline code comments across any language and IDE.

Turn your spoken thoughts into well-formatted code comments with a single command. Works with Python, JavaScript, TypeScript, Go, Rust, Java, and more.

Python License Status

Features

  • Voice Recording: Local microphone input with silence detection
  • Transcription: Support for Whisper (local) and OpenAI API
  • Smart Comment Insertion: Language-aware parser with proper indentation
  • Multi-Language Support: Python, JavaScript, TypeScript, Go, Rust, Java, C#, Ruby
  • Pluggable Backends: Swap recorders, transcribers, and parsers easily
  • Flexible API: CLI, Python package, and programmatic access
  • Production-Ready: Type hints, error handling, and comprehensive logging

Installation

Prerequisites

  • Python 3.9+
  • PortAudio (for audio recording)

macOS

brew install portaudio

Ubuntu/Debian

sudo apt-get install portaudio19-dev

Windows

PortAudio is typically bundled. If not, download from PortAudio Downloads.

Install Package

pip install voicecomment

Or from source (development):

git clone https://github.com/yourusername/voicecomment
cd voicecomment
pip install -e .

Quick Start

Command Line

# Record and insert comment at line 42
voicecomment record myfile.py 42

# With fixed duration (5 seconds)
voicecomment record myfile.py 42 --duration 5

# Transcribe without modifying file
voicecomment transcribe

# Insert comment directly (no recording)
voicecomment insert myfile.py 42 "This is my comment"

Python API

from voicecomment import VoiceCommenter

# Auto-detect language from file extension
commenter = VoiceCommenter()
commenter.record_and_insert('myfile.py', line_number=42)

# Or specify language explicitly
commenter = VoiceCommenter(language='python')
commenter.record_and_insert('main.py', line_number=15)

# Transcribe only
text = commenter.transcribe_only()
print(text)  # "This function calculates factorial recursively"

# Insert into code string (no file I/O)
code = """
def factorial(n):
    return n * factorial(n - 1) if n > 1 else 1
"""
updated = commenter.insert_comment_to_string(
    code,
    "Base case for recursion",
    line_number=3
)
print(updated)

Jupyter Notebook

from voicecomment import VoiceCommenter

commenter = VoiceCommenter(language='python')

# Record and modify cell code
code_str = """
def process_data(df):
    return df.dropna()
"""

updated = commenter.insert_comment_to_string(
    code_str,
    "Remove rows with missing values",
    line_number=2
)
print(updated)

Architecture

Core Components

1. AudioRecorder (recorder.py)

  • LocalAudioRecorder: Captures audio from system microphone
  • Supports fixed duration or silence detection
  • Configurable sample rate, channels, and format

2. Transcriber (transcriber.py)

Pluggable backends:

  • WhisperTranscriber: Local OpenAI Whisper model (no API key needed)
  • OpenAITranscriber: OpenAI Whisper API
  • MockTranscriber: For testing without audio hardware
# Use local Whisper
from voicecomment.transcriber import WhisperTranscriber
transcriber = WhisperTranscriber(model_size="base")

# Or OpenAI API
from voicecomment.transcriber import OpenAITranscriber
transcriber = OpenAITranscriber(api_key="sk-...")

3. CodeParser (parser.py)

Language-specific parsers:

  • PythonParser: Uses # prefix with proper indentation
  • JavaScriptParser: Uses // prefix
  • GenericParser: Configurable fallback for unsupported languages

4. VoiceCommenter (commenter.py)

Main orchestration class that ties everything together.

Advanced Usage

Custom Transcriber

from voicecomment import VoiceCommenter
from voicecomment.transcriber import TranscriberBase
import numpy as np

class CustomLLMTranscriber(TranscriberBase):
    def transcribe(self, audio: np.ndarray, sample_rate: int = 16000) -> str:
        # Your LLM logic here
        return "custom transcription"

commenter = VoiceCommenter(transcriber=CustomLLMTranscriber())
commenter.record_and_insert('file.py', line_number=10)

Custom Audio Config

from voicecomment import VoiceCommenter, AudioConfig

config = AudioConfig(
    sample_rate=44100,  # High-quality audio
    channels=2,         # Stereo
)

commenter = VoiceCommenter(audio_config=config)

Integration with IDE Extensions

The Python package can be called from:

  • VS Code Extension: Via subprocess or Node.js child process
  • Vim Plugin: Via Python 3 interface
  • Neovim: Via Python plugin host
  • Emacs: Via python-shell

Example VS Code extension (snippet):

const { spawn } = require('child_process');

const proc = spawn('voicecomment', ['record', filepath, lineNumber.toString()]);
proc.on('close', (code) => {
  if (code === 0) {
    vscode.window.showInformationMessage('Comment inserted!');
  }
});

Development

Setup

git clone https://github.com/yourusername/voicecomment
cd voicecomment
pip install -e ".[dev]"

Testing

pytest
pytest --cov  # With coverage

Code Quality

black .
ruff check .
mypy voicecomment/

Supported Languages

Language Extension Comment Prefix
Python .py, .pyw #
JavaScript .js, .jsx, .mjs //
TypeScript .ts, .tsx, .mts //
Go .go //
Rust .rs //
Java .java //
C# .cs //
Ruby .rb #
C/C++ .c, .cpp, .h, .hpp //

Roadmap

  • VS Code Extension (official)
  • Vim/Neovim plugin
  • Watch mode for automated comment markers
  • Voice activity detection (VAD)
  • Conversation-aware transcription (context from file)
  • Custom prompt engineering for comment style
  • Analytics dashboard (tracking comment patterns)
  • LangChain integration for LLM-powered comments

Contributing

Contributions welcome! Please open an issue or pull request.

License

MIT License - see LICENSE


Built for developers who believe code comments should be as natural as talking.

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

speakline-0.1.0.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

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

speakline-0.1.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file speakline-0.1.0.tar.gz.

File metadata

  • Download URL: speakline-0.1.0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for speakline-0.1.0.tar.gz
Algorithm Hash digest
SHA256 177d22688988adcd24bbd8450921be64fd1e1e22344ac22a32b455ffbfacdb82
MD5 9c775036b32d2f1f8c986b0c4503590e
BLAKE2b-256 457cf4c82151ca1b5362ab3c8d05bdf0c28bd53a8940d8e49c2aa3364e54b4a5

See more details on using hashes here.

File details

Details for the file speakline-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: speakline-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for speakline-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a03569efbff7cc9a4083a348648beadf7d34a1811a769c81380aa0e4865aff6
MD5 60ff0455bc23298e73eb84e3ca50145a
BLAKE2b-256 1b0af89bf7719544b9dd7c4a6701caf3c1136ae0446b9d986929588a9bb232a5

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