Skip to content

API Reference parrot.voice.transcriber.backend

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.voice.transcriber.backend

View source

Abstract Transcriber Backend.

Defines the abstract base class for voice transcription backends. Both FasterWhisperBackend and OpenAIWhisperBackend implement this interface, allowing the VoiceTranscriber service to work with either backend interchangeably.

Originally part of FEAT-008 (MS Teams Voice Note Support), refactored to shared location for FEAT-039.

Class AbstractTranscriberBackend

Abstract base class for transcription backends.

This defines the interface that all transcription backends must implement. The transcribe method is abstract and must be implemented by subclasses. The close method has a default no-op implementation.

Example usage::

class MyBackend(AbstractTranscriberBackend):
    async def transcribe(self, audio_path, language=None):
        # Implementation here
        return TranscriptionResult(...)

backend = MyBackend()
result = await backend.transcribe(Path("/path/to/audio.wav"))
await backend.close()

Method AbstractTranscriberBackend.transcribe

Transcribe audio file to text.

Example::

result = await backend.transcribe(
    Path("/path/to/audio.ogg"),
    language="en"
)
print(f"Transcribed: {result.text}")

transcribe(audio_path: Path, language: Optional[str] = None) -> TranscriptionResult

Parameter Type Default Description
audio_path Path Path to the audio file to transcribe. Supported formats depend on the backend implementation, but typically include WAV, OGG, MP3, M4A, and WebM.
language Optional[str] None Optional language hint (ISO 639-1 code, e.g., "en", "es"). If None, the backend should attempt to auto-detect the language.

Returns: TranscriptionResult — TranscriptionResult containing:

  • text: The transcribed text
  • language: Detected or specified language code
  • duration_seconds: Audio duration
  • confidence: Optional confidence score (0.0 to 1.0)
  • processing_time_ms: Time taken to transcribe

Raises:

  • FileNotFoundError — If audio_path does not exist.
  • ValueError — If the audio format is unsupported by this backend.
  • RuntimeError — If transcription fails due to backend errors.

Method AbstractTranscriberBackend.close

Release resources held by the backend.

This method should be called when the backend is no longer needed to free up resources such as loaded models, network connections, or GPU memory.

The default implementation does nothing. Subclasses should override this method if they hold resources that need explicit cleanup.

Example::

backend = FasterWhisperBackend()
try:
    result = await backend.transcribe(audio_path)
finally:
    await backend.close()  # Release GPU memory

close() -> None

Alias TranscriptionResult

Re-exported from parrot.voice.transcriber.models.TranscriptionResult.

Function primary_language_subtag

Return the lowercase primary subtag of a language tag.

Whisper-family backends accept only an ISO 639-1 code, while callers such as browsers send BCP-47 tags ("es-ES", "en_US").

primary_language_subtag(language: Optional[str]) -> Optional[str]

Parameter Type Default Description
language Optional[str] A language code or BCP-47 tag, or None.

Returns: Optional[str] — The primary subtag ("es-ES" -> "es"), or None when language is empty.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally