# AudioTranscriber

    class AudioTranscriber: NSObject

Performs automatic speech recognition (ASR) on streaming mono PCM float audio samples.
- `
  ### [init(modelPath:)](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/AudioTranscriber.md.txt#/c:objc(cs)MPPAudioTranscriber(im)initWithModelPath:error:)

  ` Creates a new instance of `MPPAudioTranscriber` from an absolute path to a model asset bundle stored locally on the device and the default `MPPAudioTranscriberOptions`.

  #### Declaration

  Swift

      convenience init(modelPath: String) throws

  #### Parameters

  |---|---|
  | `modelPath` | An absolute path to a model file stored locally on the device. |
  | `error` | An optional error parameter populated when there is an error in initializing the audio transcriber. |

  #### Return Value

  A new instance of `MPPAudioTranscriber` with the given model path. `nil` if there is an error in initializing the audio transcriber.
- `
  ### [init(options:)](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/AudioTranscriber.md.txt#/c:objc(cs)MPPAudioTranscriber(im)initWithOptions:error:)

  ` Creates a new instance of `MPPAudioTranscriber` from the given `MPPAudioTranscriberOptions`.

  #### Declaration

  Swift

      init(options: AudioTranscriberOptions) throws

  #### Parameters

  |---|---|
  | `options` | The options of type `MPPAudioTranscriberOptions` to use for configuring the `MPPAudioTranscriber`. |
  | `error` | An optional error parameter populated when there is an error in initializing the audio transcriber. |

  #### Return Value

  A new instance of `MPPAudioTranscriber` with the given options. `nil` if there is an error in initializing the audio transcriber.
- `
  ### [close()](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/AudioTranscriber.md.txt#/c:objc(cs)MPPAudioTranscriber(im)closeWithError:)

  ` Releases underlying inference engine and processor resources.

  #### Declaration

  Swift

      func close() throws

  #### Parameters

  |---|---|
  | `error` | An optional error parameter populated when closing fails. |

  #### Return Value

  `YES` if the `MPPAudioTranscriber` was successfully closed, `NO` otherwise.
- `
  ### [finishStream()](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/AudioTranscriber.md.txt#/c:objc(cs)MPPAudioTranscriber(im)finishStreamWithError:)

  ` Flushes any remaining buffered audio and finalizes the current stream.

  #### Declaration

  Swift

      func finishStream() throws -> AudioTranscriberResult

  #### Parameters

  |---|---|
  | `error` | An optional error parameter populated when there is an error finalizing the stream. |

  #### Return Value

  An `MPPAudioTranscriberResult` containing any final emitted segments, or `nil` on error.
- `
  ### [prewarm()](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/AudioTranscriber.md.txt#/c:objc(cs)MPPAudioTranscriber(im)prewarmWithError:)

  ` Prewarms the underlying inference engine to reduce first-chunk latency.

  #### Declaration

  Swift

      func prewarm() throws

  #### Parameters

  |---|---|
  | `error` | An optional error parameter populated when prewarming fails. |

  #### Return Value

  `YES` if prewarming succeeded, `NO` otherwise.
- `
  ### [transcribe(samples:count:endOfStream:)](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/AudioTranscriber.md.txt#/c:objc(cs)MPPAudioTranscriber(im)transcribeFloatBuffer:length:endOfStream:error:)

  ` Transcribes a contiguous buffer of mono PCM float audio samples in `[-1.0, 1.0]`.

  #### Declaration

  Swift

      func transcribe(samples: UnsafePointer<Float>?, count length: UInt, endOfStream: Bool) throws -> AudioTranscriberResult

  #### Parameters

  |---|---|
  | `samples` | Pointer to a contiguous array of mono PCM float audio samples. |
  | `length` | Number of float samples in `samples`. |
  | `endOfStream` | Whether this chunk marks the end of the audio stream. |
  | `error` | An optional error parameter populated when there is an error during transcription. |

  #### Return Value

  An `MPPAudioTranscriberResult` containing any emitted segments, or `nil` on error.
- `
  ### [transcribe(samples:endOfStream:)](https://developers.google.com/edge/api/mediapipe/swift/audio/Classes/AudioTranscriber.md.txt#/c:objc(cs)MPPAudioTranscriber(im)transcribeSamples:endOfStream:error:)

  ` Transcribes an array of mono PCM float audio samples in `[-1.0, 1.0]`.

  #### Declaration

  Swift

      func transcribe(samples: [NSNumber], endOfStream: Bool) throws -> AudioTranscriberResult

  #### Parameters

  |---|---|
  | `samples` | Array of `NSNumber` float values representing mono PCM audio samples. |
  | `endOfStream` | Whether this chunk marks the end of the audio stream. |
  | `error` | An optional error parameter populated when there is an error during transcription. |

  #### Return Value

  An `MPPAudioTranscriberResult` containing any emitted segments, or `nil` on error.