@ -2,6 +2,7 @@
# include "STTManagerBase.h"
# include "STTManagerBase.h"
# include "Recorder/STTRecorderDebugFile.h"
# include "Recorder/STTRecorderDebugFile.h"
# include "Preprocessor/STTPreprocessorWebRTC.h"
# include "Kismet/GameplayStatics.h"
# include "Kismet/GameplayStatics.h"
void USTTManagerBase : : InitSTTManager ( bool AutoInitModules , USTTBaseProcessorConfig * InProcessorConfig , bool DebugMode )
void USTTManagerBase : : InitSTTManager ( bool AutoInitModules , USTTBaseProcessorConfig * InProcessorConfig , bool DebugMode )
@ -381,6 +382,12 @@ void USTTManagerBase::DebugPlayFileAsSTT(FString File)
FileRecorder - > DebugPlayAudioFile ( File ) ;
FileRecorder - > DebugPlayAudioFile ( File ) ;
}
}
void USTTManagerBase : : DebugClearFilePlayback ( )
{
USTTRecorderDebugFile * FileRecorder = DebugGetFileRecorder ( ) ;
FileRecorder - > DebugClearAudioFile ( ) ;
}
USTTRecorderDebugFile * USTTManagerBase : : DebugGetFileRecorder ( )
USTTRecorderDebugFile * USTTManagerBase : : DebugGetFileRecorder ( )
{
{
@ -394,6 +401,44 @@ USTTRecorderDebugFile* USTTManagerBase::DebugGetFileRecorder()
FileRecorder - > InitSTTRecorder ( this , bDebugMode ) ;
FileRecorder - > InitSTTRecorder ( this , bDebugMode ) ;
FileRecorder - > OnChunkReceived . BindUFunction ( STTPreprocessors [ 0 ] , " OnChunkReceived " ) ;
FileRecorder - > OnChunkReceived . BindUFunction ( STTPreprocessors [ 0 ] , " OnChunkReceived " ) ;
STTRecorder = FileRecorder ;
STTRecorder = FileRecorder ;
// Disable echo cancellation on any WebRTC preprocessor in the chain
// (file playback has no real mic signal, so AEC would corrupt the audio)
for ( int32 i = 0 ; i < STTPreprocessors . Num ( ) ; i + + )
{
USTTPreprocessorWebRTC * WebRTCPP = Cast < USTTPreprocessorWebRTC > ( STTPreprocessors [ i ] ) ;
if ( ! WebRTCPP )
continue ;
UClass * PPClass = WebRTCPP - > GetClass ( ) ;
// Unbind outgoing delegate and destroy old instance
WebRTCPP - > OnChunkProcessed . Unbind ( ) ;
WebRTCPP - > DestroySTTPreprocessor ( ) ;
WebRTCPP - > RemoveFromRoot ( ) ;
// Create a replacement with echo_canceller disabled
FSTTBaseSettings ModifiedSettings = ProcessorConfig - > BaseSettings ;
ModifiedSettings . WebRTCSettings . echo_canceller = false ;
USTTPreprocessorWebRTC * NewWebRTCPP = NewObject < USTTPreprocessorWebRTC > ( this , PPClass ) ;
NewWebRTCPP - > AddToRoot ( ) ;
NewWebRTCPP - > InitSTTPreprocessor ( this , ModifiedSettings , bDebugMode ) ;
// Re-bind incoming link
if ( i = = 0 )
STTRecorder - > OnChunkReceived . BindUFunction ( NewWebRTCPP , " OnChunkReceived " ) ;
else
STTPreprocessors [ i - 1 ] - > OnChunkProcessed . BindUFunction ( NewWebRTCPP , " OnChunkReceived " ) ;
// Re-bind outgoing link
if ( i = = STTPreprocessors . Num ( ) - 1 )
NewWebRTCPP - > OnChunkProcessed . BindUFunction ( STTProcessor , " OnChunkReceived " ) ;
else
NewWebRTCPP - > OnChunkProcessed . BindUFunction ( STTPreprocessors [ i + 1 ] , " OnChunkReceived " ) ;
STTPreprocessors [ i ] = NewWebRTCPP ;
}
}
}
return FileRecorder ;
return FileRecorder ;
}
}
@ -402,11 +447,41 @@ void USTTManagerBase::DebugResetRecorder()
{
{
STTRecorder - > DestroySTTRecorder ( ) ;
STTRecorder - > DestroySTTRecorder ( ) ;
STTRecorder - > RemoveFromRoot ( ) ;
STTRecorder - > RemoveFromRoot ( ) ;
USTTRecorderBase * FileRecorder = NewObject < USTTRecorderBase > ( this , STTRecorderClass ) ;
USTTRecorderBase * NewRecorder = NewObject < USTTRecorderBase > ( this , STTRecorderClass ) ;
FileRecorder - > AddToRoot ( ) ;
NewRecorder - > AddToRoot ( ) ;
FileRecorder - > InitSTTRecorder ( this , bDebugMode ) ;
NewRecorder - > InitSTTRecorder ( this , bDebugMode ) ;
FileRecorder - > OnChunkReceived . BindUFunction ( STTPreprocessors [ 0 ] , " OnChunkReceived " ) ;
NewRecorder - > OnChunkReceived . BindUFunction ( STTPreprocessors [ 0 ] , " OnChunkReceived " ) ;
STTRecorder = FileRecorder ;
STTRecorder = NewRecorder ;
// Restore echo cancellation on any WebRTC preprocessor using original config
for ( int32 i = 0 ; i < STTPreprocessors . Num ( ) ; i + + )
{
USTTPreprocessorWebRTC * WebRTCPP = Cast < USTTPreprocessorWebRTC > ( STTPreprocessors [ i ] ) ;
if ( ! WebRTCPP )
continue ;
UClass * PPClass = WebRTCPP - > GetClass ( ) ;
WebRTCPP - > OnChunkProcessed . Unbind ( ) ;
WebRTCPP - > DestroySTTPreprocessor ( ) ;
WebRTCPP - > RemoveFromRoot ( ) ;
USTTPreprocessorWebRTC * NewWebRTCPP = NewObject < USTTPreprocessorWebRTC > ( this , PPClass ) ;
NewWebRTCPP - > AddToRoot ( ) ;
NewWebRTCPP - > InitSTTPreprocessor ( this , ProcessorConfig - > BaseSettings , bDebugMode ) ;
if ( i = = 0 )
STTRecorder - > OnChunkReceived . BindUFunction ( NewWebRTCPP , " OnChunkReceived " ) ;
else
STTPreprocessors [ i - 1 ] - > OnChunkProcessed . BindUFunction ( NewWebRTCPP , " OnChunkReceived " ) ;
if ( i = = STTPreprocessors . Num ( ) - 1 )
NewWebRTCPP - > OnChunkProcessed . BindUFunction ( STTProcessor , " OnChunkReceived " ) ;
else
NewWebRTCPP - > OnChunkProcessed . BindUFunction ( STTPreprocessors [ i + 1 ] , " OnChunkReceived " ) ;
STTPreprocessors [ i ] = NewWebRTCPP ;
}
}
}
bool USTTManagerBase : : IsSTTFullyInitialized ( )
bool USTTManagerBase : : IsSTTFullyInitialized ( )