본문으로 건너뛰기

AI 오디오 녹음

특정 RecordingScene에 맞춰 AI 오디오 녹음을 시작하고 중지합니다.

사전 요구 사항

  • 기기가 연결되어 사용할 수 있는 상태입니다.
  • 기기가 DeviceAudioRecordingAPI를 준수합니다.
  • 녹음을 중지할 때 시작할 때와 같은 scene을 사용합니다.

API 참고

프레임워크

AIBuds.xcframework

가져오기

Swift
import AIBuds
import AIBudsFoundation

프로토콜

Swift
/// The protocol for device API that supports audio recording.
protocol DeviceAudioRecordingAPI: DeviceAPI {
    /// Starts an AI audio recording for the specified scene.
    /// - Parameters:
    ///   - scene: The recording scenario context.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func startAIAudioRecording(
        _ scene: RecordingScene,
        completion: AIBudsCompletionHandler?
    )

    /// Stops the AI audio recording for the specified scene.
    /// - Parameters:
    ///   - scene: The recording scenario context.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func stopAIAudioRecording(
        _ scene: RecordingScene,
        completion: AIBudsCompletionHandler?
    )
}

인스턴스 메서드

메서드용도
startAIAudioRecording지정한 scene의 AI 녹음을 시작합니다.
stopAIAudioRecording해당 scene의 AI 녹음을 중지합니다.

녹음 Scene

SwiftObjective-C설명
.onSiteAIBudsRecordingSceneOnSite주변 환경 또는 현장 녹음입니다.
.callAIBudsRecordingSceneCall전화 통화 중 녹음입니다.

completion handler는 success와 선택적 NSError를 보고합니다. 이 메서드는 음성 인식 텍스트나 녹음 파일 경로를 반환하지 않습니다.

사용 예제

Swift
import AIBuds

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

let scene: RecordingScene = .onSite
device.startAIAudioRecording(scene) { success, error in
    guard success else {
        print("AI recording failed to start: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("AI recording started")
}

// Stop using the same scene.
device.stopAIAudioRecording(scene) { success, error in
    if !success {
        print(error?.localizedDescription ?? "AI recording failed to stop")
    }
}

오류 처리

중지 요청에 같은 scene을 전달할 수 있도록 앱에서 활성 scene을 추적하세요. 콜백이 실패하면 기기가 다음 녹음 상태 변경을 보고할 때까지 UI를 안전한 상태로 유지하세요.