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.
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
¶
Closed Captions (CC) - Real-time Subtitles
Ultra low-latency transcription for live subtitles/closed captions. Small chunks, fast processing, continuous output.
Usage
python examples/closed_captions.py python examples/closed_captions.py --language es
Requirements
pip install sounddevice soundfile numpy
examples.closed_captions.MODEL_ALIASES
module-attribute
¶
MODEL_ALIASES = {'whisper-small': 'mlx-community/whisper-small-mlx', 'whisper-medium': 'mlx-community/whisper-medium-mlx', 'whisper-large-v3': 'mlx-community/whisper-large-v3-mlx', 'whisper-turbo': 'mlx-community/whisper-large-v3-turbo', 'parakeet': 'mlx-community/parakeet-tdt-0.6b-v2'}
examples.closed_captions.ClosedCaptions
¶
Real-time closed captions.
Source code in examples/closed_captions.py
examples.closed_captions.ClosedCaptions.chunk_samples
instance-attribute
¶
chunk_samples = int(SAMPLE_RATE * chunk_sec)
examples.closed_captions.ClosedCaptions.audio_queue
instance-attribute
¶
examples.closed_captions.ClosedCaptions.load_model
¶
examples.closed_captions.ClosedCaptions.audio_callback
¶
examples.closed_captions.ClosedCaptions.transcribe
¶
Source code in examples/closed_captions.py
examples.closed_captions.ClosedCaptions.display_caption
¶
examples.closed_captions.ClosedCaptions.process_loop
¶
Process audio continuously.
Source code in examples/closed_captions.py
examples.closed_captions.ClosedCaptions.run
¶
Source code in examples/closed_captions.py
examples.closed_captions.main
¶
Source code in examples/closed_captions.py
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.
examples.closed_captions.ClosedCaptions · class
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.
examples.closed_captions.ClosedCaptions.__init__ · method
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.
examples.closed_captions.ClosedCaptions.load_model · method
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.
examples.closed_captions.ClosedCaptions.audio_callback · method
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.
examples.closed_captions.ClosedCaptions.transcribe · method
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.
examples.closed_captions.ClosedCaptions.display_caption · method
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.
examples.closed_captions.ClosedCaptions.process_loop · method
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.
examples.closed_captions.ClosedCaptions.run · method
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.
examples.closed_captions.main · function
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.
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 |
class | ClosedCaptions(model_name: str, language: str = None, chunk_sec: float = 1.5) |
Real-time closed captions. | #L40-L145 |
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 |
ClosedCaptions.load_model |
method | ClosedCaptions.load_model() -> not annotated |
Method ClosedCaptions.load_model updates self.engine; calls STTEngine, self.engine.load. |
#L57-L60 |
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 |
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 |
ClosedCaptions.display_caption |
method | ClosedCaptions.display_caption(text) -> not annotated |
Display caption like subtitles. | #L77-L83 |
ClosedCaptions.process_loop |
method | ClosedCaptions.process_loop() -> not annotated |
Process audio continuously. | #L85-L109 |
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 |
main |
function | main() -> not annotated |
Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, MODEL_ALIASES.get. |
#L148-L162 |