Skip to content

Commit aef5853

Browse files
authored
frame-processor.ts: tiny refactoring (#187)
1 parent e03c998 commit aef5853

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/web/src/frame-processor.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export class FrameProcessor implements FrameProcessorInterface {
144144

145145
reset = () => {
146146
this.speaking = false
147+
this.speechRealStartFired = false
147148
this.audioBuffer = []
148149
this.modelResetFunc()
149150
this.redemptionCounter = 0
@@ -169,11 +170,10 @@ export class FrameProcessor implements FrameProcessorInterface {
169170
const speaking = this.speaking
170171
this.reset()
171172

172-
const speechFrameCount = audioBuffer.reduce((acc, item) => {
173-
return acc + +item.isSpeech
174-
}, 0)
175-
176173
if (speaking) {
174+
const speechFrameCount = audioBuffer.reduce((acc, item) => {
175+
return item.isSpeech ? (acc + 1) : acc
176+
}, 0)
177177
if (speechFrameCount >= this.options.minSpeechFrames) {
178178
const audio = concatArrays(audioBuffer.map((item) => item.frame))
179179
handleEvent({ msg: Message.SpeechEnd, audio })
@@ -234,7 +234,7 @@ export class FrameProcessor implements FrameProcessorInterface {
234234
this.audioBuffer = []
235235

236236
const speechFrameCount = audioBuffer.reduce((acc, item) => {
237-
return acc + +item.isSpeech
237+
return item.isSpeech ? (acc + 1) : acc
238238
}, 0)
239239

240240
if (speechFrameCount >= this.options.minSpeechFrames) {

0 commit comments

Comments
 (0)