@@ -107,6 +107,12 @@ class VoiceFocus {
107107 var _a ;
108108 return ( _a = this . internal . voiceFocusNode ) === null || _a === void 0 ? void 0 : _a . getModelMetrics ( ) ;
109109 }
110+ reset ( ) {
111+ var _a , _b , _c ;
112+ ( _a = this . internal . voiceFocusNode ) === null || _a === void 0 ? void 0 : _a . reset ( ) ;
113+ ( _b = this . internal . sourceNode ) === null || _b === void 0 ? void 0 : _b . disconnect ( ) ;
114+ ( _c = this . internal . destinationNode ) === null || _c === void 0 ? void 0 : _c . disconnect ( ) ;
115+ }
110116 enable ( ) {
111117 var _a ;
112118 ( _a = this . internal . voiceFocusNode ) === null || _a === void 0 ? void 0 : _a . enable ( ) ;
@@ -325,18 +331,27 @@ class VoiceFocus {
325331 . addModule ( url )
326332 . then ( ( ) => new ( this . nodeConstructor ) ( context , Object . assign ( Object . assign ( { } , this . nodeOptions ) , { processorOptions } ) ) ) ;
327333 }
328- applyToStream ( stream , context , options ) {
334+ applyToStream ( stream , context , options , useExistingNode = false ) {
335+ var _a ;
329336 return __awaiter ( this , void 0 , void 0 , function * ( ) {
330337 if ( this . internal . isDestroyed ) {
331338 throw new Error ( "Unable to apply stream because VoiceFocus worker has been destroyed" ) ;
332339 }
340+ let voiceFocusNode ;
341+ if ( useExistingNode && this . internal . voiceFocusNode && this . internal . voiceFocusNode . isEnabled ( ) ) {
342+ ( _a = this . logger ) === null || _a === void 0 ? void 0 : _a . info ( "Re-using existing voice focus node" ) ;
343+ voiceFocusNode = this . internal . voiceFocusNode ;
344+ }
345+ else {
346+ voiceFocusNode = yield this . createNode ( context , options ) ;
347+ }
333348 const source = context . createMediaStreamSource ( stream ) ;
334- const node = yield this . applyToSourceNode ( source , context , options ) ;
349+ source . connect ( voiceFocusNode ) ;
335350 const destination = context . createMediaStreamDestination ( ) ;
336- node . connect ( destination ) ;
337- this . internal = Object . assign ( Object . assign ( { } , this . internal ) , { voiceFocusNode : node , sourceNode : source , destinationNode : destination , audioContext : context } ) ;
351+ voiceFocusNode . connect ( destination ) ;
352+ this . internal = Object . assign ( Object . assign ( { } , this . internal ) , { voiceFocusNode : voiceFocusNode , sourceNode : source , destinationNode : destination , audioContext : context } ) ;
338353 return {
339- node,
354+ node : voiceFocusNode ,
340355 source,
341356 destination,
342357 stream : destination . stream ,
0 commit comments