Skip to content

Commit b7c22c1

Browse files
bmehta001Copilot
andcommitted
Align WinML samples across SDKs
Add a C++ WinML verifier sample and expose the C++ EP discovery/download APIs needed for parity with the other SDK samples. Update the existing WinML sample paths and C++ sample build instructions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d0c9114 commit b7c22c1

35 files changed

Lines changed: 1067 additions & 170 deletions

File tree

samples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Explore complete working examples that demonstrate how to use Foundry Local —
1212
| [**JavaScript**](js/) | 13 | Node.js SDK samples including native chat, embeddings, audio transcription, Electron desktop app, Copilot SDK integration, LangChain, tool calling, web server, and tutorials. |
1313
| [**Python**](python/) | 10 | Python samples using the OpenAI-compatible API, including chat, embeddings, audio transcription, LangChain integration, tool calling, web server, and tutorials. |
1414
| [**Rust**](rust/) | 9 | Rust SDK samples including native chat, embeddings, audio transcription, tool calling, web server, and tutorials. |
15+
| [**C++**](cpp/) | 2 | C++ SDK samples including WinML EP verification and live audio transcription. |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(LiveAudioTranscriptionSample LANGUAGES CXX)
4+
5+
set(CMAKE_CXX_STANDARD 20)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
9+
set(BUILD_TESTING OFF CACHE BOOL "Build C++ SDK tests" FORCE)
10+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../../../sdk/cpp" "${CMAKE_CURRENT_BINARY_DIR}/sdk-cpp")
11+
12+
add_executable(LiveAudioTranscriptionSample main.cpp)
13+
target_compile_features(LiveAudioTranscriptionSample PRIVATE cxx_std_20)
14+
target_link_libraries(LiveAudioTranscriptionSample PRIVATE CppSdk)

samples/cpp/live-audio-transcription/README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,34 @@ available, falls back to synthetic PCM audio.
99

1010
## Build
1111

12-
```bash
13-
# With PortAudio (live microphone)
14-
g++ -std=c++20 -DHAS_PORTAUDIO main.cpp -lfoundry_local -lportaudio -o live-audio-transcription-example
12+
From this directory:
1513

16-
# Without PortAudio (synthetic audio only)
17-
g++ -std=c++20 main.cpp -lfoundry_local -o live-audio-transcription-example
14+
```powershell
15+
cmake -S . -B out\build -G "Visual Studio 18 2026" -A x64 `
16+
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" `
17+
-DVCPKG_TARGET_TRIPLET=x64-windows-static-md
18+
19+
cmake --build out\build --config Debug --target LiveAudioTranscriptionSample
1820
```
1921

22+
The C++ SDK loads `Microsoft.AI.Foundry.Local.Core.dll` from the executable
23+
directory. Copy the Foundry Local native binaries next to
24+
`LiveAudioTranscriptionSample.exe` before running the sample.
25+
26+
The CMake project builds the synthetic-audio path by default. To use live
27+
microphone capture, add PortAudio to your build, define `HAS_PORTAUDIO`, and
28+
link PortAudio with `LiveAudioTranscriptionSample`.
29+
30+
This sample requires a Foundry Local Core/catalog build that includes the live
31+
audio streaming model `nemotron-speech-streaming-en-0.6b`. If that model is not
32+
present in the catalog, the sample cannot run even though it builds successfully.
33+
2034
## Run
2135

22-
```bash
23-
# Live microphone (requires PortAudio)
24-
./live-audio-transcription-example
36+
```powershell
37+
# Synthetic 440Hz sine wave
38+
.\out\build\Debug\LiveAudioTranscriptionSample.exe --synth
2539
26-
# Synthetic 440Hz sine wave (no microphone needed)
27-
./live-audio-transcription-example --synth
40+
# Live microphone (requires a PortAudio-enabled build)
41+
.\out\build\Debug\LiveAudioTranscriptionSample.exe
2842
```

samples/cpp/live-audio-transcription/main.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <iostream>
2020
#include <mutex>
2121
#include <string>
22+
#include <string_view>
2223
#include <thread>
2324
#include <vector>
2425

@@ -32,6 +33,8 @@
3233

3334
namespace {
3435

36+
constexpr std::string_view kLiveAudioModelAlias = "nemotron-speech-streaming-en-0.6b";
37+
3538
// Global flag for Ctrl+C graceful shutdown (mirrors JS process.on('SIGINT'))
3639
std::atomic<bool> g_running{true};
3740

@@ -117,17 +120,19 @@ int main(int argc, char* argv[]) {
117120
std::cout << "===========================================================" << std::endl;
118121
std::cout << std::endl;
119122

120-
foundry_local::Configuration config;
121-
config.appName = "foundry_local_samples";
123+
foundry_local::Configuration config{"foundry_local_samples"};
122124

123125
foundry_local::Manager::Create(config);
124126
auto& manager = foundry_local::Manager::Instance();
125127
manager.EnsureEpsDownloaded();
126128

127129
auto& catalog = manager.GetCatalog();
128-
auto* model = catalog.GetModel("nemotron-speech-streaming-en-0.6b");
130+
auto* model = catalog.GetModel(kLiveAudioModelAlias);
129131
if (!model) {
130-
throw std::runtime_error("Model \"nemotron-speech-streaming-en-0.6b\" not found in catalog");
132+
throw std::runtime_error(
133+
"Live audio model \"" + std::string(kLiveAudioModelAlias) +
134+
"\" was not found in the catalog. Use a Foundry Local Core/catalog build "
135+
"that includes live audio streaming support.");
131136
}
132137

133138
std::cout << "Downloading model (if needed)..." << std::endl;
@@ -139,8 +144,6 @@ int main(int argc, char* argv[]) {
139144
model->Load();
140145
std::cout << "Model loaded" << std::endl;
141146

142-
// NOTE: CreateLiveTranscriptionSession() is not yet available in the C++ SDK.
143-
// The audio client and session code below is forward-looking.
144147
foundry_local::OpenAIAudioClient audioClient(*model);
145148
auto session = audioClient.CreateLiveTranscriptionSession();
146149

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(VerifyWinMLCpp LANGUAGES CXX)
4+
5+
set(BUILD_TESTING OFF CACHE BOOL "Build C++ SDK tests" FORCE)
6+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/../../../sdk/cpp" "${CMAKE_CURRENT_BINARY_DIR}/sdk-cpp")
7+
8+
add_executable(VerifyWinML main.cpp)
9+
target_compile_features(VerifyWinML PRIVATE cxx_std_17)
10+
target_link_libraries(VerifyWinML PRIVATE CppSdk)

samples/cpp/verify-winml/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Verify WinML 2.0 Execution Providers (C++)
2+
3+
This sample verifies that WinML 2.0 execution providers are correctly
4+
discovered, downloaded, and registered using the Foundry Local C++ SDK. It then
5+
uses registered WinML EP-backed model variants and finishes with one native
6+
streaming chat check.
7+
8+
## Prerequisites
9+
10+
- Windows with a compatible GPU or NPU
11+
- Windows App SDK 2.0 runtime installed
12+
- A Foundry Local WinML native runtime copied next to the sample executable
13+
14+
The C++ SDK loads `Microsoft.AI.Foundry.Local.Core.dll` from the executable
15+
directory. Build or install a WinML-enabled SDK/runtime first, then copy the
16+
WinML native binaries next to `VerifyWinML.exe` before running the sample.
17+
18+
## Build
19+
20+
From this directory:
21+
22+
```powershell
23+
cmake -S . -B out\build -G "Visual Studio 18 2026" -A x64 `
24+
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" `
25+
-DVCPKG_TARGET_TRIPLET=x64-windows-static-md
26+
27+
cmake --build out\build --config Debug --target VerifyWinML
28+
```
29+
30+
## Run
31+
32+
```powershell
33+
.\out\build\Debug\VerifyWinML.exe
34+
```
35+
36+
## What it tests
37+
38+
1. **EP Discovery** - Lists all available execution providers.
39+
2. **EP Download & Registration** - Downloads and registers the available WinML EPs.
40+
3. **Model Catalog** - Lists text model variants backed by registered accelerated EPs.
41+
4. **Streaming Chat** - Runs streaming chat completion on a WinML EP-backed model via the native C++ SDK.

0 commit comments

Comments
 (0)