동시통역
장시간 실행되는 음성 동시통역 세션을 시작하고 실시간 원문, 번역문, 선택적 TTS 오디오, 이벤트, 최종 보고서를 받습니다.
SimultaneousInterpretationEventType 수명 주기와 onEvent에서의 사용 방법은 AI 세션 이벤트를 참고하세요.
동시통역 세션 수명 주기
서비스 제공자 시작, 활성 오디오 입력, 순서가 있는 실시간 결과, 중단 처리, 최종 종료를 함께 관리합니다.
사전 요구 사항
AIBudsAISDK가 초기화되어 있고 등록된 서비스 제공자가 선택 및 인증되어 있습니다.- 서비스 제공자가
SimultaneousInterpretationServiceAPI를 지원합니다. - 원문 언어와 번역 언어 식별자는 하이픈 형식을 사용하며 서로 달라야 합니다.
- AIBuds AI SDK 내부 녹음이 꺼져 있으면 호스트 앱이 외부 PCM을 제공합니다. 연결된 기기에서 오디오를 받는다면 기기가
DeviceAudioRecordingAPI를 준수해야 합니다.
AI를 활용해 구현
AI로 이 워크플로 구현
공식 “AIBuds 동시통역 구현” 스킬을 사용해 앱에 맞게 구현하세요.
https://docs-aibuds.github.io/ko/skills/implement-aibuds-simultaneous-interpretation을 읽고 지침을 따르세요. 이 스킬로 “AIBuds 동시통역 구현”을 이 iOS 프로젝트에 구현하고 검증하세요.API Reference
프레임워크
AIBudsAI.xcframework
Import
- Swift
- Objective-C
import AIBuds
import AIBudsAI
import AIBudsAIFoundation#import <AIBuds/AIBuds-Swift.h>
#import <AIBudsAI/AIBudsAI-Swift.h>선언
- Swift
- Objective-C
/// Starts a simultaneous interpretation session.
/// - Parameters:
/// - config: The session configuration.
/// - onStartSuccess: Called with the started session.
/// - onStartFailure: Called when the session cannot start.
/// - onStopByInterruption: Called when an interruption stops the session.
/// - onException: Called for a recoverable session exception. The app decides
/// whether the session should stop.
/// - streamResultHandler: Called with incremental interpretation results.
/// - onEvent: Called for session-level events.
/// - onFinish: Called with the optional final report.
public static func startSimultaneousInterpretation(_ config: SimultaneousInterpretationConfig = .default,
onStartSuccess: ((_ session: SimultaneousInterpretationSessionConvertible) -> Void)? = nil,
onStartFailure: ((_ error: NSError) -> Void)? = nil,
onStopByInterruption: ((_ error: NSError?) -> Void)? = nil,
onException: ((_ error: NSError) -> Void)? = nil,
streamResultHandler: ((
_ isFinal: Bool,
_ response: SimultaneousInterpretationDataModel?,
_ error: Error?
) -> Void)? = nil,
onEvent: ((_ event: SimultaneousInterpretationEventModel) -> Void)? = nil,
onFinish: ((_ report: SimultaneousInterpretationReportModel?) -> Void)? = nil)
/// Stops the current simultaneous interpretation session.
public static func stopSimultaneousInterpretation()/// Starts a simultaneous interpretation session.
/// - Parameters:
/// - config: The session configuration.
/// - onStartSuccess: Called with the started session.
/// - onStartFailure: Called when the session cannot start.
/// - onStopByInterruption: Called when an interruption stops the session.
/// - onException: Called for a recoverable session exception.
/// - streamResultHandler: Called with incremental interpretation results.
/// - onEvent: Called for session-level events.
/// - onFinish: Called with the optional final report.
+ (void)startSimultaneousInterpretationWithConfig:(AIBudsSimultaneousInterpretationConfig * _Nonnull)config
onStartSuccess:(void (^ _Nullable)(id <AIBudsSimultaneousInterpretationSessionConvertible> _Nonnull))onStartSuccess
onStartFailure:(void (^ _Nullable)(NSError * _Nonnull))onStartFailure
onStopByInterruption:(void (^ _Nullable)(NSError * _Nullable))onStopByInterruption
onException:(void (^ _Nullable)(NSError * _Nonnull))onException
streamResultHandler:(void (^ _Nullable)(BOOL, AIBudsSimultaneousInterpretationDataModel * _Nullable, NSError * _Nullable))streamResultHandler
onEvent:(void (^ _Nullable)(AIBudsSimultaneousInterpretationEventModel * _Nonnull))onEvent
onFinish:(void (^ _Nullable)(AIBudsSimultaneousInterpretationReportModel * _Nullable))onFinish;
/// Stops the current simultaneous interpretation session.
+ (void)stopSimultaneousInterpretation;startSimultaneousInterpretation과 stopSimultaneousInterpretation을 참고하세요.
설정
SimultaneousInterpretationConfig는 다음 설정을 제공합니다.
| 속성 | 기본값 | 설명 |
|---|---|---|
sourceLanguage | 앱 언어 | 선택적 원문 언어입니다. 빈 문자열이면 자동 감지를 사용합니다. |
targetLanguage | en-US | 필수 번역 언어입니다. |
enableTTS | true | 번역문을 음성으로 합성할지 여부입니다. |
enableVoicePlayback | true | 합성 음성 재생을 사용할지 여부입니다. |
usesInternalAudioRecording | true | 세션에서 AIBuds AI SDK 내부 녹음을 사용할지 여부입니다. |
preferSpeakerOutput | false | 스피커 출력을 우선할지 여부입니다. |
usesInternalAudioRecording이 false이면 AIBuds AI SDK가 세션 오디오를 녹음하지 않습니다. 호스트 앱은 반환된 세션을 유지하고 appendInt16PCM(_:isFinal:) 또는 appendAudioPCMBuffer(_:isFinal:)로 외부 PCM을 전달해야 합니다.
사용 예제
- Swift
- Objective-C
let config = SimultaneousInterpretationConfig.default
config.sourceLanguage = "zh-CN"
config.targetLanguage = "en-US"
config.usesInternalAudioRecording = true
config.preferSpeakerOutput = false
AIBudsAISDK.startSimultaneousInterpretation(
config,
onStartSuccess: { session in
currentSession = session
},
onStartFailure: { error in
print("Unable to start: \(error.localizedDescription)")
},
onStopByInterruption: { error in
print(error?.localizedDescription ?? "Session interrupted")
currentSession = nil
},
onException: { error in
print("Session exception: \(error.localizedDescription)")
},
streamResultHandler: { isFinal, response, error in
if let error {
print(error.localizedDescription)
return
}
guard let response else { return }
if response.isSourceTextDefinite {
print("Source: \(response.sourceText ?? "")")
}
if response.isTargetTextDefinite {
print("Target: \(response.targetText ?? "")")
}
if isFinal { print("Final result") }
},
onEvent: { event in
print(event)
},
onFinish: { report in
currentSession = nil
print(report ?? "No report")
}
)AIBudsSimultaneousInterpretationConfig *config =
[AIBudsSimultaneousInterpretationConfig defaultConfig];
config.sourceLanguage = @"zh-CN";
config.targetLanguage = @"en-US";
config.usesInternalAudioRecording = YES;
config.preferSpeakerOutput = NO;
[AIBudsAISDK startSimultaneousInterpretationWithConfig:config
onStartSuccess:^(id<AIBudsSimultaneousInterpretationSessionConvertible> session) {
self.currentSession = session;
}
onStartFailure:^(NSError *error) {
NSLog(@"Unable to start: %@", error.localizedDescription);
}
onStopByInterruption:^(NSError *error) {
NSLog(@"%@", error.localizedDescription ?: @"Session interrupted");
self.currentSession = nil;
}
onException:^(NSError *error) {
NSLog(@"Session exception: %@", error.localizedDescription);
}
streamResultHandler:^(
BOOL isFinal, AIBudsSimultaneousInterpretationDataModel *response, NSError *error) {
if (error != nil) {
NSLog(@"%@", error.localizedDescription);
return;
}
if (response.isSourceTextDefinite) {
NSLog(@"Source: %@", response.sourceText ?: @"");
}
if (response.isTargetTextDefinite) {
NSLog(@"Target: %@", response.targetText ?: @"");
}
}
onEvent:^(AIBudsSimultaneousInterpretationEventModel *event) {
NSLog(@"%@", event);
}
onFinish:^(AIBudsSimultaneousInterpretationReportModel *report) {
self.currentSession = nil;
NSLog(@"%@", report);
}];session.isRecordingInternally이 false이면 호스트 앱이 외부 오디오 경로를 관리합니다. Demo는 onStartSuccess 뒤 기기 AI 녹음을 시작하고 디코딩한 PCM 묶음을 session.appendInt16PCM(_:isFinal:)로 전달한 다음, 기기 녹음을 먼저 중지하고 AIBudsAISDK.stopSimultaneousInterpretation()을 호출합니다.
참고
- 시작 때 반환된
SimultaneousInterpretationSessionConvertible을 유지하여 활성 세션과 녹음 방식을 추적합니다. onException이 세션 중지를 뜻하지는 않습니다. 계속할지stopSimultaneousInterpretation()을 호출할지 결정하세요.- 모든 실시간 콜백을 그대로 이어 붙이지 말고
sourceTextSequence와targetTextSequence로 확정 구간의 순서를 정렬하세요. SimultaneousInterpretationDataModel의 TTS 오디오는 상대 파일 경로, 전체 파일 경로 또는 Base64 PCM 데이터로 제공될 수 있습니다.