Skip to content

Commit b253664

Browse files
authored
Fix bug with speech duration calculation (#484)
1 parent e24cda9 commit b253664

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.changeset/tall-months-doubt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@livekit/agents-plugin-silero': patch
3+
---
4+
5+
bugfix with speech duration calculation

plugins/silero/src/vad.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export interface VADOptions {
3535

3636
const defaultVADOptions: VADOptions = {
3737
minSpeechDuration: 50,
38-
minSilenceDuration: 250,
38+
minSilenceDuration: 550,
3939
prefixPaddingDuration: 500,
40-
maxBufferedSpeech: 60000,
40+
maxBufferedSpeech: 60000, // 60 seconds
4141
activationThreshold: 0.5,
4242
sampleRate: 16000,
4343
forceCPU: true,
@@ -227,7 +227,7 @@ export class VADStream extends baseStream {
227227

228228
// copy the inference window to the speech buffer
229229
const availableSpace = this.#speechBuffer.length - speechBufferIndex;
230-
const toCopyBuffer = Math.min(this.#model.windowSizeSamples, availableSpace);
230+
const toCopyBuffer = Math.min(toCopyInt, availableSpace);
231231
if (toCopyBuffer > 0) {
232232
this.#speechBuffer.set(inputFrame.data.subarray(0, toCopyBuffer), speechBufferIndex);
233233
speechBufferIndex += toCopyBuffer;
@@ -250,9 +250,9 @@ export class VADStream extends baseStream {
250250
}
251251

252252
if (pubSpeaking) {
253-
pubSpeechDuration += inferenceDuration;
253+
pubSpeechDuration += windowDuration;
254254
} else {
255-
pubSilenceDuration += inferenceDuration;
255+
pubSilenceDuration += windowDuration;
256256
}
257257

258258
this.queue.put({

0 commit comments

Comments
 (0)