Skip to content

Comments

Refactor inline AudioWorkletProcessor to separate file#88

Open
ysdede wants to merge 2 commits intostagingfrom
refactor-audio-worklet-processor-17365362216095794719
Open

Refactor inline AudioWorkletProcessor to separate file#88
ysdede wants to merge 2 commits intostagingfrom
refactor-audio-worklet-processor-17365362216095794719

Conversation

@ysdede
Copy link
Owner

@ysdede ysdede commented Feb 9, 2026

Refactored the inline CaptureProcessor string from src/lib/audio/AudioEngine.ts into a dedicated TypeScript file src/lib/audio/capture-processor.ts.

Changes

  • Moved CaptureProcessor class and registerProcessor call to src/lib/audio/capture-processor.ts.
  • Replaced interpolated ${windowDuration} with a constant WINDOW_DURATION = 0.080 in the new file.
  • Updated AudioEngine.ts to import the processor using import captureProcessorUrl from './capture-processor.ts?worker&url';.
  • Updated AudioEngine.init() to load the module from the imported URL.

Verification

  • Ran npm run build successfully.
  • Ran npm test - core tests passed. One unrelated flaky test in TenVADWorkerClient timed out.
  • Verified AudioEngine instantiation and worklet loading via a temporary test file.

PR created automatically by Jules for task 17365362216095794719 started by @ysdede

Move `CaptureProcessor` from inline string in `AudioEngine.ts` to `src/lib/audio/capture-processor.ts`.
This improves code readability, maintainability, and enables type checking.
The processor is now imported using Vite's `?worker&url` suffix and loaded via `addModule`.

- Extracted `CaptureProcessor` logic to `src/lib/audio/capture-processor.ts`
- Added TypeScript types and constants to the processor
- Updated `AudioEngine.ts` to import the processor URL
- Verified with build and instantiation tests

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@ysdede ysdede changed the base branch from release/r1 to staging February 10, 2026 21:00
@ysdede
Copy link
Owner Author

ysdede commented Feb 10, 2026

Review Summary (Post r1→master merge)

Status: ✅ MERGEABLE

Changes: Extracts the inline AudioWorkletProcessor from a Blob URL in \AudioEngine.ts\ into a proper separate file \capture-processor.ts:

  1. AudioEngine.ts: Removes ~50 lines of inline JS string (the worklet processor code was embedded as a template string and compiled via Blob URL). Now imports from the separate file.
  2. capture-processor.ts: Expanded from a minimal stub to a full implementation with:
    • Proper constructor with options (input/target sample rate)
    • Buffer accumulation with configurable window duration (80ms)
    • Linear interpolation resampling
    • Peak amplitude tracking
    • Structured message format ({ type: 'audio', samples, sampleRate, maxAbs })

Assessment: Important maintainability improvement. Inline JS-in-strings is hard to debug, gets no TypeScript checking, and no IDE support. The extracted file is properly typed and can be tested/linted.

Recommendation:Merge — Significant maintainability improvement

@google-labs-jules
Copy link
Contributor

Review Summary (Post r1→master merge)

Status: ✅ MERGEABLE

Changes: Extracts the inline AudioWorkletProcessor from a Blob URL in \AudioEngine.ts\ into a proper separate file \capture-processor.ts:

  1. AudioEngine.ts: Removes ~50 lines of inline JS string (the worklet processor code was embedded as a template string and compiled via Blob URL). Now imports from the separate file.
  2. capture-processor.ts: Expanded from a minimal stub to a full implementation with:
    • Proper constructor with options (input/target sample rate)
    • Buffer accumulation with configurable window duration (80ms)
    • Linear interpolation resampling
    • Peak amplitude tracking
    • Structured message format ({ type: 'audio', samples, sampleRate, maxAbs })

Assessment: Important maintainability improvement. Inline JS-in-strings is hard to debug, gets no TypeScript checking, and no IDE support. The extracted file is properly typed and can be tested/linted.

Recommendation:Merge — Significant maintainability improvement

Thank you for the review! I'm glad the extraction of the AudioWorkletProcessor improves the codebase's maintainability and type safety.

- Replied to PR comments acknowledging the review.
- No code changes required as the review was positive.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@ysdede
Copy link
Owner Author

ysdede commented Feb 11, 2026

LGTM. Extracting the AudioWorkletProcessor from an inline string into a proper TypeScript file significantly improves maintainability and allows for better IDE support/type checking. This addresses the tech debt identified in the AudioEngine.ts review. Recommend merging.

Repository owner deleted a comment from google-labs-jules bot Feb 17, 2026
Repository owner deleted a comment from coderabbitai bot Feb 17, 2026
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.

1 participant