AI टेक्स्ट अनुवाद
टेक्स्ट को स्रोत भाषा से लक्ष्य भाषा में अनुवाद करें और बनता हुआ अनुवाद क्रमशः प्राप्त करें।
आवश्यक शर्तें
AIBudsAISDKinitialize हो और कोई registered provider चुना गया हो।- Provider
AITextTranslationServiceAPIsupport करता हो। - Input text और target language खाली न हों।
- Language identifier
zh-CNऔरen-USजैसे hyphenated format में दें; source language खाली रखने पर भाषा अपने-आप पहचानी जाती है।
AI की सहायता से लागू करें
AI से बनाएँ
इस वर्कफ़्लो को AI से लागू करें
आधिकारिक “AIBuds टेक्स्ट अनुवाद लागू करें” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।
https://docs-aibuds.github.io/hi/skills/implement-aibuds-text-translation को पढ़ें और निर्देशों का पालन करें। इस स्किल से “AIBuds टेक्स्ट अनुवाद लागू करें” को इस iOS प्रोजेक्ट में लागू करें और परिणाम सत्यापित करें।API Reference
Framework
AIBudsAI.xcframework
Import
- Swift
- Objective-C
import AIBudsAI#import <AIBudsAI/AIBudsAI-Swift.h>Declaration
- Swift
- Objective-C
/// 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;translateText और cancelTextTranslation देखें।
उपयोग के उदाहरण
- Swift
- Objective-C
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;
});
}];ध्यान देने योग्य बातें
- Source और target के लिए एक ही स्पष्ट भाषा न दें। भाषा अपने-आप पहचाननी हो तो source string खाली रखें।
- अनुवाद का टेक्स्ट क्रमशः आता है और पहले दिखाए गए परिणाम को बदल सकता है।
- यह API केवल टेक्स्ट का अनुवाद करती है। लगातार बोले जा रहे ऑडियो के अनुवाद के लिए Simultaneous Interpretation उपयोग करें।
cancelTextTranslation()में completion callback नहीं है; cancel request भेजते समय local state भी update करें।