> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/argmaxinc/WhisperKit/llms.txt
> Use this file to discover all available pages before exploring further.

# TranscriptionResult

> Result object containing transcribed text, segments, and metadata

## Overview

The `TranscriptionResult` class represents the output of a transcription operation. It contains the transcribed text, detailed segment information, language detection results, and performance timing data.

## Class Definition

```swift theme={null}
open class TranscriptionResult: Codable, @unchecked Sendable
```

## Initializer

```swift theme={null}
public init(
    text: String,
    segments: [TranscriptionSegment],
    language: String,
    timings: TranscriptionTimings,
    seekTime: Float? = nil
)
```

<ParamField path="text" type="String">
  Complete transcribed text
</ParamField>

<ParamField path="segments" type="[TranscriptionSegment]">
  Array of transcription segments with timestamps and metadata
</ParamField>

<ParamField path="language" type="String">
  Detected or specified language code
</ParamField>

<ParamField path="timings" type="TranscriptionTimings">
  Performance timing information
</ParamField>

<ParamField path="seekTime" type="Float?">
  Seek time offset in seconds (for chunked audio)
</ParamField>

## Properties

<ResponseField name="text" type="String">
  The complete transcribed text. All segments are concatenated together.
</ResponseField>

<ResponseField name="segments" type="[TranscriptionSegment]">
  Array of transcription segments, each containing:

  * Text content
  * Start and end timestamps
  * Token information
  * Quality metrics (log probabilities, compression ratio)
  * Optional word-level timestamps
</ResponseField>

<ResponseField name="language" type="String">
  ISO 639-1 language code (e.g., "en" for English, "es" for Spanish) detected or specified for this transcription.
</ResponseField>

<ResponseField name="timings" type="TranscriptionTimings">
  Detailed performance metrics including:

  * Model loading time
  * Audio processing time
  * Encoding time
  * Decoding time
  * Total pipeline duration
  * Real-time factor
</ResponseField>

<ResponseField name="seekTime" type="Float?">
  Seek time offset in seconds when this result is part of a chunked transcription.
</ResponseField>

## Computed Properties

<ResponseField name="allWords" type="[WordTiming]">
  Flat array of all word-level timings across all segments. Only populated when `wordTimestamps` is enabled in `DecodingOptions`.
</ResponseField>

## Methods

### logSegments()

Logs all segments with timestamps and text to the console.

```swift theme={null}
public func logSegments()
```

**Output Format:**

```
[Segment 0] [00:00.00 --> 00:03.50] Hello, this is a test.
[Segment 1] [00:03.50 --> 00:07.20] This is the second segment.
```

### logTimings()

Logs detailed performance timing information to the console.

```swift theme={null}
public func logTimings()
```

**Output includes:**

* Audio loading time
* Audio processing time
* Mel spectrogram computation time
* Encoding time
* Decoding time breakdown
* Total pipeline duration
* Tokens per second
* Real-time factor

## TranscriptionSegment

Each segment in the `segments` array contains detailed information:

```swift theme={null}
public struct TranscriptionSegment: Hashable, Codable, Sendable
```

### Properties

<ResponseField name="id" type="Int">
  Unique identifier for the segment
</ResponseField>

<ResponseField name="seek" type="Int">
  Seek position in the audio (in samples)
</ResponseField>

<ResponseField name="start" type="Float">
  Start timestamp in seconds
</ResponseField>

<ResponseField name="end" type="Float">
  End timestamp in seconds
</ResponseField>

<ResponseField name="text" type="String">
  Transcribed text for this segment
</ResponseField>

<ResponseField name="tokens" type="[Int]">
  Token IDs generated for this segment
</ResponseField>

<ResponseField name="tokenLogProbs" type="[[Int: Float]]">
  Log probabilities for each token
</ResponseField>

<ResponseField name="temperature" type="Float">
  Sampling temperature used for this segment
</ResponseField>

<ResponseField name="avgLogprob" type="Float">
  Average log probability of all tokens (quality indicator)
</ResponseField>

<ResponseField name="compressionRatio" type="Float">
  Text compression ratio (detects repetitive output)
</ResponseField>

<ResponseField name="noSpeechProb" type="Float">
  Probability that this segment contains no speech
</ResponseField>

<ResponseField name="words" type="[WordTiming]?">
  Optional array of word-level timings (only when `wordTimestamps` is enabled)
</ResponseField>

<ResponseField name="duration" type="Float">
  Computed duration of the segment (end - start)
</ResponseField>

## WordTiming

When word-level timestamps are enabled, each word includes:

```swift theme={null}
public struct WordTiming: Hashable, Codable, Sendable
```

### Properties

<ResponseField name="word" type="String">
  The word text
</ResponseField>

<ResponseField name="tokens" type="[Int]">
  Token IDs that comprise this word
</ResponseField>

<ResponseField name="start" type="Float">
  Start timestamp in seconds
</ResponseField>

<ResponseField name="end" type="Float">
  End timestamp in seconds
</ResponseField>

<ResponseField name="probability" type="Float">
  Confidence probability for this word
</ResponseField>

<ResponseField name="duration" type="Float">
  Computed duration (end - start)
</ResponseField>

## TranscriptionTimings

Detailed performance metrics:

```swift theme={null}
public struct TranscriptionTimings: Codable, Sendable
```

### Properties

<ResponseField name="modelLoading" type="TimeInterval">
  Total time spent loading models
</ResponseField>

<ResponseField name="audioLoading" type="TimeInterval">
  Time spent loading and converting audio
</ResponseField>

<ResponseField name="audioProcessing" type="TimeInterval">
  Time spent processing audio samples
</ResponseField>

<ResponseField name="logmels" type="TimeInterval">
  Time spent computing mel spectrograms
</ResponseField>

<ResponseField name="encoding" type="TimeInterval">
  Time spent in audio encoder
</ResponseField>

<ResponseField name="decodingPredictions" type="TimeInterval">
  Time spent in text decoder predictions
</ResponseField>

<ResponseField name="decodingLoop" type="TimeInterval">
  Total time spent in decoding loop
</ResponseField>

<ResponseField name="fullPipeline" type="TimeInterval">
  Total end-to-end pipeline duration
</ResponseField>

<ResponseField name="tokensPerSecond" type="Double">
  Computed: tokens generated per second
</ResponseField>

<ResponseField name="realTimeFactor" type="Double">
  Computed: ratio of processing time to audio duration (\< 1.0 means faster than real-time)
</ResponseField>

<ResponseField name="speedFactor" type="Double">
  Computed: inverse of real-time factor (> 1.0 means faster than real-time)
</ResponseField>

## Example Usage

### Basic Transcription

```swift theme={null}
import WhisperKit

let whisperKit = try await WhisperKit()
let results = try await whisperKit.transcribe(
    audioPath: "/path/to/audio.wav"
)

for result in results {
    print("Language: \(result.language)")
    print("Text: \(result.text)")
    print("Segments: \(result.segments.count)")
}
```

### Access Segments

```swift theme={null}
for segment in result.segments {
    print("[\(segment.start)s - \(segment.end)s]: \(segment.text)")
    print("  Confidence: \(segment.avgLogprob)")
    print("  No speech prob: \(segment.noSpeechProb)")
}
```

### Word-Level Timestamps

```swift theme={null}
let options = DecodingOptions(
    wordTimestamps: true
)

let results = try await whisperKit.transcribe(
    audioPath: "/path/to/audio.wav",
    decodeOptions: options
)

for result in results {
    for word in result.allWords {
        print("\(word.word) [\(word.start)s - \(word.end)s]")
    }
}
```

### Performance Analysis

```swift theme={null}
let result = results.first!

print("Real-time factor: \(result.timings.realTimeFactor)")
if result.timings.realTimeFactor < 1.0 {
    print("Processing faster than real-time!")
}

print("Tokens per second: \(result.timings.tokensPerSecond)")
print("Total time: \(result.timings.fullPipeline)s")
print("Audio duration: \(result.timings.inputAudioSeconds)s")

// Log detailed breakdown
result.logTimings()
```

### Quality Filtering

```swift theme={null}
// Filter out low-quality segments
let highQualitySegments = result.segments.filter { segment in
    segment.avgLogprob > -0.5 &&  // Good confidence
    segment.noSpeechProb < 0.3 &&  // Low silence probability
    segment.compressionRatio < 2.0  // Not repetitive
}

for segment in highQualitySegments {
    print(segment.text)
}
```

### Export to SRT Format

```swift theme={null}
func exportToSRT(result: TranscriptionResult) -> String {
    var srt = ""
    
    for (index, segment) in result.segments.enumerated() {
        let startTime = formatTimestamp(segment.start)
        let endTime = formatTimestamp(segment.end)
        
        srt += "\(index + 1)\n"
        srt += "\(startTime) --> \(endTime)\n"
        srt += "\(segment.text.trimmingCharacters(in: .whitespaces))\n\n"
    }
    
    return srt
}

func formatTimestamp(_ seconds: Float) -> String {
    let hours = Int(seconds) / 3600
    let minutes = (Int(seconds) % 3600) / 60
    let secs = Int(seconds) % 60
    let millis = Int((seconds - Float(Int(seconds))) * 1000)
    
    return String(format: "%02d:%02d:%02d,%03d", hours, minutes, secs, millis)
}

// Usage
let srtContent = exportToSRT(result: results.first!)
print(srtContent)
```

### Monitor Progress

```swift theme={null}
let results = try await whisperKit.transcribe(
    audioPath: "/path/to/audio.wav"
) { progress in
    print("Current text: \(progress.text)")
    print("Tokens: \(progress.tokens.count)")
    if let temp = progress.temperature {
        print("Temperature: \(temp)")
    }
    return true  // Continue
}
```
