Skip to main content

OpenAI Whisper plugin for the cjm-transcription-plugin-system library - provides local speech-to-text transcription with configurable model selection and parameter control.

Project description

cjm-transcription-plugin-whisper

Install

pip install cjm_transcription_plugin_whisper

Project Structure

nbs/
├── meta.ipynb   # Metadata introspection for the Whisper plugin used by cjm-ctl to generate the registration manifest.
└── plugin.ipynb # Plugin implementation for OpenAI Whisper transcription

Total: 2 notebooks across 1 directory

Module Dependencies

graph LR
    meta[meta<br/>Metadata]
    plugin[plugin<br/>Whisper Plugin]

    plugin --> meta

1 cross-module dependencies detected

CLI Reference

No CLI commands found in this project.

Module Overview

Detailed documentation for each module in the project:

Metadata (meta.ipynb)

Metadata introspection for the Whisper plugin used by cjm-ctl to generate the registration manifest.

Import

from cjm_transcription_plugin_whisper.meta import (
    get_plugin_metadata
)

Functions

def get_plugin_metadata() -> Dict[str, Any]: # Plugin metadata for manifest generation
    """Return metadata required to register this plugin with the PluginManager."""
    # Calculate default DB path relative to the environment
    # e.g., /opt/conda/envs/cjm-whisper/data/history.db
    base_path = os.path.dirname(os.path.dirname(sys.executable))
    data_dir = os.path.join(base_path, "data")
    db_path = os.path.join(data_dir, "transcriptions.db")
    
    # Ensure data directory exists
    os.makedirs(data_dir, exist_ok=True)

    return {
        "name": "cjm-transcription-plugin-whisper",
    "Return metadata required to register this plugin with the PluginManager."

Whisper Plugin (plugin.ipynb)

Plugin implementation for OpenAI Whisper transcription

Import

from cjm_transcription_plugin_whisper.plugin import (
    WhisperPluginConfig,
    WhisperLocalPlugin
)

Classes

@dataclass
class WhisperPluginConfig:
    "Configuration for Whisper transcription plugin."
    
    model: str = field(...)
    device: str = field(...)
    language: Optional[str] = field(...)
    task: str = field(...)
    temperature: float = field(...)
    temperature_increment_on_fallback: Optional[float] = field(...)
    beam_size: int = field(...)
    best_of: int = field(...)
    patience: float = field(...)
    length_penalty: Optional[float] = field(...)
    suppress_tokens: str = field(...)
    initial_prompt: Optional[str] = field(...)
    condition_on_previous_text: bool = field(...)
    fp16: bool = field(...)
    compression_ratio_threshold: float = field(...)
    logprob_threshold: float = field(...)
    no_speech_threshold: float = field(...)
    word_timestamps: bool = field(...)
    prepend_punctuations: str = field(...)
    append_punctuations: str = field(...)
    threads: int = field(...)
    model_dir: Optional[str] = field(...)
    compile_model: bool = field(...)
class WhisperLocalPlugin:
    def __init__(self):
        """Initialize the Whisper plugin with default configuration."""
        self.logger = logging.getLogger(f"{__name__}.{type(self).__name__}")
        self.config: WhisperPluginConfig = None
    "OpenAI Whisper transcription plugin."
    
    def __init__(self):
            """Initialize the Whisper plugin with default configuration."""
            self.logger = logging.getLogger(f"{__name__}.{type(self).__name__}")
            self.config: WhisperPluginConfig = None
        "Initialize the Whisper plugin with default configuration."
    
    def name(self) -> str: # Plugin name identifier
            """Get the plugin name identifier."""
            return "whisper_local"
        
        @property
        def version(self) -> str: # Plugin version string
        "Get the plugin name identifier."
    
    def version(self) -> str: # Plugin version string
            """Get the plugin version string."""
            return "1.0.0"
        
        @property
        def supported_formats(self) -> List[str]: # List of supported audio file formats
        "Get the plugin version string."
    
    def supported_formats(self) -> List[str]: # List of supported audio file formats
            """Get the list of supported audio file formats."""
            return ["wav", "mp3", "flac", "m4a", "ogg", "webm", "mp4", "avi", "mov"]
    
        def get_current_config(self) -> Dict[str, Any]: # Current configuration as dictionary
        "Get the list of supported audio file formats."
    
    def get_current_config(self) -> Dict[str, Any]: # Current configuration as dictionary
            """Return current configuration state."""
            if not self.config
        "Return current configuration state."
    
    def get_config_schema(self) -> Dict[str, Any]: # JSON Schema for configuration
            """Return JSON Schema for UI generation."""
            return dataclass_to_jsonschema(WhisperPluginConfig)
    
        @staticmethod
        def get_config_dataclass() -> WhisperPluginConfig: # Configuration dataclass
        "Return JSON Schema for UI generation."
    
    def get_config_dataclass() -> WhisperPluginConfig: # Configuration dataclass
            """Return dataclass describing the plugin's configuration options."""
            return WhisperPluginConfig
        
        def initialize(
            self,
            config: Optional[Any] = None # Configuration dataclass, dict, or None
        ) -> None
        "Return dataclass describing the plugin's configuration options."
    
    def initialize(
            self,
            config: Optional[Any] = None # Configuration dataclass, dict, or None
        ) -> None
        "Initialize or re-configure the plugin (idempotent)."
    
    def execute(
            self,
            audio: Union[AudioData, str, Path], # Audio data or path to audio file to transcribe
            **kwargs # Additional arguments to override config
        ) -> TranscriptionResult: # Transcription result with text and metadata
        "Transcribe audio using Whisper."
    
    def is_available(self) -> bool: # True if Whisper and its dependencies are available
            """Check if Whisper is available."""
            return WHISPER_AVAILABLE
        
        def cleanup(self) -> None
        "Check if Whisper is available."
    
    def cleanup(self) -> None:
            """Clean up resources."""
            if self.model is not None
        "Clean up resources."

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

cjm_transcription_plugin_whisper-0.0.10.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file cjm_transcription_plugin_whisper-0.0.10.tar.gz.

File metadata

File hashes

Hashes for cjm_transcription_plugin_whisper-0.0.10.tar.gz
Algorithm Hash digest
SHA256 74a188f5ec2640e84b065c4c7896d842f6cb9fefda3d18a00279e5ff66afe6b5
MD5 f20d7d9985a1ac6ee2097919f9717a2b
BLAKE2b-256 d196582b3f6e52092afc414caeb2133c8cc06e2f1d266bed99011fec148a01f0

See more details on using hashes here.

File details

Details for the file cjm_transcription_plugin_whisper-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for cjm_transcription_plugin_whisper-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 5d999bb8c2bd01aabf458eac15d47697bc52cfbc7768797e751fffc1b71242e6
MD5 af42236512067fceac87b021ec07750a
BLAKE2b-256 848a4c3c6c7b12f6d9b0a4926b1aa9352f3fb8c03637bd97ac6314db4672d82a

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