Add loopback STT debug logging

This commit is contained in:
2026-05-02 21:05:28 +09:00
parent f0f62c2307
commit c4baca1739
2 changed files with 65 additions and 0 deletions

View File

@@ -1,5 +1,9 @@
interface RealtimeSegmenterOptions {
onSegment: (pcm16: Buffer) => void;
onLevel?: (peak: number) => void;
onSpeechStart?: (peak: number) => void;
onSpeechDiscarded?: (samples: number) => void;
onSpeechReady?: (samples: number) => void;
}
export class RealtimeSegmenter {
@@ -44,6 +48,8 @@ export class RealtimeSegmenter {
}
}
this.options.onLevel?.(peak);
if (!this.speechActive) {
appendWithCap(this.preRoll, frame, this.preRollSamples);
if (peak >= this.speechStartThreshold) {
@@ -60,6 +66,7 @@ export class RealtimeSegmenter {
this.silenceFrames = 0;
this.speech.splice(0, this.speech.length, ...this.preRoll);
this.preRoll.splice(0, this.preRoll.length);
this.options.onSpeechStart?.(peak);
}
this.speech.push(...frame);
@@ -81,9 +88,11 @@ export class RealtimeSegmenter {
this.speechCandidateFrames = 0;
if (speechPcm.length < this.minSpeechSamples * 2) {
this.options.onSpeechDiscarded?.(speechPcm.length / 2);
return;
}
this.options.onSpeechReady?.(speechPcm.length / 2);
this.options.onSegment(speechPcm);
}
}