Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/google/adk/cli/browser/assets/audio-processor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2026 Google LLC
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
class AudioProcessor extends AudioWorkletProcessor {
constructor() {
super();
this.targetSampleRate = 22000; // Change to your desired rate
this.targetSampleRate = 16000; // Live API expects 16 kHz PCM input
this.originalSampleRate = sampleRate; // Browser's sample rate
this.resampleRatio = this.originalSampleRate / this.targetSampleRate;
}
Expand All @@ -26,7 +26,7 @@ class AudioProcessor extends AudioWorkletProcessor {
const input = inputs[0];
if (input.length > 0) {
let audioData = input[0]; // Get first channel's data

if (this.resampleRatio !== 1) {
audioData = this.resample(audioData);
}
Expand All @@ -40,9 +40,15 @@ class AudioProcessor extends AudioWorkletProcessor {
const newLength = Math.round(audioData.length / this.resampleRatio);
const resampled = new Float32Array(newLength);

// Linear interpolation resampling (higher quality than nearest neighbor)
const lastIndex = audioData.length - 1;
for (let i = 0; i < newLength; i++) {
const srcIndex = Math.floor(i * this.resampleRatio);
resampled[i] = audioData[srcIndex]; // Nearest neighbor resampling
const srcPos = i * this.resampleRatio;
const srcIndex = Math.floor(srcPos);
const nextIndex = Math.min(srcIndex + 1, lastIndex);
const frac = srcPos - srcIndex;
resampled[i] =
audioData[srcIndex] * (1 - frac) + audioData[nextIndex] * frac;
}
return resampled;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"backendUrl": ""
}
}
14 changes: 0 additions & 14 deletions src/google/adk/cli/browser/chunk-27SWUPRL.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions src/google/adk/cli/browser/chunk-2DLZXFEQ.js

This file was deleted.

Loading