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

टेक्स्ट से आवाज़

चुने गए AI provider से टेक्स्ट को आवाज़ में बदलें और local audio file पाएँ, जिसे app चला या आगे process कर सकता है।

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

  • AIBudsAISDK initialize हो और registered provider चुना गया हो।
  • Provider TTSServiceAPI support करता हो।
  • ज़रूरत पड़ने पर provider authentication और network access उपलब्ध हों।
  • Public SDK contract के अनुसार synthesis को background thread से call करें।

AI की सहायता से लागू करें

AI से बनाएँ

इस वर्कफ़्लो को AI से लागू करें

आधिकारिक “AIBuds टेक्स्ट-टू-स्पीच लागू करें” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।

https://docs-aibuds.github.io/hi/skills/implement-aibuds-text-to-speech को पढ़ें और निर्देशों का पालन करें। इस स्किल से “AIBuds टेक्स्ट-टू-स्पीच लागू करें” को इस iOS प्रोजेक्ट में लागू करें और परिणाम सत्यापित करें।
आधिकारिक स्किल देखें

API Reference

Framework

AIBudsAI.xcframework

Import

Swift
import AIBudsAI
import AIBudsAIFoundation

Declaration

Swift
/// Synthesizes text into speech.
/// - Parameters:
///   - text: The text to synthesize.
///   - config: The synthesis configuration.
///   - completion: Called with the task identifier, success state, optional
///     result, and optional error when synthesis completes.
/// - Important: Call this method from a background thread to avoid blocking
///   the main thread.
public static func synthesizeText(_ text: String,
                                  config: TTSConfig = .default,
                              completion: ((
                                  _ taskId: String?,
                                  _ success: Bool,
                                  _ response: TTSResultModel?,
                                  _ error: NSError?
                              ) -> Void)? = nil) -> Void

synthesizeText देखें।

Configuration और Result

TTSConfig में optional speakerId है। इसके nil होने पर provider अपना default speaker चुनता है।

सफल होने पर TTSResultModel ये values देता है:

Propertyविवरण
audioFileApp की Documents directory के सापेक्ष audio file path।
audioFilePathबनी हुई audio file का पूरा path।
audioFormatबनी हुई audio file का format।

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

Swift
let config = TTSConfig.default
config.speakerId = nil

DispatchQueue.global(qos: .userInitiated).async {
    AIBudsAISDK.synthesizeText(
        "Hello, how can I help you?",
        config: config
    ) { taskId, success, response, error in
        guard success, let response else {
            print(error?.localizedDescription ?? "Synthesis failed")
            return
        }

        print("Task: \(taskId ?? "Unavailable")")
        print("Audio: \(response.audioFilePath)")

        DispatchQueue.main.async {
            playAudio(atPath: response.audioFilePath)
        }
    }
}

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

  • यह API audio file बनाती है; device playback शुरू नहीं करती और stopSpeaking() या isSpeaking() expose नहीं करती।
  • success, response और error को साथ जाँचें। Operation तभी सफल है जब success == true हो और response nil न हो।
  • Speaker identifiers provider-specific हैं। केवल चुने गए provider द्वारा documented identifier ही set करें।
  • UI और audio-player updates को main thread पर करें।