Skip to content

Module whisper Architecture

github-actions[bot] edited this page Sep 1, 2026 · 3 revisions

Architektur-Hinweis: Klassen/Typen/Namespaces mit aktuellem Sourcecode abgleichen. Symbole, die nicht im Source gefunden werden, mit `` markieren.

Whisper Plugin β€” Architecture Guide

Version: 1.0 Last Updated: 2026-04-07 Module Path: src/whisper/


1. Overview

The Whisper plugin integrates whisper.cpp into ThemisDB's plugin system as an IAudioBackend. It converts raw WAV audio into text transcriptions enriched with mandatory provenance metadata. The plugin is structured around three orthogonal concerns:

  1. Audio ingestion β€” WavAudioChunkReader parses RIFF/WAV containers without external libraries; FfmpegAudioChunkReader handles MP3/OGG/FLAC/M4A via an ffmpeg subprocess; CompositeAudioChunkReader chains multiple readers by file extension.
  2. Inference β€” IWhisperTranscriber (strategy) decouples model execution from plugin lifecycle.
  3. Provenance β€” WhisperPlugin applies stamps (ingestion_source_type, plugin_version, generation_timestamp) unconditionally before returning TranscriptionResult.

2. Design Principles

  • Stub-first β€” WhisperStubTranscriber is always available; whisper.cpp is optional. CI environments without a model file receive a valid TranscriptionResult with success=true.
  • Injection-friendly β€” WhisperPlugin(std::unique_ptr<IWhisperTranscriber>) constructor enables full unit testing without touching the file system or model files.
  • Provenance unconditional β€” timestamps and source-type stamps are applied in WhisperPlugin, never delegated to the transcriber, ensuring no transcriber implementation can omit them.
  • Zero external dependencies for ingestion β€” WavAudioChunkReader requires only <fstream> and <cstring>.

3. Component Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  IAudioBackend  (include/plugins/audio_backend_interface.h) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚ implements
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚      WhisperPlugin       β”‚
                β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
                β”‚  β”‚ IWhisperTranscriberβ”‚   β”‚  ← strategy
                β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚   β”‚
                β”‚  β”‚  β”‚ CppTranscribβ”‚  β”‚   β”‚  (whisper.cpp, optional)
                β”‚  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚   β”‚
                β”‚  β”‚  β”‚ StubTranscr β”‚  β”‚   β”‚  (always available)
                β”‚  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚   β”‚
                β”‚  β”‚  β”‚ InMemoryTr. β”‚  β”‚   β”‚  (test double)
                β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚   β”‚
                β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
                β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
                β”‚  β”‚CompositeChunkRdr  β”‚   β”‚  ← dispatches by extension
                β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚   β”‚
                β”‚  β”‚  β”‚WavChunkRdr  β”‚  β”‚   β”‚  (RIFF/WAV, no deps)
                β”‚  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚   β”‚
                β”‚  β”‚  β”‚FfmpegChkRdr β”‚  β”‚   β”‚  (MP3/OGG/FLAC, ffmpeg)
                β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚   β”‚
                β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚ registered via
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚ WhisperPluginAdapter : IThemisPlugin β”‚  ← PluginManager integration
         β”‚ WhisperPluginRegistrar              β”‚  ← hot-plug lifecycle
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

4. Key Data Flows

4.1 transcribe(path, config)

WhisperPlugin::transcribe(path, cfg)
  β”œβ”€ WavAudioChunkReader::read(path)     β†’ AudioChunk (PCM samples)
  β”œβ”€ IWhisperTranscriber::transcribe(chunk, cfg)  β†’ raw text / language
  β”œβ”€ apply provenance stamps
  └─ return TranscriptionResult

4.2 Error Paths

Condition Behaviour
Plugin not initialised success=false, error_message="not initialized"
File not found success=false, error_message=<filesystem error>
Invalid WAV format success=false, error_message=<parse error>
Transcriber throws success=false, error_message=<exception.what()>
All success paths success=true, provenance stamps set

5. Configuration (WhisperConfig)

Field Default Constraint
model_path "" path to .bin model
language "auto" ISO 639-1 or "auto"
threads 4 clamped to [1, 64]
n_past 0 context tokens to keep
use_gpu false enables CUDA/Metal
beam_size 5 [1, 20]

6. Plugin Manifest

plugins/whisper/plugin.json.in is processed by CMake into plugin.json at build time. The manifest declares type: AUDIO_PROCESSING, api_version: 1.0, and optional dependency on whisper_cpp >= 1.5.0.


7. Thread Safety

WhisperPlugin is thread-safe for concurrent transcribe(), transcribeFile(), and detectLanguage() calls via transcriber_mutex_ plus atomic counters.


8. Testing Strategy

Type Files Count
Unit (stub mode) src/whisper/tests/test_whisper_plugin.cpp 44
Unit (registrar) src/whisper/tests/test_whisper_plugin_registrar.cpp 12

All 44 plugin tests run without a whisper.cpp model file. InMemoryWhisperTranscriber is injected via the DI constructor for multiple groups (including E–N).

The 12 registrar tests cover WhisperPluginAdapter and WhisperPluginRegistrar lifecycle (groups A–D: create, adapter capabilities, hot-plug enable/disable, default reload callback).


ThemisDB 1.9.0-beta Β· Home Β· Module-Index Β· GitHub Β· Issues

ThemisDB Wiki

🏠 Overview

πŸš€ Getting Started

πŸ“– Tutorials

πŸ“— User Guide

βš™οΈ Operations & Security

πŸ“Ÿ Ops Runbooks

πŸ—οΈ Architecture

πŸ“ ADRs

πŸ”§ Contributing

πŸ“‹ Governance

πŸ” Audit

🧩 Plugins

πŸ”Œ Adapters

πŸ’‘ Examples

πŸ“¦ Client SDKs

πŸŽ“ Training

πŸ› οΈ Tools

πŸ€– Developer LLM Wiki

Clone this wiki locally