|
|
@ -73,7 +73,7 @@ void USTTProcessorAzure::OnChunkReceived(TArray<int16> PCMData, FAudioInformatio |
|
|
if (IsValid(STTManager) && STTManager->IsBlocked()) |
|
|
if (IsValid(STTManager) && STTManager->IsBlocked()) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
if (!AzureRunnable) //Runable not ready
|
|
|
if (!AzureRunnable || !bTranscriptionRunning) //Runable not ready or previous session ended
|
|
|
{ |
|
|
{ |
|
|
USTTProcessorAzure::StartRecognition(); |
|
|
USTTProcessorAzure::StartRecognition(); |
|
|
} |
|
|
} |
|
|
@ -99,13 +99,13 @@ void USTTProcessorAzure::OnSpeechStateChanged(ESTTTalkingState TalkingState) |
|
|
StopRecognition(true); |
|
|
StopRecognition(true); |
|
|
} |
|
|
} |
|
|
else if (TalkingState == ESTTTalkingState::SILENCE || TalkingState == ESTTTalkingState::TRANSCRIBING) { |
|
|
else if (TalkingState == ESTTTalkingState::SILENCE || TalkingState == ESTTTalkingState::TRANSCRIBING) { |
|
|
if (AzureRunnable) |
|
|
if (AzureRunnable) { |
|
|
StopRecognition(false); |
|
|
StopRecognition(false); // Signal stop, runnable delivers final result via OnRecognized/OnRunnableEnded
|
|
|
else { |
|
|
} |
|
|
if (!intermediateResult.IsEmpty()) { |
|
|
else if (!intermediateResult.IsEmpty()) { |
|
|
USTTProcessorBase::OnTranscriptionResult(TranscriptionCounter, intermediateResult, DetectedLanguage); |
|
|
// No runnable pending, send accumulated result immediately
|
|
|
intermediateResult = ""; |
|
|
USTTProcessorBase::OnTranscriptionResult(TranscriptionCounter, intermediateResult, DetectedLanguage); |
|
|
} |
|
|
intermediateResult = ""; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -113,6 +113,11 @@ void USTTProcessorAzure::OnSpeechStateChanged(ESTTTalkingState TalkingState) |
|
|
void USTTProcessorAzure::StartRecognition() |
|
|
void USTTProcessorAzure::StartRecognition() |
|
|
{ |
|
|
{ |
|
|
StopRecognition(true); //In case there is something else running
|
|
|
StopRecognition(true); //In case there is something else running
|
|
|
|
|
|
// Force-destroy any leftover runnable from a non-forced stop
|
|
|
|
|
|
if (AzureRunnable) { |
|
|
|
|
|
AzureRunnable->StopRecognition(true); |
|
|
|
|
|
AzureRunnable = nullptr; |
|
|
|
|
|
} |
|
|
intermediateResult = ""; |
|
|
intermediateResult = ""; |
|
|
USTTProcessorBase::OnTranscriptionStarted(); |
|
|
USTTProcessorBase::OnTranscriptionStarted(); |
|
|
AzureRunnable = MakeUnique<FAzureRunnable>(config, audioConfig, STTManager->GetSpecialWords(), this, false); |
|
|
AzureRunnable = MakeUnique<FAzureRunnable>(config, audioConfig, STTManager->GetSpecialWords(), this, false); |
|
|
@ -120,14 +125,14 @@ void USTTProcessorAzure::StartRecognition() |
|
|
|
|
|
|
|
|
void USTTProcessorAzure::StopRecognition(bool Forced) |
|
|
void USTTProcessorAzure::StopRecognition(bool Forced) |
|
|
{ |
|
|
{ |
|
|
if (!bTranscriptionRunning) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
bTranscriptionRunning = false; |
|
|
bTranscriptionRunning = false; |
|
|
if (AzureRunnable) |
|
|
if (AzureRunnable) |
|
|
{ |
|
|
{ |
|
|
AzureRunnable->StopRecognition(Forced); |
|
|
AzureRunnable->StopRecognition(Forced); |
|
|
AzureRunnable = nullptr; |
|
|
if (Forced) { |
|
|
|
|
|
AzureRunnable = nullptr; // Immediate cleanup, no result expected
|
|
|
|
|
|
} |
|
|
|
|
|
// Non-forced: runnable finishes gracefully and delivers final result
|
|
|
if(bDebugMode && STTManager!=nullptr) |
|
|
if(bDebugMode && STTManager!=nullptr) |
|
|
STTManager->OnSTTLog.Broadcast(TEXT("Recognition thread stopped.")); |
|
|
STTManager->OnSTTLog.Broadcast(TEXT("Recognition thread stopped.")); |
|
|
} |
|
|
} |
|
|
@ -135,7 +140,11 @@ void USTTProcessorAzure::StopRecognition(bool Forced) |
|
|
|
|
|
|
|
|
void USTTProcessorAzure::OnRecognizing(const FString& RecognizedText) |
|
|
void USTTProcessorAzure::OnRecognizing(const FString& RecognizedText) |
|
|
{ |
|
|
{ |
|
|
if (IsValid(STTManager) && STTManager->IsBlocked()) |
|
|
if (!bTranscriptionRunning) |
|
|
|
|
|
return; |
|
|
|
|
|
if (!IsValid(STTManager)) |
|
|
|
|
|
return; |
|
|
|
|
|
if (STTManager->IsBlocked()) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
FString tmpResult; |
|
|
FString tmpResult; |
|
|
@ -149,7 +158,9 @@ void USTTProcessorAzure::OnRecognizing(const FString& RecognizedText) |
|
|
|
|
|
|
|
|
void USTTProcessorAzure::OnRecognized(const FString& RecognizedText, const FString& Language) |
|
|
void USTTProcessorAzure::OnRecognized(const FString& RecognizedText, const FString& Language) |
|
|
{ |
|
|
{ |
|
|
if (IsValid(STTManager) && STTManager->IsBlocked()) |
|
|
if (!IsValid(STTManager)) |
|
|
|
|
|
return; |
|
|
|
|
|
if (STTManager->IsBlocked()) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
this->DetectedLanguage = Language; |
|
|
this->DetectedLanguage = Language; |
|
|
@ -178,22 +189,32 @@ void USTTProcessorAzure::OnConnectionSuccess() |
|
|
void USTTProcessorAzure::OnRunnableEnded() |
|
|
void USTTProcessorAzure::OnRunnableEnded() |
|
|
{ |
|
|
{ |
|
|
bTranscriptionRunning = false; |
|
|
bTranscriptionRunning = false; |
|
|
|
|
|
AzureRunnable = nullptr; |
|
|
|
|
|
|
|
|
if (!intermediateResult.IsEmpty()) { |
|
|
if (IsValid(STTManager)) { |
|
|
STTManager->OnTranscriptionReceived.Broadcast(TranscriptionCounter, *intermediateResult, this->DetectedLanguage); |
|
|
// Send any remaining intermediate result that wasn't finalized by OnRecognized
|
|
|
intermediateResult.Empty(); |
|
|
if (!intermediateResult.IsEmpty()) { |
|
|
|
|
|
USTTProcessorBase::OnTranscriptionResult(TranscriptionCounter, intermediateResult, DetectedLanguage); |
|
|
|
|
|
intermediateResult.Empty(); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
// Ensure we return to SILENCE even if no result was produced
|
|
|
|
|
|
// (empty audio, network timeout, etc.) to prevent stuck TRANSCRIBING state
|
|
|
|
|
|
STTManager->UserSpeechStateChanged(ESTTTalkingState::SILENCE); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
AzureRunnable = nullptr; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void USTTProcessorAzure::OnAzureError(FString Error) |
|
|
void USTTProcessorAzure::OnAzureError(FString Error) |
|
|
{ |
|
|
{ |
|
|
if (IsValid(STTManager)) |
|
|
|
|
|
STTManager->OnSTTError.Broadcast(Error); |
|
|
|
|
|
|
|
|
|
|
|
bTranscriptionRunning = false; |
|
|
bTranscriptionRunning = false; |
|
|
AzureRunnable = nullptr; |
|
|
AzureRunnable = nullptr; |
|
|
|
|
|
intermediateResult.Empty(); |
|
|
|
|
|
|
|
|
|
|
|
if (IsValid(STTManager)) { |
|
|
|
|
|
STTManager->OnSTTError.Broadcast(Error); |
|
|
|
|
|
STTManager->UserSpeechStateChanged(ESTTTalkingState::SILENCE); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
FString USTTProcessorAzure::AzureEnumToString(EAzureLanguages Language) |
|
|
FString USTTProcessorAzure::AzureEnumToString(EAzureLanguages Language) |
|
|
|