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

स्ट्रीमिंग स्पीच रिकग्निशन

Audio data या local audio file चुने गए AI provider को भेजें और क्रमशः speech-recognition results पाएँ।

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

  • AIBudsAISDK initialize हो और registered provider चुना गया हो।
  • Provider StreamingASRServiceAPI support करता हो।
  • Input bytes कॉन्फ़िगरेशन में दिए audioFormat से मेल खाते हों।
  • languageForSpeechInput देने पर en-US या zh-CN जैसा hyphenated language identifier उपयोग करें।

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

AI से बनाएँ

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

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

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

API Reference

Framework

AIBudsAI.xcframework

Import

Swift
import AIBudsAI
import AIBudsAIFoundation

Declaration

Swift
/// Recognizes voice data.
/// - Parameters:
///   - data: The audio data to recognize.
///   - config: The recognition configuration.
///   - onTranscript: Called for each incremental transcript result.
///   - onFailed: Called when recognition fails.
///   - onFinish: Called when recognition finishes.
public static func recognizeVoice(_ data: Data,
                                  config: StreamingASRConfig = .default,
                            onTranscript: ((_ transcriptData: StreamSpeechASRModel) -> Void)? = nil,
                                onFailed: ((_ error: NSError) -> Void)? = nil,
                                onFinish: (() -> Void)? = nil) -> Void

/// Recognizes a voice file.
/// - Parameters:
///   - filePath: The local path of the audio file to recognize.
///   - config: The recognition configuration.
///   - onTranscript: Called for each incremental transcript result.
///   - onFailed: Called when recognition fails.
///   - onFinish: Called when recognition finishes.
public static func recognizeVoice(withFile filePath: String,
                                             config: StreamingASRConfig = .default,
                                       onTranscript: ((_ transcriptData: StreamSpeechASRModel) -> Void)? = nil,
                                           onFailed: ((_ error: NSError) -> Void)? = nil,
                                           onFinish: (() -> Void)? = nil) -> Void

दोनों overloads AIBudsAISDK उपलब्ध कराता है और वे चुने गए provider के StreamingASRServiceAPI implementation तक जाते हैं।

कॉन्फ़िगरेशन

StreamingASRConfig इन values के साथ बनाएँ:

Valueविवरण
languageForSpeechInputOptional recognition language। न देने पर provider app localization की वर्तमान भाषा उपयोग करता है।
audioFormat.pcm, .mp3 या .wav जैसा input format।
enableSpeakerDiarizationProvider speaker segments पहचाने या नहीं। Default false है।

Input format AIAudioFormat उपयोग करता है:

Valueइनपुट
.pcmचुने गए provider के अपेक्षित sample format से मेल खाता raw PCM audio।
.opusOpus-encoded audio।
.mp3MP3 audio।
.wavWAV container audio।
.none / .unknownउपयोग योग्य format नहीं; इन values से recognition शुरू न करें।

हर StreamSpeechASRModel में sequence, optional request ID, incremental transcript, definiteness flag, optional transcript sequence और optional speaker segments होते हैं।

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

File पहचानें

Swift
let config = StreamingASRConfig(
    languageForSpeechInput: "en-US",
    audioFormat: .wav,
    enableSpeakerDiarization: true
)

AIBudsAISDK.recognizeVoice(
    withFile: fileURL.path,
    config: config,
    onTranscript: { result in
        print("Sequence \(result.sequence): \(result.transcript ?? "")")
        if result.isDefinite {
            print("Definite transcript received")
        }
    },
    onFailed: { error in
        print("Recognition failed: \(error.localizedDescription)")
    },
    onFinish: {
        print("Recognition finished")
    }
)

In-memory audio के लिए recognizeVoice(_:config:onTranscript:onFailed:onFinish:) को Data / NSData और समान callback handling के साथ call करें।

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

  • Transcript text क्रमशः आता है और वाक्य पूरा होते समय दोहर सकता है; UI output बनाते समय sequence, transcriptSequence और isDefinite उपयोग करें।
  • वर्तमान API पूरा Data value या file path लेता है। यह start/append/stop streaming controls या recognition delegate उपलब्ध नहीं कराता।
  • onFinish में result value नहीं होती। Completion के बाद अंतिम टेक्स्ट चाहिए तो onTranscript से मिला नवीनतम transcript सहेजें।
  • Supported formats, languages और speaker diarization behavior provider के अनुसार बदल सकते हैं।