Add real-time audio streaming support (Microphone ASR) - c##485
Open
Add real-time audio streaming support (Microphone ASR) - c##485
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds real-time audio streaming support to the Foundry Local C# SDK, enabling live microphone-to-text transcription via ONNX Runtime GenAI ASR.
The existing
OpenAIAudioClientonly supports file-based transcription. This PR introduces a newOpenAIAudioStreamingClientthat accepts continuous PCM audio chunks (e.g., from a microphone) and returns partial/final transcription results as an async stream.What's included
New files
src/OpenAI/AudioStreamingClient.cs— Main streaming client withStartAsync(),PushAudioDataAsync(),GetTranscriptionStream(),StopAsync()src/OpenAI/AudioStreamTranscriptionTypes.cs—AudioStreamTranscriptionResultandCoreErrorResponsetypestest/FoundryLocal.Tests/AudioStreamingClientTests.cs— 14 unit tests for types, serialization, and settingsModified files
src/IModel.cs— AddedGetAudioStreamingClientAsync()to interfacesrc/Model.cs— Delegates toSelectedVariantsrc/ModelVariant.cs— Implementation (checks model loaded, returns client)src/Detail/ICoreInterop.cs— AddedStreamingRequestBufferstruct,AudioStreamSessionrecord, 3 new interface methodssrc/Detail/CoreInterop.cs— Added 3 P/Invoke bindings (audio_stream_start,audio_stream_push,audio_stream_stop) and managed implementations with GCHandle lifecyclesrc/Detail/JsonSerializationContext.cs— Registered new types for AOT compatibilityDesign highlights
Channel<T>serializes audio pushes from any thread (safe for mic callbacks) and provides backpressureStartAsync()and immutable during the sessionStopAsyncalways calls native stop even if cancelled, preventing native session leaksCancellationTokenSource, decoupled from the caller's tokenNative core dependency
This PR adds the C# SDK surface. The 3 native exports (
audio_stream_start,audio_stream_push,audio_stream_stop) must be implemented inMicrosoft.AI.Foundry.Local.Corebefore integration testing. The code compiles and unit tests for types/settings pass without the native library.Native contract spec: See
audio-streaming-codex.mdfor the full production contract.Testing
dotnet build— 0 errors)Related docs
https://microsoft-my.sharepoint.com/:w:/p/ruiren/IQBhsuMcvAByTqaVZhU7Xn7tAWgVj-EHvJYW2seiItfI2V0?e=HsmT7w