- 
                Notifications
    You must be signed in to change notification settings 
- Fork 167
Fix race condition causing "Writer is not bound to a WritableStream" error in Silero VAD #786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f2f90c5
              88b3587
              0dcdf13
              4db5c8f
              226ba74
              dbb6c0e
              029c72b
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@livekit/agents-plugin-silero': patch | ||
| --- | ||
|  | ||
| Fix race condition causing "Writer is not bound to a WritableStream" error in Silero VAD | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -260,26 +260,30 @@ export class VADStream extends baseStream { | |
| pubSilenceDuration += windowDuration; | ||
| } | ||
|  | ||
| this.outputWriter.write({ | ||
| type: VADEventType.INFERENCE_DONE, | ||
| samplesIndex: pubCurrentSample, | ||
| timestamp: pubTimestamp, | ||
| silenceDuration: pubSilenceDuration, | ||
| speechDuration: pubSpeechDuration, | ||
| probability: p, | ||
| inferenceDuration, | ||
| frames: [ | ||
| new AudioFrame( | ||
| inputFrame.data.subarray(0, toCopyInt), | ||
| this.#inputSampleRate, | ||
| 1, | ||
| toCopyInt, | ||
| ), | ||
| ], | ||
| speaking: pubSpeaking, | ||
| rawAccumulatedSilence: silenceThresholdDuration, | ||
| rawAccumulatedSpeech: speechThresholdDuration, | ||
| }); | ||
| if ( | ||
| !this.sendVADEvent({ | ||
| type: VADEventType.INFERENCE_DONE, | ||
| samplesIndex: pubCurrentSample, | ||
| timestamp: pubTimestamp, | ||
| silenceDuration: pubSilenceDuration, | ||
| speechDuration: pubSpeechDuration, | ||
| probability: p, | ||
| inferenceDuration, | ||
| frames: [ | ||
| new AudioFrame( | ||
| inputFrame.data.subarray(0, toCopyInt), | ||
| this.#inputSampleRate, | ||
| 1, | ||
| toCopyInt, | ||
| ), | ||
| ], | ||
| speaking: pubSpeaking, | ||
| rawAccumulatedSilence: silenceThresholdDuration, | ||
| rawAccumulatedSpeech: speechThresholdDuration, | ||
| }) | ||
| ) { | ||
| continue; | ||
| } | ||
|  | ||
| const resetWriteCursor = () => { | ||
| if (!this.#speechBuffer) throw new Error('speechBuffer is empty'); | ||
|  | @@ -314,19 +318,23 @@ export class VADStream extends baseStream { | |
| pubSilenceDuration = 0; | ||
| pubSpeechDuration = speechThresholdDuration; | ||
|  | ||
| this.outputWriter.write({ | ||
| type: VADEventType.START_OF_SPEECH, | ||
| samplesIndex: pubCurrentSample, | ||
| timestamp: pubTimestamp, | ||
| silenceDuration: pubSilenceDuration, | ||
| speechDuration: pubSpeechDuration, | ||
| probability: p, | ||
| inferenceDuration, | ||
| frames: [copySpeechBuffer()], | ||
| speaking: pubSpeaking, | ||
| rawAccumulatedSilence: 0, | ||
| rawAccumulatedSpeech: 0, | ||
| }); | ||
| if ( | ||
| !this.sendVADEvent({ | ||
| 
      Comment on lines
    
      +321
     to 
      +322
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!this.sendVADEvent) {
    continue
}Feels redundant? We can just do  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @toubatbrian bump There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah it's fine for now | ||
| type: VADEventType.START_OF_SPEECH, | ||
| samplesIndex: pubCurrentSample, | ||
| timestamp: pubTimestamp, | ||
| silenceDuration: pubSilenceDuration, | ||
| speechDuration: pubSpeechDuration, | ||
| probability: p, | ||
| inferenceDuration, | ||
| frames: [copySpeechBuffer()], | ||
| speaking: pubSpeaking, | ||
| rawAccumulatedSilence: 0, | ||
| rawAccumulatedSpeech: 0, | ||
| }) | ||
| ) { | ||
| continue; | ||
| } | ||
| } | ||
| } else { | ||
| silenceThresholdDuration += windowDuration; | ||
|  | @@ -341,19 +349,23 @@ export class VADStream extends baseStream { | |
| pubSpeechDuration = 0; | ||
| pubSilenceDuration = silenceThresholdDuration; | ||
|  | ||
| this.outputWriter.write({ | ||
| type: VADEventType.END_OF_SPEECH, | ||
| samplesIndex: pubCurrentSample, | ||
| timestamp: pubTimestamp, | ||
| silenceDuration: pubSilenceDuration, | ||
| speechDuration: pubSpeechDuration, | ||
| probability: p, | ||
| inferenceDuration, | ||
| frames: [copySpeechBuffer()], | ||
| speaking: pubSpeaking, | ||
| rawAccumulatedSilence: 0, | ||
| rawAccumulatedSpeech: 0, | ||
| }); | ||
| if ( | ||
| !this.sendVADEvent({ | ||
| type: VADEventType.END_OF_SPEECH, | ||
| samplesIndex: pubCurrentSample, | ||
| timestamp: pubTimestamp, | ||
| silenceDuration: pubSilenceDuration, | ||
| speechDuration: pubSpeechDuration, | ||
| probability: p, | ||
| inferenceDuration, | ||
| frames: [copySpeechBuffer()], | ||
| speaking: pubSpeaking, | ||
| rawAccumulatedSilence: 0, | ||
| rawAccumulatedSpeech: 0, | ||
| }) | ||
| ) { | ||
| continue; | ||
| } | ||
|  | ||
| resetWriteCursor(); | ||
| } | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.