AI 서비스 제공자 선택
앱에 포함한 AI 서비스 제공자 SDK를 등록한 뒤, 이후 AI 작업에서 AIBudsAISDK가 사용할 제공자를 선택합니다.
사전 요구 사항
- 기본 AIBuds SDK가 초기화되어 있습니다.
- 앱에 서비스 제공자 SDK가 하나 이상 설치되고 링크되어 있습니다.
- 선택할 제공자가
AIBudsAISDK.initialize(_:)에 전달한 배열에 포함되어 있습니다. - 서비스 제공자 인증이나 기기 연동 AI 작업 전에 기기 정보가 설정되어 있습니다.
AI를 활용해 구현
AI로 구현
AI로 이 워크플로 구현
공식 “AIBuds AI 제공자 선택” 스킬을 사용해 앱에 맞게 구현하세요.
https://docs-aibuds.github.io/ko/skills/select-aibuds-ai-provider을 읽고 지침을 따르세요. 이 스킬로 “AIBuds AI 제공자 선택”을 이 iOS 프로젝트에 구현하고 검증하세요.API Reference
프레임워크
AIBudsAI.xcframework
서비스 제공자 구현은 AIBudsStarBurst.xcframework, AIBudsMagicHelper.xcframework처럼 별도로 배포됩니다.
Import
- Swift
- Objective-C
import AIBudsAI
import AIBudsAIFoundation
import AIBudsStarBurst
import AIBudsMagicHelper#import <AIBudsAI/AIBudsAI-Swift.h>
#import <AIBudsMagicHelper/AIBudsMagicHelper-Swift.h>
#import <AIBudsStarBurst/AIBudsStarBurst-Swift.h>선언
서비스 제공자 수명 주기는 AIBudsAISDK에서 관리합니다. 제공자 구현은 AIConnectSDK을 준수합니다.
- Swift
- Objective-C
/// Initializes the SDK with the specified provider implementations.
/// - Parameter aiSDKs: The providers to register. Their order determines
/// recognition priority; a later provider using an already-registered
/// Bluetooth data protocol type is ignored.
/// - Returns: `true` when initialization succeeds; otherwise `false`.
public static func initialize( _ aiSDKs: [AIConnectSDK] ) -> Bool
/// The current AI service vendor.
static var aiServiceVendor: AIServiceVendor { get }
/// Sets the AI service vendor for the SDK.
/// - Parameter aiServiceVendor: The vendor used by subsequent AI services.
/// - Important: Call this method before using AI service-dependent functionality.
public static func setAIServiceVendor(_ aiServiceVendor: AIServiceVendor) -> Void
/// Returns all languages supported by the specified vendor.
/// - Parameter vendor: The vendor whose languages are requested.
/// - Returns: Supported languages, or an empty array when the vendor is `.none`
/// or its provider SDK is not registered.
public static func allSupportedLanguages(for vendor: AIServiceVendor) -> [AIServiceLanguage]
/// Returns the authentication initiation mode for the specified vendor.
/// - Parameter vendor: The vendor whose authentication mode is requested.
/// - Returns: The provider authentication mode.
public static func authenticationMode(for vendor: AIServiceVendor) -> AIAuthenticationMode
/// Indicates whether the device is authenticated for the specified vendor.
/// - Parameter vendor: The vendor whose authentication state is requested.
/// - Returns: `true` when the provider reports an authenticated device.
public static func isAuthenticated(for vendor: AIServiceVendor) -> Bool/// Initializes the SDK with the specified provider implementations.
/// - Parameter aiSDKs: The providers to register. Their order determines
/// recognition priority; a later provider using an already-registered
/// Bluetooth data protocol type is ignored.
/// - Returns: `YES` when initialization succeeds; otherwise `NO`.
+ (BOOL)initWithAISDKs:(NSArray<id <AIBudsAIConnectSDK>> * _Nonnull)aiSDKs;
/// The current AI service vendor.
@property(nonatomic, class, readonly) AIBudsAIServiceVendor aiServiceVendor;
/// Sets the AI service vendor for the SDK.
/// - Parameter aiServiceVendor: The vendor used by subsequent AI services.
/// - Important: Call this method before using AI service-dependent functionality.
+ (void)setAIServiceVendor:(enum AIBudsAIServiceVendor)aiServiceVendor;
/// Returns all languages supported by the specified vendor.
/// - Parameter vendor: The vendor whose languages are requested.
/// - Returns: Supported languages, or an empty array when the vendor is
/// `AIBudsAIServiceVendorNone` or its provider SDK is not registered.
+ (NSArray<AIBudsAIServiceLanguage *> * _Nonnull)allSupportedLanguagesForVendor:(enum AIBudsAIServiceVendor)vendor;
/// Returns the authentication initiation mode for the specified vendor.
/// - Parameter vendor: The vendor whose authentication mode is requested.
/// - Returns: The provider authentication mode.
+ (enum AIBudsAIAuthenticationMode)authenticationModeForVendor:(enum AIBudsAIServiceVendor)vendor;
/// Indicates whether the device is authenticated for the specified vendor.
/// - Parameter vendor: The vendor whose authentication state is requested.
/// - Returns: `YES` when the provider reports an authenticated device.
+ (BOOL)isAuthenticatedForVendor:(enum AIBudsAIServiceVendor)vendor;서비스 제공자
| Swift | Objective-C | 설명 |
|---|---|---|
.none | AIBudsAIServiceVendorNone | 선택한 제공자가 없는 기본 상태입니다. |
.starBurst | AIBudsAIServiceVendorStarBurst | StarBurst AI(ByteDance)입니다. |
.mltcloud | AIBudsAIServiceVendorMltcloud | MltCloud AI(Meilc)입니다. |
정확한 열거형 정의는 AIServiceVendor을 참고하세요.
사용 예제
서비스 제공자 SDK 등록
서비스 제공자는 일반적으로 앱 시작 중 한 번만 등록합니다.
- Swift
- Objective-C
import AIBudsAI
import AIBudsStarBurst
import AIBudsMagicHelper
let initialized = AIBudsAISDK.initialize([
StarBurstSDK.shared,
MagicHelperSDK.shared,
])
guard initialized else {
print("AIBudsAISDK initialization failed")
return
}#import <AIBudsAI/AIBudsAI-Swift.h>
#import <AIBudsMagicHelper/AIBudsMagicHelper-Swift.h>
#import <AIBudsStarBurst/AIBudsStarBurst-Swift.h>
BOOL initialized = [AIBudsAISDK initWithAISDKs:@[
[AIBudsStarBurstSDK shared],
[AIBudsMagicHelperSDK shared],
]];
if (!initialized) {
NSLog(@"AIBudsAISDK initialization failed");
return;
}앱에서 AIBudsAllInOneSDK를 사용하면 초기화 과정에서 번들 AI 서비스 제공자를 설치할 수 있습니다. AIBudsAISDK를 다시 초기화하지 마세요.
서비스 제공자 선택
- Swift
- Objective-C
let vendor: AIServiceVendor = .starBurst
AIBudsAISDK.setAIServiceVendor(vendor)
print("Selected provider: \(AIBudsAISDK.aiServiceVendor)")
print("Supported languages: \(AIBudsAISDK.allSupportedLanguages(for: vendor))")AIBudsAIServiceVendor vendor = AIBudsAIServiceVendorStarBurst;
[AIBudsAISDK setAIServiceVendor:vendor];
NSLog(@"Selected provider: %ld", (long)AIBudsAISDK.aiServiceVendor);
NSLog(@"Supported languages: %@", [AIBudsAISDK allSupportedLanguagesForVendor:vendor]);인증 필요 여부 확인
연결된 기기의 AI 정보를 설정한 뒤, 앱에서 인증을 시작해야 하는 서비스 제공자를 인증합니다.
- Swift
- Objective-C
let vendor = AIBudsAISDK.aiServiceVendor
if AIBudsAISDK.authenticationMode(for: vendor) == .appInitiated,
!AIBudsAISDK.isAuthenticated(for: vendor)
{
AIBudsAISDK.authenticateDevice(deviceInfo) { success, error in
guard success else {
print(error?.localizedDescription ?? "Authentication failed")
return
}
print("AI provider authenticated")
}
}AIBudsAIServiceVendor vendor = AIBudsAISDK.aiServiceVendor;
if ([AIBudsAISDK authenticationModeForVendor:vendor] == AIBudsAIAuthenticationModeAppInitiated &&
![AIBudsAISDK isAuthenticatedForVendor:vendor]) {
[AIBudsAISDK
authenticateDevice:deviceInfo
completion:^(BOOL success, NSError *error) {
if (!success) {
NSLog(@"%@", error.localizedDescription ?: @"Authentication failed");
return;
}
NSLog(@"AI provider authenticated");
}];
}참고
setAIServiceVendor(_:)는 서비스 제공자 SDK를 등록하거나 설치하지 않습니다..none을 선택하면 AI 서비스에 의존하는 작업에서 사용할 제공자가 없습니다.initialize(_:)를 두 번 이상 호출하면false를 반환하고 기존 초기화 상태를 유지합니다.- 여러 구현이 같은 제공자 열거형 값을 선언하면 먼저 등록한 구현을 유지합니다.
- 지원 기능과 언어는 서비스 제공자마다 다를 수 있습니다.