मुख्य कंटेंट तक स्किप करें

AI टेक्स्ट अनुवाद

टेक्स्ट को स्रोत भाषा से लक्ष्य भाषा में अनुवाद करें और बनता हुआ अनुवाद क्रमशः प्राप्त करें।

आवश्यक शर्तें

  • AIBudsAISDK initialize हो और कोई registered provider चुना गया हो।
  • Provider AITextTranslationServiceAPI support करता हो।
  • 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
import AIBudsAI

Declaration

Swift
/// 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()

translateText और cancelTextTranslation देखें।

उपयोग के उदाहरण

Swift
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
    }
}

ध्यान देने योग्य बातें

  • Source और target के लिए एक ही स्पष्ट भाषा न दें। भाषा अपने-आप पहचाननी हो तो source string खाली रखें।
  • अनुवाद का टेक्स्ट क्रमशः आता है और पहले दिखाए गए परिणाम को बदल सकता है।
  • यह API केवल टेक्स्ट का अनुवाद करती है। लगातार बोले जा रहे ऑडियो के अनुवाद के लिए Simultaneous Interpretation उपयोग करें।
  • cancelTextTranslation() में completion callback नहीं है; cancel request भेजते समय local state भी update करें।