transcribe
Transcribe an audio file to text.
Transcribes recorded audio. When the declared media type is generic, the format is sniffed from the bytes themselves, so MP4, M4A, WAV, Ogg, FLAC, and MP3 are recognized without you naming them.
For microphone input that should transcribe as it arrives, use
streamTranscribe.
let result = try await transcribe(
model: DeepgramTranscriptionModel("nova-3"),
audio: try Data(contentsOf: url)
)
print(result.text)Signature
func transcribe(
model: any TranscriptionModel,
audio: Data,
mediaType: String,
providerOptions: JSONValue? = nil,
maxRetries: Int = 2
) async throws -> TranscriptionResultDefined in Sources/AI/Core/Transcription.swift.
Parameters
| Parameter | Type | Default |
|---|---|---|
model | any TranscriptionModel | required |
audio | Data | required |
mediaType | String | required |
providerOptions | JSONValue? | nil |
maxRetries | Int | 2 |
Returns
TranscriptionResult with text, segments, detected language,
durationInSeconds, and providerMetadata.