fix: Audio-Chunk Overlap - 1s Pre-Roll nach gesendeten Chunks behalten, STT Wortanfang nicht abschneiden
Made-with: Cursor
This commit is contained in:
parent
f8bd473008
commit
96819abcf2
1 changed files with 10 additions and 6 deletions
|
|
@ -23,7 +23,7 @@ class AudioCaptureProcessor extends AudioWorkletProcessor {
|
||||||
this.targetRate = opts.targetRate || 16000;
|
this.targetRate = opts.targetRate || 16000;
|
||||||
this.maxSamplesPerChunk = this.nativeRate * 8;
|
this.maxSamplesPerChunk = this.nativeRate * 8;
|
||||||
this.minRmsThreshold = 0.0003;
|
this.minRmsThreshold = 0.0003;
|
||||||
this.preRollSamples = Math.ceil(this.nativeRate * 0.5);
|
this.preRollSamples = Math.ceil(this.nativeRate * 1.0);
|
||||||
this.minFlushSamples = Math.ceil(this.nativeRate * 0.5);
|
this.minFlushSamples = Math.ceil(this.nativeRate * 0.5);
|
||||||
this.silenceFlushCallbacks = 6;
|
this.silenceFlushCallbacks = 6;
|
||||||
this.ratio = this.nativeRate / this.targetRate;
|
this.ratio = this.nativeRate / this.targetRate;
|
||||||
|
|
@ -99,8 +99,10 @@ class AudioCaptureProcessor extends AudioWorkletProcessor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.chunkBuffer = [];
|
const keep = Math.min(this.preRollSamples, merged.length);
|
||||||
this.samplesCollected = 0;
|
const preRoll = merged.slice(merged.length - keep);
|
||||||
|
this.chunkBuffer = [preRoll];
|
||||||
|
this.samplesCollected = keep;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -274,7 +276,7 @@ export class AudioCaptureProcedure {
|
||||||
const useScriptProcessor = () => {
|
const useScriptProcessor = () => {
|
||||||
const minRmsThreshold = 0.0003;
|
const minRmsThreshold = 0.0003;
|
||||||
const maxSamplesPerChunk = nativeRate * 8;
|
const maxSamplesPerChunk = nativeRate * 8;
|
||||||
const preRollSamples = Math.ceil(nativeRate * 0.5);
|
const preRollSamples = Math.ceil(nativeRate * 1.0);
|
||||||
const minFlushSamples = Math.ceil(nativeRate * 0.5);
|
const minFlushSamples = Math.ceil(nativeRate * 0.5);
|
||||||
const silenceFlushCallbacks = 6;
|
const silenceFlushCallbacks = 6;
|
||||||
const ratio = nativeRate / targetRate;
|
const ratio = nativeRate / targetRate;
|
||||||
|
|
@ -348,8 +350,10 @@ export class AudioCaptureProcedure {
|
||||||
samplesCollected = keep;
|
samplesCollected = keep;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chunkBuffer = [];
|
const keep = Math.min(preRollSamples, merged.length);
|
||||||
samplesCollected = 0;
|
const preRoll = merged.slice(merged.length - keep);
|
||||||
|
chunkBuffer = [preRoll];
|
||||||
|
samplesCollected = keep;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue