일반 녹음
연결된 기기에 일반 오디오 녹음 세션의 시작 또는 중지를 요청합니다.
사전 요구 사항
- 기기가 연결되어 사용할 수 있는 상태입니다.
- 기기가
DeviceAudioRecordingAPI를 준수합니다. - 기기에 녹음에 필요한 저장 공간이 충분합니다.
API 참고
프레임워크
AIBuds.xcframework
가져오기
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>프로토콜
요청은 DeviceAudioRecordingAPI에 정의되어 있습니다.
- Swift
- Objective-C
/// 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?)
}/// The protocol for device API that supports audio recording.
@protocol AIBudsDeviceAudioRecordingAPI <AIBudsDeviceAPI>
/// 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.
- (void)requestStartAudioRecordingWithCompletion:
(AIBudsStatusCodeCompletionHandler _Nullable)completion;
/// 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.
- (void)requestStopAudioRecordingWithCompletion:
(AIBudsStatusCodeCompletionHandler _Nullable)completion;
@end인스턴스 메서드
| 메서드 | 용도 |
|---|---|
requestStartAudioRecording | 기기에 녹음 시작을 요청합니다. |
requestStopAudioRecording | 기기에 녹음 중지를 요청합니다. |
Completion 값
| 이름 | 타입 | 설명 |
|---|---|---|
success | Bool / BOOL | 요청 성공 여부입니다. |
statusCode | NSNumber? | 기기가 반환한 상태 코드이며 작업에 실패하면 nil입니다. |
error | NSError? | 실패 상세 정보이며 성공하면 nil입니다. |
메서드는 녹음 파일 경로를 반환하지 않으며 결과는 기기 명령 상태입니다.
사용 예제
- Swift
- Objective-C
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")")
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceAudioRecordingAPI> device = (id<AIBudsDeviceAudioRecordingAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceAudioRecordingAPI)]) {
NSLog(@"Device does not support audio recording");
return;
}
[device requestStartAudioRecordingWithCompletion:^(
BOOL success, NSNumber *_Nullable statusCode, NSError *_Nullable error) {
if (!success) {
NSLog(@"Start failed: %@", error.localizedDescription);
return;
}
NSLog(@"Recording started, status: %@", statusCode);
}];
// Call this from the UI action that stops the active recording.
[device requestStopAudioRecordingWithCompletion:^(
BOOL success, NSNumber *_Nullable statusCode, NSError *_Nullable error) {
if (!success) {
NSLog(@"Stop failed: %@", error.localizedDescription);
return;
}
NSLog(@"Recording stopped, status: %@", statusCode);
}];오류 처리
success를 기본 결과로 사용하세요. 기기별 처리를 위해 반환된 statusCode를 보관하고 error가 있으면 표시하세요. 공개 프로토콜에는 개별 상태 코드의 의미가 정의되어 있지 않습니다.