Skip to main content

Standard Recording

Request the connected device to start or stop its standard audio recording session.

Prerequisites

  • The device is connected and ready.
  • The device conforms to DeviceAudioRecordingAPI.
  • The device has sufficient storage for the recording.

API Reference

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

Protocol

The requests are defined by DeviceAudioRecordingAPI.

Swift
/// The protocol for device API that supports audio recording.
protocol DeviceAudioRecordingAPI: DeviceAPI {
    /// Requests the device to start an audio recording session.
    /// - Parameters:
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - statusCode: The status code returned by the device. `nil` if the operation failed.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func requestStartAudioRecording(_ completion: AIBudsStatusCodeCompletionHandler?)

    /// Requests the device to stop the current audio recording session.
    /// - Parameters:
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - statusCode: The status code returned by the device. `nil` if the operation failed.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func requestStopAudioRecording(_ completion: AIBudsStatusCodeCompletionHandler?)
}

Instance Methods

MethodPurpose
requestStartAudioRecordingRequest the device to start recording.
requestStopAudioRecordingRequest the device to stop recording.

Completion Values

NameTypeDescription
successBool / BOOLWhether the request succeeded.
statusCodeNSNumber?Status code returned by the device, or nil if the operation failed.
errorNSError?Failure details, or nil on success.

The methods do not return a recording file path. The result is the device command status.

Usage Examples

Swift
import AIBuds

guard let device = device as? DeviceAudioRecordingAPI else {
    print("Device does not support audio recording")
    return
}

device.requestStartAudioRecording { success, statusCode, error in
    guard success else {
        print("Start failed: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("Recording started, status: \(statusCode?.stringValue ?? "Unavailable")")
}

// Call this from the UI action that stops the active recording.
device.requestStopAudioRecording { success, statusCode, error in
    guard success else {
        print("Stop failed: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("Recording stopped, status: \(statusCode?.stringValue ?? "Unavailable")")
}

Error Handling

Use success as the primary result. Preserve the returned statusCode for device-specific handling and surface error when available; the public protocol does not document the meaning of individual status-code values.