-
Notifications
You must be signed in to change notification settings - Fork 0
Ai Ai Text Translation
Mr.P edited this page Aug 29, 2026
·
2 revisions
Translate a text value from a source language to a target language and receive the translated text incrementally.
-
AIBudsAISDKis initialized and a registered provider is selected. - The provider supports
AITextTranslationServiceAPI. - The input text and target language are non-empty.
- Language identifiers use a hyphenated form such as
zh-CNanden-US; an empty source language enables automatic detection.
AIBudsAI.xcframework
import AIBudsAI#import <AIBudsAI/AIBudsAI-Swift.h>/// Translates text from one language to another.
/// - Parameters:
/// - text: The text to translate.
/// - sourceLanguage: Source language code. An empty string enables auto-detect.
/// - targetLanguage: Target language code.
/// - streamResultHandler: Called repeatedly with translation results.
/// - isFinal: `true` when translation is complete.
/// - transcript: The current incremental translated text.
/// - error: The translation error, or `nil` on success.
public static func translateText(_ text: String,
from sourceLanguage: String,
to targetLanguage: String,
streamResultHandler: ((_ isFinal: Bool, _ transcript: String?, _ error: Error?) -> Void)? = nil)
/// Cancels the current text translation operation.
public static func cancelTextTranslation()/// Translates text from one language to another.
/// - Parameters:
/// - text: The text to translate.
/// - sourceLanguage: Source language code. An empty string enables auto-detect.
/// - targetLanguage: Target language code.
/// - streamResultHandler: Called repeatedly with translation results.
/// - isFinal: `YES` when translation is complete.
/// - transcript: The current incremental translated text.
/// - error: The translation error, or `nil` on success.
+ (void)translateText:(NSString * _Nonnull)text
from:(NSString * _Nonnull)sourceLanguage
to:(NSString * _Nonnull)targetLanguage
streamResultHandler:(void (^ _Nullable)(BOOL, NSString * _Nullable, NSError * _Nullable))streamResultHandler;
/// Cancels the current text translation operation.
+ (void)cancelTextTranslation;See translateText and cancelTextTranslation.
AIBudsAISDK.translateText(
"你好,欢迎使用 AIBuds SDK。",
from: "zh-CN",
to: "en-US"
) { isFinal, transcript, error in
DispatchQueue.main.async {
if let error {
translationLabel.text = error.localizedDescription
return
}
if let transcript {
translationLabel.text = transcript
}
translateButton.isEnabled = isFinal
}
}[AIBudsAISDK translateText:@"你好,欢迎使用 AIBuds SDK。"
from:@"zh-CN"
to:@"en-US"
streamResultHandler:^(BOOL isFinal, NSString *transcript, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error != nil) {
self.translationLabel.text = error.localizedDescription;
return;
}
if (transcript != nil) {
self.translationLabel.text = transcript;
}
self.translateButton.enabled = isFinal;
});
}];- Do not use the same explicit source and target language. Use an empty source string when auto-detection is required.
- The transcript is incremental and can replace the previous displayed result.
- This API translates text only. For continuous spoken translation, use Simultaneous Interpretation.
-
cancelTextTranslation()has no completion callback; update local state when cancellation is requested.
AIBuds SDK documentation · Full documentation · API Reference
- Introduction
- Getting Started
- Core Concepts
-
Core Features
- Basic Features
- Device Info
- Find Device
- Physical Operations
- Work Mode
- Work Status
- Wear Detection
- Volume Control
- Music Control
- TWS
- Equalizer
- ANC
- Audio
- Camera
- Remote Camera
- File Import
- Teleprompter
- Segment Navigation
- Live Streaming
- Device Applications
- OTA
- Camera OTA
- Service Auth
- AI Services
- Voice Assistant
- Logging
- Advanced Topics
- Releases
- Troubleshooting