# AudioRecord

    final class AudioRecord: Sendable

Continuously records microphone samples into a thread-safe circular buffer.
- `
  ### [maximumChannelCount](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/AudioRecord.md.txt#/s:20MediaPipeTasksCommon11AudioRecordC19maximumChannelCountSivpZ)

  ` Maximum supported audio channel count (`2`).

  #### Declaration

  Swift

      static let maximumChannelCount: Int

- `
  ### [init(audioDataFormat:bufferLength:)](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/AudioRecord.md.txt#/s:20MediaPipeTasksCommon11AudioRecordC15audioDataFormat12bufferLengthAcA0ehI0V_SitKcfc)

  ` Creates a microphone recorder backed by a ring buffer of capacity `bufferLength`.

  #### Declaration

  Swift

      init(audioDataFormat: AudioDataFormat, bufferLength: Int) throws

- `
  ### [audioDataFormat](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/AudioRecord.md.txt#/s:20MediaPipeTasksCommon11AudioRecordC15audioDataFormatAA0ehI0Vvp)

  ` Audio format specifying the channel count and sample rate of recorded samples.

  #### Declaration

  Swift

      final let audioDataFormat: AudioDataFormat

- `
  ### [bufferLength](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/AudioRecord.md.txt#/s:20MediaPipeTasksCommon11AudioRecordC12bufferLengthSivp)

  ` Maximum number of samples retained across all channels.

  #### Declaration

  Swift

      final let bufferLength: Int

- `
  ### [read(offset:length:)](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/AudioRecord.md.txt#/s:20MediaPipeTasksCommon11AudioRecordC4read6offset6lengthAA11FloatBufferCSi_SitKF)

  ` Reads `length` samples starting at `offset` from the oldest sample.

  #### Declaration

  Swift

      final func read(offset: Int, length: Int) throws -> FloatBuffer

- `
  ### [startRecording()](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/AudioRecord.md.txt#/s:20MediaPipeTasksCommon11AudioRecordC14startRecordingyyKF)

  ` Starts tapping microphone samples using `AVAudioEngine`.

  #### Declaration

  Swift

      final func startRecording() throws

- `
  ### [stop()](https://developers.google.com/edge/api/mediapipe/swift/common/Classes/AudioRecord.md.txt#/s:20MediaPipeTasksCommon11AudioRecordC4stopyyKF)

  ` Stops recording audio and clears buffered samples.

  #### Declaration

  Swift

      final func stop() throws