Skip to content

[Refactor] improve the JS example#588

Open
rui-ren wants to merge 1 commit intomainfrom
ruiren/app-js
Open

[Refactor] improve the JS example#588
rui-ren wants to merge 1 commit intomainfrom
ruiren/app-js

Conversation

@rui-ren
Copy link
Copy Markdown
Contributor

@rui-ren rui-ren commented Apr 4, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 4, 2026 04:25
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview, Comment Apr 4, 2026 4:25am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the JS live audio transcription sample to make streaming output cleaner and to make microphone audio ingestion more resilient to short event-loop stalls (aligning behavior more closely with the existing C# sample pattern).

Changes:

  • Adjust transcription printing to skip empty partials and treat is_final as a marker (not a stop condition).
  • Increase PortAudio chunk size / queue depth to reduce callback frequency and overflow risk.
  • Replace “drop-while-backpressured” audio appends with a bounded async append queue and a pump loop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 125 to +127
const pcm = new Uint8Array(buffer);
appendPending = true;
session.append(pcm).then(() => {
appendPending = false;
}).catch((err) => {
appendPending = false;
console.error('append error:', err.message);
});
const copy = new Uint8Array(pcm.length);
copy.set(pcm);
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the audio data handler you’re copying the PCM buffer twice (new Uint8Array(buffer) already copies when buffer is a Node Buffer/TypedArray, and then you allocate/copy again into copy). This adds avoidable work on a hot path and can increase overflow risk under load. Consider doing a single copy into the queued Uint8Array (or creating a view + one explicit copy if you need to detach from a reused native buffer).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants