-
Notifications
You must be signed in to change notification settings - Fork 281
Feature/js sdk responses api #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MaanavD
wants to merge
2
commits into
main
Choose a base branch
from
feature/js-sdk-responses-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Sample: Audio Transcription with Foundry Local | ||
|
|
||
| This sample demonstrates how to use Foundry Local for **speech-to-text (audio transcription)** using the Whisper model — entirely on-device, with no cloud services required. | ||
|
|
||
| ## What This Shows | ||
|
|
||
| - Loading the `whisper-tiny` model via the Foundry Local SDK | ||
| - Transcribing an audio file (`.wav`, `.mp3`, etc.) to text | ||
| - Both standard and streaming transcription modes | ||
| - Automatic hardware acceleration (NPU > GPU > CPU) | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Foundry Local](https://github.com/microsoft/Foundry-Local) installed on your machine | ||
| - Node.js 18+ | ||
|
|
||
| ## Getting Started | ||
|
|
||
| Install the Foundry Local SDK: | ||
|
|
||
| ```bash | ||
| npm install foundry-local-sdk | ||
| ``` | ||
|
|
||
| Place an audio file (e.g., `recording.wav` or `recording.mp3`) in the project directory, then run: | ||
|
|
||
| ```bash | ||
| node src/app.js | ||
| ``` | ||
|
|
||
| ## How It Works | ||
|
|
||
| The Foundry Local SDK handles everything: | ||
| 1. **Model discovery** — finds the best `whisper-tiny` variant for your hardware | ||
| 2. **Model download** — downloads the model if not already cached | ||
| 3. **Model loading** — loads the model into memory with optimized hardware acceleration | ||
| 4. **Transcription** — runs Whisper inference entirely on-device | ||
|
|
||
| No need for `whisper.cpp`, `@huggingface/transformers`, or any other separate STT tool. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "name": "audio-transcription-foundry-local", | ||
| "type": "module", | ||
| "description": "Audio transcription (speech-to-text) sample using Foundry Local", | ||
| "scripts": { | ||
| "start": "node src/app.js" | ||
| }, | ||
| "dependencies": { | ||
| "foundry-local-sdk": "latest" | ||
MaanavD marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { FoundryLocalManager } from "foundry-local-sdk"; | ||
| import path from "path"; | ||
|
|
||
| // The Whisper model alias for audio transcription | ||
| const alias = "whisper-tiny"; | ||
|
|
||
| async function main() { | ||
| console.log("Initializing Foundry Local SDK..."); | ||
| const manager = FoundryLocalManager.create({ | ||
| appName: "AudioTranscriptionSample", | ||
| logLevel: "info", | ||
| }); | ||
|
|
||
| // Get the Whisper model from the catalog | ||
| const catalog = manager.catalog; | ||
| const model = await catalog.getModel(alias); | ||
| if (!model) { | ||
| throw new Error( | ||
| `Model "${alias}" not found. Run "foundry model list" to see available models.` | ||
| ); | ||
| } | ||
|
|
||
| // Download the model if not already cached | ||
| if (!model.isCached) { | ||
| console.log(`Downloading model "${alias}"...`); | ||
| await model.download((progress) => { | ||
| process.stdout.write(`\rDownload progress: ${progress.toFixed(1)}%`); | ||
| }); | ||
| console.log("\nDownload complete."); | ||
| } | ||
|
|
||
| // Load the model into memory | ||
| console.log(`Loading model "${model.id}"...`); | ||
| await model.load(); | ||
| console.log("Model loaded.\n"); | ||
|
|
||
| // Create an audio client for transcription | ||
| const audioClient = model.createAudioClient(); | ||
| audioClient.settings.language = "en"; | ||
|
|
||
| // Update this path to point to your audio file | ||
| const audioFilePath = path.resolve("recording.mp3"); | ||
|
|
||
| // --- Standard transcription --- | ||
| console.log("=== Standard Transcription ==="); | ||
| const result = await audioClient.transcribe(audioFilePath); | ||
| console.log("Transcription:", result.text); | ||
|
|
||
| // --- Streaming transcription --- | ||
| console.log("\n=== Streaming Transcription ==="); | ||
| await audioClient.transcribeStreaming(audioFilePath, (chunk) => { | ||
| process.stdout.write(chunk.text); | ||
| }); | ||
MaanavD marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| console.log("\n"); | ||
|
|
||
| // Clean up | ||
| await model.unload(); | ||
| console.log("Done."); | ||
| } | ||
|
|
||
| main().catch(console.error); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.