텔레프롬프터 내용 및 설정
현재 슬롯을 확인하고 텔레프롬프터 텍스트를 전송하며, 슬롯 전환, 내용 삭제 및 공통 스크롤 속도 변경을 수행합니다.
사전 요구 사항
- 기기가 연결되어 있고
TeleprompterAPI를 준수합니다. - 선택한 슬롯 인덱스가
0...(overlayPromptTotalSlots - 1)범위에 있습니다. - 텍스트의 인코딩된 byte 크기가
capacityBytesOfCurrentOverlayPromptSlot이내입니다.
API 참고
프레임워크
AIBuds.xcframework
가져오기
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>프로토콜
- Swift
- Objective-C
/// Teleprompter API
protocol TeleprompterAPI: DeviceAPI {
/// The overlay prompt scroll speed; all slots share this value.
/// 100 is 1.0×, 150 is 1.5×, minimum 10 (0.1×), maximum 1000 (10×).
var overlayPromptScrollSpeed: NSNumber? { get }
/// The total number of overlay prompt slots.
var overlayPromptTotalSlots: NSNumber? { get }
/// The current zero-based overlay prompt slot index.
var overlayPromptSlotIndex: NSNumber? { get }
/// The current overlay prompt slot used bytes.
var usedBytesOfCurrentOverlayPromptSlot: NSNumber? { get }
/// The current overlay prompt slot capacity in bytes.
var capacityBytesOfCurrentOverlayPromptSlot: NSNumber? { get }
/// Sends an overlay prompt to the device.
/// - Parameters:
/// - prompt: The overlay prompt to send.
/// - progressHandler: Called when transfer progress changes.
/// - completionHandler: Called when the operation completes with success and an optional error.
func sendOverlayPrompt(
_ prompt: String,
progressHandler: (
(
_ progress: CGFloat
) -> Void
)?,
completionHandler: AIBudsCompletionHandler?
)
/// Clears the current overlay prompt slot content.
/// - Parameter completion: Called when the operation completes with success and an optional error.
func clearCurrentOverlayPromptSlotContent(_ completion: AIBudsCompletionHandler?)
/// Switches to the specified zero-based slot index.
/// - Parameters:
/// - index: A value from 0 through `overlayPromptTotalSlots - 1`.
/// - completion: Called when the operation completes with success and an optional error.
func toggleOverlayPromptSlotIndexTo(
_ index: Int,
completion: AIBudsCompletionHandler?
)
/// Sets the shared overlay prompt scroll speed.
/// - Parameters:
/// - speed: 10...1000, where 100 represents 1.0×.
/// - completion: Called when the operation completes with success and an optional error.
func setOverlayPromptScrollSpeed(
_ speed: Int,
completion: AIBudsCompletionHandler?
)
}/// Teleprompter API
@protocol AIBudsTeleprompterAPI <AIBudsDeviceAPI>
@property(nonatomic, readonly, strong) NSNumber *_Nullable overlayPromptScrollSpeed;
@property(nonatomic, readonly, strong) NSNumber *_Nullable overlayPromptTotalSlots;
@property(nonatomic, readonly, strong) NSNumber *_Nullable overlayPromptSlotIndex;
@property(nonatomic, readonly, strong) NSNumber *_Nullable usedBytesOfCurrentOverlayPromptSlot;
@property(nonatomic, readonly, strong) NSNumber *_Nullable capacityBytesOfCurrentOverlayPromptSlot;
/// Sends an overlay prompt to the device and reports transfer progress.
- (void)sendOverlayPrompt:(NSString *_Nonnull)prompt
progressHandler:(void (^_Nullable)(CGFloat))progressHandler
completionHandler:(AIBudsCompletionHandler _Nullable)completionHandler;
/// Clears the current overlay prompt slot content.
- (void)clearCurrentOverlayPromptSlotContentWithCompletion:
(AIBudsCompletionHandler _Nullable)completion;
/// Switches to a zero-based index from 0 through totalSlots - 1.
- (void)toggleOverlayPromptSlotIndexTo:(NSInteger)index
completion:(AIBudsCompletionHandler _Nullable)completion;
/// Sets the shared speed from 10 (0.1×) through 1000 (10×).
- (void)setOverlayPromptScrollSpeed:(NSInteger)speed
completion:(AIBudsCompletionHandler _Nullable)completion;
@end기호
| 기호 | 용도 |
|---|---|
sendOverlayPrompt | 진행률을 확인하면서 텍스트를 전송합니다. |
clearCurrentOverlayPromptSlotContent | 현재 슬롯을 비웁니다. |
toggleOverlayPromptSlotIndexTo | 슬롯을 전환합니다. |
setOverlayPromptScrollSpeed | 공통 스크롤 속도를 설정합니다. |
사용 예제
- Swift
- Objective-C
guard let device = device as? TeleprompterAPI else { return }
guard let capacity = device.capacityBytesOfCurrentOverlayPromptSlot?.intValue else {
print("Slot capacity unavailable")
return
}
let prompt = "Welcome to AIBuds"
guard prompt.lengthOfBytes(using: .utf8) <= capacity else {
print("Prompt exceeds the current slot capacity")
return
}
device.sendOverlayPrompt(
prompt,
progressHandler: { progress in
print("Transfer: \(Int(progress * 100))%")
}
) { success, error in
if !success { print(error?.localizedDescription ?? "Transfer failed") }
}
device.setOverlayPromptScrollSpeed(150, completion: nil) // 1.5×id<AIBudsTeleprompterAPI> device = (id<AIBudsTeleprompterAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsTeleprompterAPI)])
return;
NSString *prompt = @"Welcome to AIBuds";
NSInteger capacity = device.capacityBytesOfCurrentOverlayPromptSlot.integerValue;
if ([prompt lengthOfBytesUsingEncoding:NSUTF8StringEncoding] <= capacity) {
[device sendOverlayPrompt:prompt
progressHandler:^(CGFloat progress) {
NSLog(@"Transfer: %.0f%%", progress * 100);
}
completionHandler:^(BOOL success, NSError *_Nullable error) {
if (!success)
NSLog(@"Transfer failed: %@", error.localizedDescription);
}];
}
[device setOverlayPromptScrollSpeed:150 completion:nil]; // 1.5×오류 처리
명령을 보내기 전에 슬롯 인덱스, UTF-8 byte 길이 및 속도를 검증하세요. 전송에 실패하면 현재 슬롯을 유지하고 사용자가 다시 시도할 수 있게 하며, 일부만 전송된 텍스트를 사용할 수 있다고 가정하지 마세요.