समकालिक व्याख्या
लंबा spoken-language interpretation session शुरू करें और क्रमशः source text, translated text, optional TTS audio, events तथा अंतिम report पाएँ।
SimultaneousInterpretationEventType lifecycle समझने के लिए AI Session Events देखें, जिसका उपयोग onEvent करता है।
Interpretation session lifecycle
Provider startup, active audio source, क्रमबद्ध incremental results, interruption handling और final shutdown coordinate करें।
आवश्यक शर्तें
AIBudsAISDKinitialize हो और registered provider चुना तथा authenticated हो।- Provider
SimultaneousInterpretationServiceAPIsupport करता हो। - Source और target language identifiers hyphenated format में हों और समान न हों।
- AIBuds AI SDK की internal recording बंद होने पर host app external PCM देता है। Audio जुड़े डिवाइस से आता हो तो वह
DeviceAudioRecordingAPIको conform करता है।
AI की सहायता से लागू करें
इस वर्कफ़्लो को AI से लागू करें
आधिकारिक “AIBuds समकालिक अनुवाद लागू करें” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।
https://docs-aibuds.github.io/hi/skills/implement-aibuds-simultaneous-interpretation को पढ़ें और निर्देशों का पालन करें। इस स्किल से “AIBuds समकालिक अनुवाद लागू करें” को इस iOS प्रोजेक्ट में लागू करें और परिणाम सत्यापित करें।API Reference
Framework
AIBudsAI.xcframework
Import
- Swift
- Objective-C
import AIBuds
import AIBudsAI
import AIBudsAIFoundation#import <AIBuds/AIBuds-Swift.h>
#import <AIBudsAI/AIBudsAI-Swift.h>Declaration
- 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 ये settings देता है:
| प्रॉपर्टी | Default | विवरण |
|---|---|---|
sourceLanguage | App language | Optional source language; empty string auto-detection चालू करती है। |
targetLanguage | en-US | आवश्यक target language। |
enableTTS | true | Translated speech synthesize होगी या नहीं। |
enableVoicePlayback | true | Synthesized voice playback चालू है या नहीं। |
usesInternalAudioRecording | true | AIBuds AI SDK session के लिए audio record करता है या नहीं। |
preferSpeakerOutput | false | Speaker output को प्राथमिकता देनी है या नहीं। |
usesInternalAudioRecording के false होने पर AIBuds AI SDK session का audio capture नहीं करता। Host app को मिला session बनाए रखना और appendInt16PCM(_:isFinal:) या appendAudioPCMBuffer(_:isFinal:) से external 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 होने पर external audio path host app संभालता है। Demo onStartSuccess के बाद device-side AI recording शुरू करता है, हर decoded PCM batch को session.appendInt16PCM(_:isFinal:) भेजता है, पहले device recording रोकता है और फिर AIBudsAISDK.stopSimultaneousInterpretation() call करता है।
ध्यान देने योग्य बातें
- Active session और recording mode track करने के लिए startup पर मिला
SimultaneousInterpretationSessionConvertibleबनाए रखें। onExceptionजरूरी नहीं कि session रोक दे। तय करें कि जारी रखना है याstopSimultaneousInterpretation()call करना है।- हर incremental callback सीधे जोड़ने के बजाय निश्चित segments को क्रम देने के लिए
sourceTextSequenceऔरtargetTextSequenceउपयोग करें। - TTS audio
SimultaneousInterpretationDataModelमें relative file, full file path या Base64 PCM data के रूप में मिल सकता है।