본문으로 건너뛰기

일반 녹음

연결된 기기에 일반 오디오 녹음 세션의 시작 또는 중지를 요청합니다.

사전 요구 사항​

  • 기기가 연결되어 사용할 수 있는 상태입니다.
  • 기기가 DeviceAudioRecordingAPI를 준수합니다.
  • 기기에 녹음에 필요한 저장 공간이 충분합니다.

API 참고​

프레임워크​

AIBuds.xcframework

가져오기​

Swift
import AIBuds

프로토콜​

요청은 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?)
}

인스턴스 메서드​

메서드용도
requestStartAudioRecording기기에 녹음 시작을 요청합니다.
requestStopAudioRecording기기에 녹음 중지를 요청합니다.

Completion 값​

이름타입설명
successBool / BOOL요청 성공 여부입니다.
statusCodeNSNumber?기기가 반환한 상태 코드이며 작업에 실패하면 nil입니다.
errorNSError?실패 상세 정보이며 성공하면 nil입니다.

메서드는 녹음 파일 경로를 반환하지 않으며 결과는 기기 명령 상태입니다.

사용 예제​

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")")
}

오류 처리​

success를 기본 결과로 사용하세요. 기기별 처리를 위해 반환된 statusCode를 보관하고 error가 있으면 표시하세요. 공개 프로토콜에는 개별 상태 코드의 의미가 정의되어 있지 않습니다.