# `examples.closed_captions`

Closed Captions (CC) - Real-time Subtitles Ultra low-latency transcription for live subtitles/closed captions.

[View the complete module source at #L1-L166](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L1-L166).

## API details

Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.

::: examples.closed_captions
    options:
      members:
        - MODEL_ALIASES
        - SAMPLE_RATE
        - ClosedCaptions
        - main
      filters: []
      show_if_no_docstring: true

## Complete contract reference

Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.

<details class="api-contract" id="contract-examples.closed_captions.ClosedCaptions" markdown="1">
<summary><code>examples.closed_captions.ClosedCaptions</code> · class</summary>

```python
examples.closed_captions.ClosedCaptions(model_name: str, language: str = None, chunk_sec: float = 1.5)
```

Real-time closed captions.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model_name` | `str` | `yes` | `none` | Required positional or keyword input. |
| `language` | `str` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `chunk_sec` | `float` | `no` | `1.5` | Optional positional or keyword input; defaults to `1.5`. |

**Returns**

- Constructs: `examples.closed_captions.ClosedCaptions`

**Exceptions and behavior**

Class `ClosedCaptions` declares 7 direct member(s).
No direct `raise` statement appears in this definition.

[View source #L40-L145](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L40-L145).

</details>

<details class="api-contract" id="contract-examples.closed_captions.ClosedCaptions.__init__" markdown="1">
<summary><code>examples.closed_captions.ClosedCaptions.__init__</code> · method</summary>

```python
examples.closed_captions.ClosedCaptions.__init__(model_name: str, language: str = None, chunk_sec: float = 1.5) -> not annotated
```

Method `ClosedCaptions.__init__` updates `self.model_name`, `self.language`, `self.chunk_sec`, `self.chunk_samples`; calls `int`, `queue.Queue`.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `model_name` | `str` | `yes` | `none` | Required positional or keyword input. |
| `language` | `str` | `no` | `None` | Optional positional or keyword input; defaults to `None`. |
| `chunk_sec` | `float` | `no` | `1.5` | Optional positional or keyword input; defaults to `1.5`. |

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Method `ClosedCaptions.__init__` updates `self.model_name`, `self.language`, `self.chunk_sec`, `self.chunk_samples`; calls `int`, `queue.Queue`.
No direct `raise` statement appears in this definition.

[View source #L43-L55](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L43-L55).

</details>

<details class="api-contract" id="contract-examples.closed_captions.ClosedCaptions.load_model" markdown="1">
<summary><code>examples.closed_captions.ClosedCaptions.load_model</code> · method</summary>

```python
examples.closed_captions.ClosedCaptions.load_model() -> not annotated
```

Method `ClosedCaptions.load_model` updates `self.engine`; calls `STTEngine`, `self.engine.load`.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Method `ClosedCaptions.load_model` updates `self.engine`; calls `STTEngine`, `self.engine.load`.
No direct `raise` statement appears in this definition.

[View source #L57-L60](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L57-L60).

</details>

<details class="api-contract" id="contract-examples.closed_captions.ClosedCaptions.audio_callback" markdown="1">
<summary><code>examples.closed_captions.ClosedCaptions.audio_callback</code> · method</summary>

```python
examples.closed_captions.ClosedCaptions.audio_callback(indata, frames, time_info, status) -> not annotated
```

Method `ClosedCaptions.audio_callback` calls `self.audio_queue.put`, `indata.copy().flatten`, `indata.copy`.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `indata` | `not annotated` | `yes` | `none` | Required positional or keyword input. |
| `frames` | `not annotated` | `yes` | `none` | Required positional or keyword input. |
| `time_info` | `not annotated` | `yes` | `none` | Required positional or keyword input. |
| `status` | `not annotated` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Method `ClosedCaptions.audio_callback` calls `self.audio_queue.put`, `indata.copy().flatten`, `indata.copy`.
No direct `raise` statement appears in this definition.

[View source #L62-L64](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L62-L64).

</details>

<details class="api-contract" id="contract-examples.closed_captions.ClosedCaptions.transcribe" markdown="1">
<summary><code>examples.closed_captions.ClosedCaptions.transcribe</code> · method</summary>

```python
examples.closed_captions.ClosedCaptions.transcribe(audio) -> not annotated
```

Method `ClosedCaptions.transcribe` calls `tempfile.NamedTemporaryFile`, `sf.write`, `self.engine.transcribe`, `result.text.strip`; returns `result.text.strip()`.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `audio` | `not annotated` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `not annotated`
- Direct return expressions: `result.text.strip()`

**Exceptions and behavior**

Method `ClosedCaptions.transcribe` calls `tempfile.NamedTemporaryFile`, `sf.write`, `self.engine.transcribe`, `result.text.strip`; returns `result.text.strip()`.
No direct `raise` statement appears in this definition.

[View source #L66-L75](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L66-L75).

</details>

<details class="api-contract" id="contract-examples.closed_captions.ClosedCaptions.display_caption" markdown="1">
<summary><code>examples.closed_captions.ClosedCaptions.display_caption</code> · method</summary>

```python
examples.closed_captions.ClosedCaptions.display_caption(text) -> not annotated
```

Display caption like subtitles.

**Parameters**

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `not annotated` | `yes` | `none` | Required positional or keyword input. |

**Returns**

- Type: `not annotated`
- Direct return expressions: `None`

**Exceptions and behavior**

Method `ClosedCaptions.display_caption` calls `print`; returns `None`.
No direct `raise` statement appears in this definition.

[View source #L77-L83](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L77-L83).

</details>

<details class="api-contract" id="contract-examples.closed_captions.ClosedCaptions.process_loop" markdown="1">
<summary><code>examples.closed_captions.ClosedCaptions.process_loop</code> · method</summary>

```python
examples.closed_captions.ClosedCaptions.process_loop() -> not annotated
```

Process audio continuously.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Method `ClosedCaptions.process_loop` calls `np.array`, `self.audio_queue.get`, `np.concatenate`, `len`.
No direct `raise` statement appears in this definition.

[View source #L85-L109](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L85-L109).

</details>

<details class="api-contract" id="contract-examples.closed_captions.ClosedCaptions.run" markdown="1">
<summary><code>examples.closed_captions.ClosedCaptions.run</code> · method</summary>

```python
examples.closed_captions.ClosedCaptions.run() -> not annotated
```

Method `ClosedCaptions.run` updates `self.running`; calls `print`, `' 🎬 CLOSED CAPTIONS - Real-time Subtitles'.center`, `self.model_name.split`, `threading.Thread`.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Method `ClosedCaptions.run` updates `self.running`; calls `print`, `' 🎬 CLOSED CAPTIONS - Real-time Subtitles'.center`, `self.model_name.split`, `threading.Thread`.
No direct `raise` statement appears in this definition.

[View source #L111-L145](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L111-L145).

</details>

<details class="api-contract" id="contract-examples.closed_captions.main" markdown="1">
<summary><code>examples.closed_captions.main</code> · function</summary>

```python
examples.closed_captions.main() -> not annotated
```

Function `main` calls `argparse.ArgumentParser`, `parser.add_argument`, `parser.parse_args`, `MODEL_ALIASES.get`.

**Parameters**

This callable has no explicit inputs.

**Returns**

- Type: `not annotated`

**Exceptions and behavior**

Function `main` calls `argparse.ArgumentParser`, `parser.add_argument`, `parser.parse_args`, `MODEL_ALIASES.get`.
No direct `raise` statement appears in this definition.

[View source #L148-L162](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L148-L162).

</details>

## Complete symbol map

This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.

| Symbol | Kind | Signature and inputs | What it does | Source |
| --- | --- | --- | --- | --- |
| [`ClosedCaptions`](#contract-examples.closed_captions.ClosedCaptions) | class | `ClosedCaptions(model_name: str, language: str = None, chunk_sec: float = 1.5)` | Real-time closed captions. | [#L40-L145](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L40-L145) |
| [`ClosedCaptions.__init__`](#contract-examples.closed_captions.ClosedCaptions.__init__) | method | `ClosedCaptions.__init__(model_name: str, language: str = None, chunk_sec: float = 1.5) -> not annotated` | Method `ClosedCaptions.__init__` updates `self.model_name`, `self.language`, `self.chunk_sec`, `self.chunk_samples`; calls `int`, `queue.Queue`. | [#L43-L55](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L43-L55) |
| [`ClosedCaptions.load_model`](#contract-examples.closed_captions.ClosedCaptions.load_model) | method | `ClosedCaptions.load_model() -> not annotated` | Method `ClosedCaptions.load_model` updates `self.engine`; calls `STTEngine`, `self.engine.load`. | [#L57-L60](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L57-L60) |
| [`ClosedCaptions.audio_callback`](#contract-examples.closed_captions.ClosedCaptions.audio_callback) | method | `ClosedCaptions.audio_callback(indata, frames, time_info, status) -> not annotated` | Method `ClosedCaptions.audio_callback` calls `self.audio_queue.put`, `indata.copy().flatten`, `indata.copy`. | [#L62-L64](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L62-L64) |
| [`ClosedCaptions.transcribe`](#contract-examples.closed_captions.ClosedCaptions.transcribe) | method | `ClosedCaptions.transcribe(audio) -> not annotated` | Method `ClosedCaptions.transcribe` calls `tempfile.NamedTemporaryFile`, `sf.write`, `self.engine.transcribe`, `result.text.strip`; returns `result.text.strip()`. | [#L66-L75](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L66-L75) |
| [`ClosedCaptions.display_caption`](#contract-examples.closed_captions.ClosedCaptions.display_caption) | method | `ClosedCaptions.display_caption(text) -> not annotated` | Display caption like subtitles. | [#L77-L83](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L77-L83) |
| [`ClosedCaptions.process_loop`](#contract-examples.closed_captions.ClosedCaptions.process_loop) | method | `ClosedCaptions.process_loop() -> not annotated` | Process audio continuously. | [#L85-L109](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L85-L109) |
| [`ClosedCaptions.run`](#contract-examples.closed_captions.ClosedCaptions.run) | method | `ClosedCaptions.run() -> not annotated` | Method `ClosedCaptions.run` updates `self.running`; calls `print`, `' 🎬 CLOSED CAPTIONS - Real-time Subtitles'.center`, `self.model_name.split`, `threading.Thread`. | [#L111-L145](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L111-L145) |
| [`main`](#contract-examples.closed_captions.main) | function | `main() -> not annotated` | Function `main` calls `argparse.ArgumentParser`, `parser.add_argument`, `parser.parse_args`, `MODEL_ALIASES.get`. | [#L148-L162](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/closed_captions.py#L148-L162) |
