syncalong.transcribe¶
Transcribe audio with OpenAI Whisper and extract word-level timestamps. Use
Transcriber to load the model once and
reuse it across many songs.
transcribe ¶
Transcribe audio with OpenAI Whisper and extract word-level timestamps.
WordTimestamp
dataclass
¶
A single recognised word with its timing.
Attributes:
| Name | Type | Description |
|---|---|---|
word |
str
|
Normalized text (for matching). |
raw |
str
|
Original text from Whisper. |
start |
float
|
Start time in seconds. |
end |
float
|
End time in seconds. |
Transcriber ¶
Reusable Whisper transcriber that loads its model once.
Loading a Whisper model is expensive, so a long-running consumer (e.g. a
jukebox processing many songs) should create one Transcriber and call
:meth:transcribe repeatedly rather than calling
:func:transcribe_audio per song.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Whisper model size or variant ( |
'base'
|
model
|
Any
|
A preloaded Whisper model object. When given it is used as-is
and |
None
|
Initialize the transcriber, loading a Whisper model if none is given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Whisper model size or variant to load when |
'base'
|
model
|
Any
|
A preloaded Whisper model to use as-is instead of loading one. |
None
|
Source code in src/syncalong/transcribe.py
transcribe ¶
transcribe(audio_path: Path, *, language: str | None = None, initial_prompt: str | None = None) -> list[WordTimestamp]
Transcribe one audio file into word-level timestamps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio_path
|
Path
|
Audio file (any format ffmpeg can decode). |
required |
language
|
str | None
|
BCP-47 language code, or |
None
|
initial_prompt
|
str | None
|
Text to bias the decoder with (e.g. the lyrics). |
None
|
Returns:
| Type | Description |
|---|---|
list[WordTimestamp]
|
Every recognised word, in order, with start/end times in seconds. |
Source code in src/syncalong/transcribe.py
transcribe_audio ¶
transcribe_audio(audio_path: Path, *, model_name: str = 'base', language: str | None = None, initial_prompt: str | None = None) -> list[WordTimestamp]
Transcribe one audio file, loading the model for this call only.
Convenience wrapper around :class:Transcriber for one-shot use. A
consumer that transcribes many files should instantiate a
:class:Transcriber once and reuse it instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio_path
|
Path
|
Audio file (any format ffmpeg can decode). |
required |
model_name
|
str
|
Whisper model size or variant. |
'base'
|
language
|
str | None
|
BCP-47 language code, or |
None
|
initial_prompt
|
str | None
|
Text to bias the decoder with (e.g. the lyrics). |
None
|
Returns:
| Type | Description |
|---|---|
list[WordTimestamp]
|
Ordered word timestamps. |