Add loopback STT debug logging
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user