AI 오디오 녹음
특정 RecordingScene에 맞춰 AI 오디오 녹음을 시작하고 중지합니다.
사전 요구 사항
- 기기가 연결되어 사용할 수 있는 상태입니다.
- 기기가
DeviceAudioRecordingAPI를 준수합니다. - 녹음을 중지할 때 시작할 때와 같은 scene을 사용합니다.
API 참고
프레임워크
AIBuds.xcframework
가져오기
- Swift
- Objective-C
import AIBuds
import AIBudsFoundation#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>프로토콜
- Swift
- Objective-C
/// 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?
)
}/// The protocol for device API that supports audio recording.
@protocol AIBudsDeviceAudioRecordingAPI <AIBudsDeviceAPI>
/// 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.
- (void)startAIAudioRecordingWithScene:(enum AIBudsRecordingScene)scene
completion:(AIBudsCompletionHandler _Nullable)completion;
/// 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.
- (void)stopAIAudioRecordingWithScene:(enum AIBudsRecordingScene)scene
completion:(AIBudsCompletionHandler _Nullable)completion;
@end인스턴스 메서드
| 메서드 | 용도 |
|---|---|
startAIAudioRecording | 지정한 scene의 AI 녹음을 시작합니다. |
stopAIAudioRecording | 해당 scene의 AI 녹음을 중지합니다. |
녹음 Scene
| Swift | Objective-C | 설명 |
|---|---|---|
.onSite | AIBudsRecordingSceneOnSite | 주변 환경 또는 현장 녹음입니다. |
.call | AIBudsRecordingSceneCall | 전화 통화 중 녹음입니다. |
completion handler는 success와 선택적 NSError를 보고합니다. 이 메서드는 음성 인식 텍스트나 녹음 파일 경로를 반환하지 않습니다.
사용 예제
- Swift
- Objective-C
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")
}
}#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;
}
AIBudsRecordingScene scene = AIBudsRecordingSceneOnSite;
[device startAIAudioRecordingWithScene:scene
completion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"AI recording failed to start: %@",
error.localizedDescription);
return;
}
NSLog(@"AI recording started");
}];
// Stop using the same scene.
[device stopAIAudioRecordingWithScene:scene
completion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"AI recording failed to stop: %@",
error.localizedDescription);
}
}];오류 처리
중지 요청에 같은 scene을 전달할 수 있도록 앱에서 활성 scene을 추적하세요. 콜백이 실패하면 기기가 다음 녹음 상태 변경을 보고할 때까지 UI를 안전한 상태로 유지하세요.