-
Notifications
You must be signed in to change notification settings - Fork 0
Ai Streaming Asr
Mr.P edited this page Aug 29, 2026
·
2 revisions
Send audio data or a local audio file to the selected AI provider and receive incremental speech-recognition results.
-
AIBudsAISDKis initialized and a registered provider is selected. - The provider supports
StreamingASRServiceAPI. - The input bytes match the
audioFormatspecified by the configuration. -
languageForSpeechInput, when supplied, uses a hyphenated language identifier such asen-USorzh-CN.
AIBudsAI.xcframework
import AIBudsAI
import AIBudsAIFoundation#import <AIBudsAI/AIBudsAI-Swift.h>/// 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/// 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.
+ (void)recognizeVoiceData:(NSData * _Nonnull)data
withConfig:(AIBudsStreamingASRConfig * _Nonnull)config
onTranscript:(void (^ _Nullable)(AIBudsStreamSpeechASRModel * _Nonnull))onTranscript
onFailed:(void (^ _Nullable)(NSError * _Nonnull))onFailed
onFinish:(void (^ _Nullable)(void))onFinish;
/// 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.
+ (void)recognizeVoiceFile:(NSString * _Nonnull)filePath
withConfig:(AIBudsStreamingASRConfig * _Nonnull)config
onTranscript:(void (^ _Nullable)(AIBudsStreamSpeechASRModel * _Nonnull))onTranscript
onFailed:(void (^ _Nullable)(NSError * _Nonnull))onFailed
onFinish:(void (^ _Nullable)(void))onFinish;Both overloads are exposed by AIBudsAISDK and route to the selected provider's StreamingASRServiceAPI implementation.
Create StreamingASRConfig with:
| Value | Description |
|---|---|
languageForSpeechInput |
Optional recognition language. When omitted, the provider uses the current app localization language. |
audioFormat |
Input format, such as .pcm, .mp3, or .wav. |
enableSpeakerDiarization |
Whether the provider should identify speaker segments. Defaults to false. |
The input format uses AIAudioFormat:
| Value | Input |
|---|---|
.pcm |
Raw PCM audio matching the selected provider's required sample format. |
.opus |
Opus-encoded audio. |
.mp3 |
MP3 audio. |
.wav |
WAV container audio. |
.none / .unknown
|
No usable format; do not start recognition with these values. |
Each StreamSpeechASRModel includes a sequence, optional request ID, incremental transcript, definiteness flag, optional transcript sequence, and optional speaker segments.
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")
}
)AIBudsStreamingASRConfig *config =
[[AIBudsStreamingASRConfig alloc] initWithLanguageForSpeechInput:@"en-US"
audioFormat:AIBudsAIAudioFormatWav
enableSpeakerDiarization:YES];
[AIBudsAISDK recognizeVoiceFile:fileURL.path
withConfig:config
onTranscript:^(AIBudsStreamSpeechASRModel *result) {
NSLog(@"Sequence %ld: %@", (long)result.sequence, result.transcript ?: @"");
if (result.isDefinite) {
NSLog(@"Definite transcript received");
}
}
onFailed:^(NSError *error) {
NSLog(@"Recognition failed: %@", error.localizedDescription);
}
onFinish:^{
NSLog(@"Recognition finished");
}];For in-memory audio, call recognizeVoice(_:config:onTranscript:onFailed:onFinish:) with Data / NSData and the same callback handling.
- Transcript text is incremental and may repeat as a sentence becomes more complete; use
sequence,transcriptSequence, andisDefinitewhen assembling UI output. - The current API accepts a complete
Datavalue or file path. It does not expose start/append/stop streaming controls or a recognition delegate. -
onFinishhas no result value. Store the latest transcript received byonTranscriptif the final text is needed after completion. - Supported formats, languages, and speaker diarization behavior can vary by provider.
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