Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

audit: fix multilingual_audio_translator - add missing docstrings

Tiioluwani0bfa97f78e93
diff --git a/audio/multilingual_audio_translator/app.py b/audio/multilingual_audio_translator/app.py
index ca24881..4beb890 100644
--- a/audio/multilingual_audio_translator/app.py
+++ b/audio/multilingual_audio_translator/app.py
@@ -12,6 +12,7 @@ TARGET_LANGUAGES = list(LANGUAGE_NAMES.items())
def process_audio(audio_path: str | None, target_language: str):
+ """Run the full transcribe, translate, and synthesize pipeline and return all outputs for the UI."""
if not audio_path:
raise gr.Error("Please upload or record an audio file.")
@@ -51,6 +52,7 @@ def process_audio(audio_path: str | None, target_language: str):
def build_app() -> gr.Blocks:
+ """Construct and return the Gradio Blocks interface for the audio translator."""
with gr.Blocks(
title="Multilingual Audio Translator",
theme=gr.themes.Soft(),
diff --git a/audio/multilingual_audio_translator/synthesizer.py b/audio/multilingual_audio_translator/synthesizer.py
index 2d37c72..93d770e 100644
--- a/audio/multilingual_audio_translator/synthesizer.py
+++ b/audio/multilingual_audio_translator/synthesizer.py
@@ -39,6 +39,7 @@ _pipelines: dict[str, KPipeline] = {}
def _get_pipeline(lang_code: str) -> KPipeline:
+ """Return the cached KPipeline for the given Kokoro language code, creating it if needed."""
if lang_code not in _pipelines:
_pipelines[lang_code] = KPipeline(lang_code=lang_code)
return _pipelines[lang_code]
diff --git a/audio/multilingual_audio_translator/transcriber.py b/audio/multilingual_audio_translator/transcriber.py
index 3fccd6f..4d529c5 100644
--- a/audio/multilingual_audio_translator/transcriber.py
+++ b/audio/multilingual_audio_translator/transcriber.py
@@ -14,12 +14,14 @@ _model: WhisperModel | None = None
def _get_device_config() -> tuple[str, str]:
+ """Return the appropriate device and compute type based on CUDA availability."""
if torch.cuda.is_available():
return "cuda", "float16"
return "cpu", "int8"
def get_model() -> WhisperModel:
+ """Return the cached WhisperModel, loading it on first call."""
global _model
if _model is None:
device, compute_type = _get_device_config()
@@ -29,6 +31,7 @@ def get_model() -> WhisperModel:
@dataclass
class TranscriptionResult:
+ """Holds the transcript text, detected language code, and detection confidence."""
text: str
language: str
language_probability: float
diff --git a/audio/multilingual_audio_translator/translator.py b/audio/multilingual_audio_translator/translator.py
index c6763a9..7c02fc0 100644
--- a/audio/multilingual_audio_translator/translator.py
+++ b/audio/multilingual_audio_translator/translator.py
@@ -37,6 +37,7 @@ LANGUAGE_NAMES = {
def _get_client() -> OpenAI:
+ """Build and return an OpenAI client pointed at the Orq.ai router."""
api_key = os.getenv("ORQ_API_KEY")
if not api_key:
raise ValueError(