Browse Source

Unified Word Lists in STT

master
Tillman Staffen 2 days ago
parent
commit
cf9ac0a5cb
  1. 29
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/AvatarCore_STT.Build.cs
  2. 4
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Private/Processor/Azure/STTProcessorAzure.cpp
  3. 438
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Private/Processor/Whisper/STTProcessorWhisper.cpp
  4. 10
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Private/Processor/Whisper/STTWhisperProcessorConfig.cpp
  5. 17
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Private/STTManagerBase.cpp
  6. 2
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/Processor/Azure/STTAzureProcessorConfig.h
  7. 2
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/Processor/STTProcessorBase.h
  8. 47
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/Processor/Whisper/STTProcessorWhisper.h
  9. 38
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/Processor/Whisper/STTWhisperProcessorConfig.h
  10. 3
      Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/STTStructs.h
  11. 8
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/CMakeLists.txt
  12. 81
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_api_c_common.h
  13. 80
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_api_c_diagnostics.h
  14. 24
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_api_c_error.h
  15. 13
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_api_c_pal.h
  16. 845
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_debug.h
  17. 455
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_error.h
  18. 51
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c.h
  19. 27
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_audio_config.h
  20. 173
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_audio_processing_options.h
  21. 67
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_audio_stream.h
  22. 93
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_audio_stream_format.h
  23. 15
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_auto_detect_source_lang_config.h
  24. 81
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_common.h
  25. 46
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_connection.h
  26. 28
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_conversation.h
  27. 11
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_conversation_transcription_result.h
  28. 63
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_conversation_translator.h
  29. 8
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_diagnostics.h
  30. 15
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_dialog_service_config.h
  31. 92
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_dialog_service_connector.h
  32. 21
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_embedded_speech_config.h
  33. 9
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_error.h
  34. 105
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_ext_audiocompression.h
  35. 29
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_factory.h
  36. 33
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_grammar.h
  37. 9
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_hybrid_speech_config.h
  38. 16
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_intent_recognizer.h
  39. 11
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_intent_result.h
  40. 17
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_intent_trigger.h
  41. 37
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_json.h
  42. 17
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_keyword_recognition_model.h
  43. 18
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_language_understanding_model.h
  44. 28
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_meeting.h
  45. 12
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_meeting_transcription_result.h
  46. 12
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_operations.h
  47. 15
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_participant.h
  48. 33
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_pattern_matching_model.h
  49. 33
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_pronunciation_assessment_config.h
  50. 159
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_property_bag.h
  51. 66
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_recognizer.h
  52. 108
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_result.h
  53. 16
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_session.h
  54. 13
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_source_lang_config.h
  55. 37
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speaker_recognition.h
  56. 171
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speech_config.h
  57. 13
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speech_recognition_model.h
  58. 16
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speech_translation_config.h
  59. 14
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speech_translation_model.h
  60. 17
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_synthesis_request.h
  61. 74
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_synthesizer.h
  62. 17
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_translation_recognizer.h
  63. 14
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_translation_result.h
  64. 13
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_user.h
  65. 548
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/spxdebug.h
  66. 449
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/spxerror.h
  67. 9
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/CMakeLists.txt
  68. 82
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/azac_api_cxx_common.h
  69. 117
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx.h
  70. 338
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_config.h
  71. 239
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_data_stream.h
  72. 358
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_processing_options.h
  73. 995
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_stream.h
  74. 215
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_stream_format.h
  75. 141
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_auto_detect_source_lang_config.h
  76. 85
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_auto_detect_source_lang_result.h
  77. 70
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_class_language_model.h
  78. 16
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_common.h
  79. 346
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_connection.h
  80. 68
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_connection_eventargs.h
  81. 152
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_connection_message.h
  82. 79
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_connection_message_eventargs.h
  83. 340
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation.h
  84. 509
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_transcriber.h
  85. 165
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_transcription_eventargs.h
  86. 72
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_transcription_result.h
  87. 448
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_translator.h
  88. 262
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_translator_events.h
  89. 89
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversational_language_understanding_model.h
  90. 268
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_dialog_service_config.h
  91. 547
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_dialog_service_connector.h
  92. 148
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_dialog_service_connector_eventargs.h
  93. 324
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_embedded_speech_config.h
  94. 1685
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_enums.h
  95. 108
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_event_logger.h
  96. 47
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_eventargs.h
  97. 202
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_eventsignal.h
  98. 166
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_eventsignalbase.h
  99. 115
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_file_logger.h
  100. 70
      Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_grammar.h

29
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/AvatarCore_STT.Build.cs

@ -39,26 +39,26 @@ public class AvatarCore_STT : ModuleRules
PublicIncludePaths.AddRange(
new string[] {
// ... add public include paths required here ...
Path.Combine(ModuleDirectory, "ThirdParty", "portaudio", "include"),
Path.Combine(ModuleDirectory, "..", "ThirdParty", "portaudio", "include"),
}
);
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "ThirdParty", "fvad", "include"));
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "ThirdParty", "fvad", "lib", "fvad.lib"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "..", "ThirdParty", "fvad", "include"));
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "..", "ThirdParty", "fvad", "lib", "fvad.lib"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "ThirdParty", "SpeexDSP", "include"));
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "ThirdParty", "SpeexDSP", "lib", "libspeexdsp.dll.a"));
PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "ThirdParty", "SpeexDSP", "lib", "libspeexdsp-1.dll"));
RuntimeDependencies.Add(Path.Combine(@"$(BinaryOutputDir)", "libspeexdsp-1.dll"), Path.Combine(ModuleDirectory, "ThirdParty", "SpeexDSP", "lib", "libspeexdsp-1.dll"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "..", "ThirdParty", "SpeexDSP", "include"));
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "..", "ThirdParty", "SpeexDSP", "lib", "libspeexdsp.dll.a"));
PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "..", "ThirdParty", "SpeexDSP", "lib", "libspeexdsp-1.dll"));
RuntimeDependencies.Add(Path.Combine(@"$(BinaryOutputDir)", "libspeexdsp-1.dll"), Path.Combine(ModuleDirectory, "..", "ThirdParty", "SpeexDSP", "lib", "libspeexdsp-1.dll"));
CppStandard = CppStandardVersion.Cpp20;
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "ThirdParty", "AzureWrapper", "include", "c_api"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "ThirdParty", "AzureWrapper", "include", "cxx_api"));
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "ThirdParty", "AzureWrapper", "libs", "Microsoft.CognitiveServices.Speech.core.lib"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "..", "ThirdParty", "AzureWrapper", "include", "c_api"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "..", "ThirdParty", "AzureWrapper", "include", "cxx_api"));
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "..", "ThirdParty", "AzureWrapper", "libs", "Microsoft.CognitiveServices.Speech.core.lib"));
foreach (string DynamicLib in GetDynamicLibraries())
{
PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "ThirdParty", "AzureWrapper", "libs", "Runtime", DynamicLib));
RuntimeDependencies.Add(Path.Combine(@"$(BinaryOutputDir)", DynamicLib), Path.Combine(ModuleDirectory, "ThirdParty", "AzureWrapper", "libs", "Runtime", DynamicLib));
PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "..", "ThirdParty", "AzureWrapper", "libs", "Runtime", DynamicLib));
RuntimeDependencies.Add(Path.Combine(@"$(BinaryOutputDir)", DynamicLib), Path.Combine(ModuleDirectory, "..", "ThirdParty", "AzureWrapper", "libs", "Runtime", DynamicLib));
}
PrivateIncludePaths.AddRange(
@ -80,7 +80,7 @@ public class AvatarCore_STT : ModuleRules
// PortAudio linking for Win64
if (Target.Platform == UnrealTargetPlatform.Win64)
{
string PortAudioLibDir = Path.Combine(ModuleDirectory, "ThirdParty", "portaudio", "lib");
string PortAudioLibDir = Path.Combine(ModuleDirectory, "..", "ThirdParty", "portaudio", "lib");
PublicAdditionalLibraries.Add(Path.Combine(PortAudioLibDir, "portaudio_x64.lib")); // Link .lib for static symbols
string PortAudioDllPath = Path.Combine(PortAudioLibDir, "portaudio_x64.dll");
PublicDelayLoadDLLs.Add(PortAudioDllPath);
@ -95,6 +95,9 @@ public class AvatarCore_STT : ModuleRules
"Slate",
"SlateCore",
"AvatarCore_AI",
"HTTP",
"Json",
"JsonUtilities",
// ... add private dependencies that you statically link with here ...
}
);

4
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Private/Processor/Azure/STTProcessorAzure.cpp

@ -51,7 +51,7 @@ void USTTProcessorAzure::InitSTTProcessor(USTTManagerBase* BaseSTTManager, USTTB
if(bDebugMode)
STTManager->OnSTTLog.Broadcast(TEXT("SpeechConfig initialized successfully."));
AzureRunnable = MakeUnique<FAzureRunnable>(config, audioConfig, AzureProcessorConfig->AzurePhraseList, this, true);
AzureRunnable = MakeUnique<FAzureRunnable>(config, audioConfig, STTManager->GetSpecialWords(), this, true);
}
void USTTProcessorAzure::ClearSTTProcessor()
@ -118,7 +118,7 @@ void USTTProcessorAzure::StartRecognition()
StopRecognition(true); //In case there is something else running
intermediateResult = "";
USTTProcessorBase::OnTranscriptionStarted();
AzureRunnable = MakeUnique<FAzureRunnable>(config, audioConfig, AzureProcessorConfig->AzurePhraseList, this, false);
AzureRunnable = MakeUnique<FAzureRunnable>(config, audioConfig, STTManager->GetSpecialWords(), this, false);
}
void USTTProcessorAzure::StopRecognition(bool Forced)

438
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Private/Processor/Whisper/STTProcessorWhisper.cpp

@ -0,0 +1,438 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Processor/Whisper/STTProcessorWhisper.h"
#include "STTManagerBase.h"
#include "HttpModule.h"
#include "Interfaces/IHttpRequest.h"
#include "Interfaces/IHttpResponse.h"
#include "Serialization/JsonSerializer.h"
#include "Dom/JsonObject.h"
namespace
{
static void AppendStringToBody(TArray<uint8>& Body, const FString& Str)
{
FTCHARToUTF8 Converter(*Str);
Body.Append(reinterpret_cast<const uint8*>(Converter.Get()), Converter.Length());
}
static const FString TranscribeModelEnumToString(EOpenAITranscriptionModel Model)
{
switch (Model)
{
case EOpenAITranscriptionModel::Whisper1:
return TEXT("whisper-1");
break;
case EOpenAITranscriptionModel::TranscribeMini4o:
return TEXT("gpt-4o-mini-transcribe");
break;
case EOpenAITranscriptionModel::Transcribe4o:
return TEXT("gpt-4o-transcribe");
break;
default:
return TEXT("");
break;
}
}
}
void USTTProcessorWhisper::InitSTTProcessor(USTTManagerBase* BaseSTTManager, USTTBaseProcessorConfig* InProcessorConfig, bool InDebugMode)
{
USTTProcessorBase::InitSTTProcessor(BaseSTTManager, InProcessorConfig, InDebugMode);
WhisperProcessorConfig = Cast<USTTWhisperProcessorConfig>(InProcessorConfig);
if(!WhisperProcessorConfig)
{
if (IsValid(STTManager))
STTManager->OnSTTError.Broadcast(TEXT("Whisper Processor Config is invalid."));
return;
}
if (WhisperProcessorConfig->OpenAI_API_Key.IsEmpty()) {
if (IsValid(STTManager))
STTManager->OnSTTError.Broadcast(TEXT("OpenAI API Key not set. Needs to be done before initializing modules."));
return;
}
NormalizeWhisperURL();
if (IsValid(STTManager))
{
STTManager->OnSpeechStateChanged.AddUniqueDynamic(this, &USTTProcessorWhisper::OnSpeechStateChanged);
}
PerformHealthCheck();
}
void USTTProcessorWhisper::ClearSTTProcessor()
{
USTTProcessorBase::ClearSTTProcessor();
BufferedPCMData.Empty();
bHasBufferedAudioInformation = false;
for (TSharedPtr<IHttpRequest, ESPMode::ThreadSafe>& Request : ActiveRequests)
{
if (Request.IsValid())
{
Request->OnProcessRequestComplete().Unbind();
Request->CancelRequest();
}
}
ActiveRequests.Empty();
}
void USTTProcessorWhisper::DestroySTTProcessor()
{
ClearSTTProcessor();
STTManager = nullptr;
}
void USTTProcessorWhisper::OnChunkReceived(TArray<int16> PCMData, FAudioInformation AudioInformation)
{
if (CurrentTalkingState != ESTTTalkingState::TALKING)
return;
if (PCMData.Num() == 0)
return;
if (!bHasBufferedAudioInformation)
{
BufferedAudioInformation = AudioInformation;
bHasBufferedAudioInformation = true;
}
else if (BufferedAudioInformation.SampleRate != AudioInformation.SampleRate ||
BufferedAudioInformation.NumChannels != AudioInformation.NumChannels)
{
BufferedPCMData.Empty();
BufferedAudioInformation = AudioInformation;
}
const int64 BytesPerSample = sizeof(int16);
const int64 CurrentBytes = static_cast<int64>(BufferedPCMData.Num()) * BytesPerSample;
const int64 NewBytes = static_cast<int64>(PCMData.Num()) * BytesPerSample;
const int64 MaxUploadBytes = static_cast<int64>(25) * 1024 * 1024;
const int64 MaxAudioBytes = MaxUploadBytes - 1024;
if (CurrentBytes + NewBytes > MaxAudioBytes)
{
int64 ExcessBytes = CurrentBytes + NewBytes - MaxAudioBytes;
int64 SamplesToRemove = (ExcessBytes + BytesPerSample - 1) / BytesPerSample;
if (SamplesToRemove >= BufferedPCMData.Num())
{
BufferedPCMData.Empty();
if (NewBytes > MaxAudioBytes)
{
int64 NewSamplesAllowed = MaxAudioBytes / BytesPerSample;
if (NewSamplesAllowed > 0 && NewSamplesAllowed < PCMData.Num())
{
int32 StartIndex = PCMData.Num() - static_cast<int32>(NewSamplesAllowed);
BufferedPCMData.Append(&PCMData[StartIndex], static_cast<int32>(NewSamplesAllowed));
}
}
else
{
BufferedPCMData.Append(PCMData);
}
}
else
{
BufferedPCMData.RemoveAt(0, static_cast<int32>(SamplesToRemove), EAllowShrinking::No);
BufferedPCMData.Append(PCMData);
}
}
else
{
BufferedPCMData.Append(PCMData);
}
}
void USTTProcessorWhisper::OnSpeechStateChanged(ESTTTalkingState TalkingState)
{
CurrentTalkingState = TalkingState;
if (TalkingState == ESTTTalkingState::BLOCKED)
{
ClearSTTProcessor();
return;
}
if (TalkingState == ESTTTalkingState::SILENCE || TalkingState == ESTTTalkingState::TRANSCRIBING)
{
StartTranscriptionFromBuffer();
}
}
void USTTProcessorWhisper::StartTranscriptionFromBuffer()
{
if (BufferedPCMData.Num() == 0 || !bHasBufferedAudioInformation)
return;
TArray<int16> PCMDataCopy = BufferedPCMData;
FAudioInformation AudioInfoCopy = BufferedAudioInformation;
BufferedPCMData.Empty();
bHasBufferedAudioInformation = false;
// Require at least x seconds of audio before sending to Whisper
if (AudioInfoCopy.SampleRate > 0 && AudioInfoCopy.NumChannels > 0)
{
const float Frames = static_cast<float>(PCMDataCopy.Num()) / static_cast<float>(AudioInfoCopy.NumChannels);
const float DurationSeconds = Frames / static_cast<float>(AudioInfoCopy.SampleRate);
if (DurationSeconds < WhisperProcessorConfig->MinDuration)
{
return;
}
}
TArray<uint8> WavData;
if (!BuildWavFromPCM(PCMDataCopy, AudioInfoCopy, WavData))
{
if (IsValid(STTManager))
STTManager->OnSTTError.Broadcast(TEXT("Failed to build WAV data for Whisper transcription."));
return;
}
const int64 MaxUploadBytes = static_cast<int64>(25) * 1024 * 1024;
if (WavData.Num() > MaxUploadBytes)
{
if (IsValid(STTManager))
STTManager->OnSTTError.Broadcast(TEXT("Whisper audio size exceeds 25MB limit. Transcription aborted."));
return;
}
SendWhisperRequest(MoveTemp(WavData));
}
bool USTTProcessorWhisper::BuildWavFromPCM(const TArray<int16>& PCMData, const FAudioInformation& AudioInformation, TArray<uint8>& OutWavData) const
{
if (PCMData.Num() == 0)
return false;
if (AudioInformation.SampleRate <= 0 || AudioInformation.NumChannels <= 0)
return false;
const uint32 BitsPerSample = 16;
const uint32 BytesPerSample = BitsPerSample / 8;
const uint32 NumSamples = static_cast<uint32>(PCMData.Num());
const uint32 ByteRate = static_cast<uint32>(AudioInformation.SampleRate) * static_cast<uint32>(AudioInformation.NumChannels) * BytesPerSample;
const uint32 BlockAlign = static_cast<uint32>(AudioInformation.NumChannels) * BytesPerSample;
const uint32 Subchunk1Size = 16;
const uint32 AudioFormat = 1;
const uint32 Subchunk2Size = NumSamples * BytesPerSample;
const uint32 ChunkSize = 4 + (8 + Subchunk1Size) + (8 + Subchunk2Size);
OutWavData.Reset();
OutWavData.Reserve(ChunkSize + 8);
auto AppendLittleEndian = [&OutWavData](uint32 Value, int32 ByteCount)
{
for (int32 i = 0; i < ByteCount; i++)
{
OutWavData.Add(static_cast<uint8>((Value >> (i * 8)) & 0xFF));
}
};
OutWavData.Append(reinterpret_cast<const uint8*>("RIFF"), 4);
AppendLittleEndian(ChunkSize, 4);
OutWavData.Append(reinterpret_cast<const uint8*>("WAVE"), 4);
OutWavData.Append(reinterpret_cast<const uint8*>("fmt "), 4);
AppendLittleEndian(Subchunk1Size, 4);
AppendLittleEndian(AudioFormat, 2);
AppendLittleEndian(static_cast<uint32>(AudioInformation.NumChannels), 2);
AppendLittleEndian(static_cast<uint32>(AudioInformation.SampleRate), 4);
AppendLittleEndian(ByteRate, 4);
AppendLittleEndian(BlockAlign, 2);
AppendLittleEndian(BitsPerSample, 2);
OutWavData.Append(reinterpret_cast<const uint8*>("data"), 4);
AppendLittleEndian(Subchunk2Size, 4);
const uint8* PCMDataPtr = reinterpret_cast<const uint8*>(PCMData.GetData());
OutWavData.Append(PCMDataPtr, Subchunk2Size);
return true;
}
void USTTProcessorWhisper::BuildMultipartBody(const TArray<uint8>& WavData, const FString& Boundary, TArray<uint8>& OutBody, const FString& Prompt) const
{
OutBody.Reset();
FString BoundaryLine = FString::Printf(TEXT("--%s\r\n"), *Boundary);
AppendStringToBody(OutBody, BoundaryLine);
AppendStringToBody(OutBody, TEXT("Content-Disposition: form-data; name=\"model\"\r\n\r\n"));
AppendStringToBody(OutBody, TranscribeModelEnumToString(WhisperProcessorConfig->Model) + TEXT("\r\n"));
if (!Prompt.IsEmpty())
{
BoundaryLine = FString::Printf(TEXT("--%s\r\n"), *Boundary);
AppendStringToBody(OutBody, BoundaryLine);
AppendStringToBody(OutBody, TEXT("Content-Disposition: form-data; name=\"prompt\"\r\n\r\n"));
AppendStringToBody(OutBody, Prompt + TEXT("\r\n"));
}
BoundaryLine = FString::Printf(TEXT("--%s\r\n"), *Boundary);
AppendStringToBody(OutBody, BoundaryLine);
AppendStringToBody(OutBody, TEXT("Content-Disposition: form-data; name=\"file\"; filename=\"audio.wav\"\r\n"));
AppendStringToBody(OutBody, TEXT("Content-Type: audio/wav\r\n\r\n"));
OutBody.Append(WavData);
AppendStringToBody(OutBody, TEXT("\r\n"));
BoundaryLine = FString::Printf(TEXT("--%s--\r\n"), *Boundary);
AppendStringToBody(OutBody, BoundaryLine);
}
void USTTProcessorWhisper::NormalizeWhisperURL()
{
if (!WhisperProcessorConfig)
return;
NormalizedWhisperURL = WhisperProcessorConfig->WhisperURL;
if (!NormalizedWhisperURL.StartsWith(TEXT("http://")) && !NormalizedWhisperURL.StartsWith(TEXT("https://")))
{
NormalizedWhisperURL = FString::Printf(TEXT("https://%s"), *NormalizedWhisperURL);
}
}
void USTTProcessorWhisper::PerformHealthCheck()
{
if (!WhisperProcessorConfig)
return;
if (NormalizedWhisperURL.IsEmpty())
NormalizeWhisperURL();
FHttpModule& HttpModule = FHttpModule::Get();
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = HttpModule.CreateRequest();
Request->SetURL(NormalizedWhisperURL);
Request->SetVerb(TEXT("GET"));
FString AuthHeader = FString::Printf(TEXT("Bearer %s"), *WhisperProcessorConfig->OpenAI_API_Key);
Request->SetHeader(TEXT("Authorization"), AuthHeader);
Request->OnProcessRequestComplete().BindLambda([
WeakManager = TWeakObjectPtr<USTTManagerBase>(STTManager)](FHttpRequestPtr Req, FHttpResponsePtr Resp, bool bWasSuccessful)
{
if (!WeakManager.IsValid())
return;
USTTManagerBase* Manager = WeakManager.Get();
if (!bWasSuccessful || !Resp.IsValid())
{
Manager->OnSTTError.Broadcast(TEXT("Whisper initialization check failed: URL not reachable."));
return;
}
int32 StatusCode = Resp->GetResponseCode();
if (StatusCode == 401)
{
Manager->OnSTTError.Broadcast(TEXT("Whisper initialization check failed: API key invalid (401)."));
}
});
Request->ProcessRequest();
}
void USTTProcessorWhisper::SendWhisperRequest(TArray<uint8>&& WavData)
{
if (!WhisperProcessorConfig)
return;
if (NormalizedWhisperURL.IsEmpty())
NormalizeWhisperURL();
FHttpModule& HttpModule = FHttpModule::Get();
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> Request = HttpModule.CreateRequest();
Request->SetURL(NormalizedWhisperURL);
Request->SetVerb(TEXT("POST"));
FString AuthHeader = FString::Printf(TEXT("Bearer %s"), *WhisperProcessorConfig->OpenAI_API_Key);
Request->SetHeader(TEXT("Authorization"), AuthHeader);
Request->SetHeader(TEXT("Accept"), TEXT("application/json"));
FString Boundary = TEXT("----AvatarCoreSTTWhisperBoundary");
FString ContentType = FString::Printf(TEXT("multipart/form-data; boundary=%s"), *Boundary);
Request->SetHeader(TEXT("Content-Type"), ContentType);
FString Prompt;
if (IsValid(STTManager))
{
Prompt = STTManager->GetSpecialWordsAsString();
}
TArray<uint8> Body;
BuildMultipartBody(WavData, Boundary, Body, Prompt);
Request->SetContent(Body);
OnTranscriptionStarted();
int32 TranscriptionId = TranscriptionCounter;
TWeakObjectPtr<USTTProcessorWhisper> WeakThis(this);
TSharedPtr<IHttpRequest, ESPMode::ThreadSafe> RequestPtr = Request;
Request->OnProcessRequestComplete().BindLambda([
WeakThis,
RequestPtr,
TranscriptionId](FHttpRequestPtr Req, FHttpResponsePtr Resp, bool bWasSuccessful)
{
if (!WeakThis.IsValid())
return;
USTTProcessorWhisper* Self = WeakThis.Get();
Self->ActiveRequests.Remove(RequestPtr);
if (!bWasSuccessful || !Resp.IsValid())
{
if (IsValid(Self->STTManager))
Self->STTManager->OnSTTError.Broadcast(TEXT("Whisper request failed or no response received."));
Self->bTranscriptionRunning = false;
return;
}
int32 StatusCode = Resp->GetResponseCode();
if (StatusCode == 401)
{
if (IsValid(Self->STTManager))
Self->STTManager->OnSTTError.Broadcast(TEXT("Whisper request unauthorized (401). Please check API key."));
Self->bTranscriptionRunning = false;
return;
}
else if (StatusCode < 200 || StatusCode >= 300)
{
FString ErrorBody = Resp->GetContentAsString();
if (IsValid(Self->STTManager))
{
FString ErrorMessage = FString::Printf(TEXT("Whisper request failed with HTTP %d: %s"), StatusCode, *ErrorBody);
Self->STTManager->OnSTTError.Broadcast(ErrorMessage);
}
Self->bTranscriptionRunning = false;
return;
}
FString JsonString = Resp->GetContentAsString();
TSharedPtr<FJsonObject> RootObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(JsonString);
if (!FJsonSerializer::Deserialize(Reader, RootObject) || !RootObject.IsValid())
{
if (IsValid(Self->STTManager))
Self->STTManager->OnSTTError.Broadcast(TEXT("Failed to parse Whisper JSON response."));
Self->bTranscriptionRunning = false;
return;
}
FString Text;
if (!RootObject->TryGetStringField(TEXT("text"), Text))
{
if (IsValid(Self->STTManager))
Self->STTManager->OnSTTError.Broadcast(TEXT("Whisper response JSON does not contain 'text' field."));
Self->bTranscriptionRunning = false;
return;
}
Self->OnTranscriptionResult(TranscriptionId, Text);
});
ActiveRequests.Add(RequestPtr);
Request->ProcessRequest();
}

10
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Private/Processor/Whisper/STTWhisperProcessorConfig.cpp

@ -0,0 +1,10 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Processor/Whisper/STTWhisperProcessorConfig.h"
#include "Processor/Whisper/STTProcessorWhisper.h"
USTTWhisperProcessorConfig::USTTWhisperProcessorConfig(const FObjectInitializer& ObjectInitializer)
{
STTProcessorClass = USTTProcessorWhisper::StaticClass();
}

17
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Private/STTManagerBase.cpp

@ -182,15 +182,24 @@ void USTTManagerBase::RemoveSpecialWords(const TArray<FString> WordsToRemove)
TArray<FString> USTTManagerBase::GetSpecialWords()
{
return SpecialWords;
TArray<FString> CombinedSpecialWords;
CombinedSpecialWords.Append(ProcessorConfig->BaseSettings.STTSpecialWords);
CombinedSpecialWords.Append(SpecialWords);
return CombinedSpecialWords;
}
FString USTTManagerBase::GetSpecialWordsAsString()
{
FString SpecialWordsString;
for (int i = 0; i < SpecialWords.Num(); i++) {
SpecialWordsString.Append(SpecialWords[i]);
if (i < SpecialWords.Num() - 1)
//Combine both the special words from STTSettings globally as also the on runtime special words (Kira, Aki etc.)
TArray<FString> CombinedSpecialWords;
CombinedSpecialWords.Append(ProcessorConfig->BaseSettings.STTSpecialWords);
CombinedSpecialWords.Append(SpecialWords);
for (int i = 0; i < CombinedSpecialWords.Num(); i++) {
SpecialWordsString.Append(CombinedSpecialWords[i]);
if (i < CombinedSpecialWords.Num() - 1)
SpecialWordsString.Append(TEXT(", "));
}
return SpecialWordsString;

2
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/Processor/Azure/STTAzureProcessorConfig.h

@ -37,8 +37,6 @@ public:
USTTAzureProcessorConfig(const FObjectInitializer& ObjectInitializer);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AvatarCoreSTT|Azure", meta = (ExposeOnSpawn = "true"))
TArray<FString> AzurePhraseList = { TEXT("b.ReX"), TEXT("Bruce B.") };
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AvatarCoreSTT|Azure", meta = (ExposeOnSpawn = "true"))
FString AzureAPIKey = "";
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AvatarCoreSTT|Azure", meta = (ExposeOnSpawn = "true"))

2
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/Processor/STTProcessorBase.h

@ -24,7 +24,7 @@ public:
virtual void InitSTTProcessor(USTTManagerBase* BaseSTTManager, USTTBaseProcessorConfig* InPreprocessorConfig, bool InDebugMode = false) { STTManager = BaseSTTManager; PreprocessorConfig = InPreprocessorConfig; bDebugMode = InDebugMode; };
UFUNCTION()
void ClearSTTProcessor();
virtual void ClearSTTProcessor();
UFUNCTION()
virtual void DestroySTTProcessor() {};

47
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/Processor/Whisper/STTProcessorWhisper.h

@ -0,0 +1,47 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Processor/STTProcessorBase.h"
#include "Processor/Whisper/STTWhisperProcessorConfig.h"
#include "STTProcessorWhisper.generated.h"
/**
*
*/
UCLASS()
class USTTProcessorWhisper : public USTTProcessorBase
{
GENERATED_BODY()
public:
void InitSTTProcessor(USTTManagerBase* BaseSTTManager, USTTBaseProcessorConfig* InProcessorConfig, bool InDebugMode = false) override;
virtual void ClearSTTProcessor() override;
virtual void DestroySTTProcessor() override;
virtual void OnChunkReceived(TArray<int16> PCMData, FAudioInformation AudioInformation) override;
UFUNCTION()
void OnSpeechStateChanged(ESTTTalkingState TalkingState);
private:
void StartTranscriptionFromBuffer();
bool BuildWavFromPCM(const TArray<int16>& PCMData, const FAudioInformation& AudioInformation, TArray<uint8>& OutWavData) const;
void BuildMultipartBody(const TArray<uint8>& WavData, const FString& Boundary, TArray<uint8>& OutBody, const FString& Prompt) const;
void NormalizeWhisperURL();
void PerformHealthCheck();
void SendWhisperRequest(TArray<uint8>&& WavData);
private:
USTTWhisperProcessorConfig* WhisperProcessorConfig = nullptr;
FString NormalizedWhisperURL;
TArray<int16> BufferedPCMData;
FAudioInformation BufferedAudioInformation;
bool bHasBufferedAudioInformation = false;
TArray<TSharedPtr<class IHttpRequest, ESPMode::ThreadSafe>> ActiveRequests;
ESTTTalkingState CurrentTalkingState = ESTTTalkingState::SILENCE;
};

38
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/Processor/Whisper/STTWhisperProcessorConfig.h

@ -0,0 +1,38 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Processor/STTBaseProcessorConfig.h"
#include "STTWhisperProcessorConfig.generated.h"
UENUM(BlueprintType)
enum class EOpenAITranscriptionModel : uint8
{
Whisper1 UMETA(DisplayName = "Whisper-1"),
TranscribeMini4o UMETA(DisplayName = "4o Transcribe Mini"),
Transcribe4o UMETA(DisplayName = "4o Transcribe")
};
/**
*
*/
UCLASS()
class USTTWhisperProcessorConfig : public USTTBaseProcessorConfig
{
GENERATED_BODY()
public:
USTTWhisperProcessorConfig(const FObjectInitializer& ObjectInitializer);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AvatarCoreSTT|Whisper", meta = (ExposeOnSpawn = "true"))
FString OpenAI_API_Key = "";
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AvatarCoreSTT|Whisper", meta = (ExposeOnSpawn = "true"))
FString WhisperURL = "api.openai.com/v1/audio/transcriptions";
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AvatarCoreSTT|Whisper", meta = (ExposeOnSpawn = "true"))
EOpenAITranscriptionModel Model = EOpenAITranscriptionModel::Transcribe4o;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AvatarCoreSTT|Whisper", meta = (ExposeOnSpawn = "true"))
float MinDuration = 0.75f;
};

3
Unreal/Plugins/AvatarCore_STT/Source/AvatarCore_STT/Public/STTStructs.h

@ -123,4 +123,7 @@ struct FSTTBaseSettings
FSpeexDSPSettings SpeexDSPSettings;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "Transcriptions to always change to another word.", Category = "STT|Base"))
TArray<FSTTWordReplacement> STTReplacements;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "Special words that the transcription service needs to know (e.g. b.ReX or Bruce-B).", Category = "STT|Base"))
TArray<FString> STTSpecialWords;
};

8
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/CMakeLists.txt

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.19)
project(c_headers)
set(SRC_DIR "${PROJECT_SOURCE_DIR}")
add_library(${PROJECT_NAME} INTERFACE ${SPEECH_C_API_HEADERS})
target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER api)

81
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_api_c_common.h

@ -0,0 +1,81 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/azai/license202106 for the full license information.
//
#pragma once
// TODO: TFS#3671215 - Vision: C/C++ azac_api* files are in shared include directory, speech and vision share
#include <stdbool.h>
#include <azac_error.h>
#ifdef __cplusplus
#define AZAC_EXTERN_C extern "C"
#else
#define AZAC_EXTERN_C
#endif
#ifdef _WIN32
#define AZAC_DLL_EXPORT __declspec(dllexport)
#define AZAC_DLL_IMPORT __declspec(dllimport)
#define AZAC_API_NOTHROW __declspec(nothrow)
#define AZAC_API_RESULTTYPE AZACHR
#define AZAC_API_CALLTYPE __stdcall
#define AZAC_API_VCALLTYPE __cdecl
#else
#define AZAC_DLL_EXPORT __attribute__ ((__visibility__("default")))
#define AZAC_DLL_IMPORT
#define AZAC_API_NOTHROW __attribute__((nothrow))
#define AZAC_API_RESULTTYPE AZACHR
#define AZAC_API_CALLTYPE
#define AZAC_API_VCALLTYPE __attribute__((cdecl))
#endif
#ifdef AZAC_CONFIG_EXPORTAPIS
#define AZAC_API_EXPORT AZAC_DLL_EXPORT
#endif
#ifdef AZAC_CONFIG_IMPORTAPIS
#define AZAC_API_EXPORT AZAC_DLL_IMPORT
#endif
#ifdef AZAC_CONFIG_STATIC_LINK_APIS
#define AZAC_API_EXPORT
#endif
#ifndef AZAC_API_EXPORT
#define AZAC_API_EXPORT AZAC_DLL_IMPORT
#endif
#define AZAC_API AZAC_EXTERN_C AZAC_API_EXPORT AZAC_API_RESULTTYPE AZAC_API_NOTHROW AZAC_API_CALLTYPE
#define AZAC_API_(type) AZAC_EXTERN_C AZAC_API_EXPORT type AZAC_API_NOTHROW AZAC_API_CALLTYPE
#define AZAC_API__(type) AZAC_EXTERN_C AZAC_API_EXPORT AZAC_API_NOTHROW type AZAC_API_CALLTYPE
#define AZAC_APIV AZAC_EXTERN_C AZAC_API_EXPORT AZAC_API_NOTHROW AZAC_API_RESULTTYPE AZAC_API_VCALLTYPE
#define AZAC_APIV_(type) AZAC_EXTERN_C AZAC_API_EXPORT AZAC_API_NOTHROW type AZAC_API_VCALLTYPE
#define AZAC_API_PRIVATE AZAC_EXTERN_C AZAC_API_RESULTTYPE AZAC_API_NOTHROW AZAC_API_CALLTYPE
#define AZAC_API_PRIVATE_(type) AZAC_EXTERN_C type AZAC_API_NOTHROW AZAC_API_CALLTYPE
struct _azac_empty {};
typedef struct _azac_empty* _azachandle;
typedef _azachandle AZAC_HANDLE;
#define AZAC_HANDLE_INVALID ((AZAC_HANDLE)-1)
#define AZAC_HANDLE_RESERVED1 ((AZAC_HANDLE)+1)
#ifndef AZAC_SUPPRESS_DIAGNOSTICS_INCLUDE_FROM_COMMON
#define AZAC_SUPPRESS_COMMON_INCLUDE_FROM_DIAGNOSTICS
#include <azac_api_c_diagnostics.h>
#undef AZAC_SUPPRESS_COMMON_INCLUDE_FROM_DIAGNOSTICS
#endif
#ifndef AZAC_SUPPRESS_ERROR_INCLUDE_FROM_COMMON
#define AZAC_SUPPRESS_COMMON_INCLUDE_FROM_ERROR
#include <azac_api_c_error.h>
#undef AZAC_SUPPRESS_COMMON_INCLUDE_FROM_ERROR
#endif
#ifndef AZAC_SUPPRESS_DEBUG_INCLUDE_FROM_COMMON
#define AZAC_SUPPRESS_COMMON_INCLUDE_FROM_DEBUG
#include <azac_debug.h>
#undef AZAC_SUPPRESS_COMMON_INCLUDE_FROM_DEBUG
#endif
#define AZACPROPERTYBAGHANDLE AZAC_HANDLE

80
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_api_c_diagnostics.h

@ -0,0 +1,80 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/azai/license202106 for the full license information.
//
#pragma once
// TODO: TFS#3671215 - Vision: C/C++ azac_api* files are in shared include directory, speech and vision share
#ifndef AZAC_SUPPRESS_COMMON_INCLUDE_FROM_DIAGNOSTICS
#define AZAC_SUPPRESS_DIAGNOSTICS_INCLUDE_FROM_COMMON
#include <azac_api_c_common.h>
#undef AZAC_SUPPRESS_DIAGNOSTICS_INCLUDE_FROM_COMMON
#endif
#include <stdarg.h>
#include <stddef.h>
//
// APIs to manage logging to file
//
AZAC_API diagnostics_log_start_logging(AZAC_HANDLE hpropbag, void* reserved);
AZAC_API diagnostics_log_apply_properties(AZAC_HANDLE hpropbag, void* reserved);
AZAC_API diagnostics_log_stop_logging();
//
// APIs to manage logging events
//
typedef void(*DIAGNOSTICS_CALLBACK_FUNC)(const char *logLine);
AZAC_API diagnostics_logmessage_set_callback(DIAGNOSTICS_CALLBACK_FUNC callback);
AZAC_API diagnostics_logmessage_set_filters(const char* filters);
//
// APIs to managed eventSource events
//
typedef void(*DIAGNOSTICS_EVENTSOURCE_CALLBACK_FUNC)(const char *logLine, const int level);
AZAC_API diagnostics_eventsource_logmessage_set_callback(DIAGNOSTICS_EVENTSOURCE_CALLBACK_FUNC callback);
AZAC_API diagnostics_eventsource_logmessage_set_filters(const char* filters);
//
// APIs to manage logging to memory
//
AZAC_API_(void) diagnostics_log_memory_start_logging();
AZAC_API_(void) diagnostics_log_memory_stop_logging();
AZAC_API_(void) diagnostics_log_memory_set_filters(const char* filters);
// The binding layers use these to implement a dump to vector of strings or an output stream
AZAC_API_(size_t) diagnostics_log_memory_get_line_num_oldest();
AZAC_API_(size_t) diagnostics_log_memory_get_line_num_newest();
AZAC_API__(const char*) diagnostics_log_memory_get_line(size_t lineNum);
// Dump to file, std out or std err with optional prefix string
AZAC_API diagnostics_log_memory_dump_to_stderr(); // This calls diagnostics_log_memory_dump(nullptr, nullptr, false, true)
AZAC_API diagnostics_log_memory_dump(const char* filename, const char* linePrefix, bool emitToStdOut, bool emitToStdErr);
AZAC_API diagnostics_log_memory_dump_on_exit(const char* filename, const char* linePrefix, bool emitToStdOut, bool emitToStdErr);
//
// APIs to manage logging to the console
//
AZAC_API_(void) diagnostics_log_console_start_logging(bool logToStderr);
AZAC_API_(void) diagnostics_log_console_stop_logging();
AZAC_API_(void) diagnostics_log_console_set_filters(const char* filters);
//
// APIs to log a string
//
AZAC_API_(void) diagnostics_log_format_message(char* buffer, size_t bufferSize, int level, const char* pszTitle, const char* fileName, const int lineNumber, const char* pszFormat, va_list argptr);
AZAC_API_(void) diagnostics_log_trace_string(int level, const char* pszTitle, const char* fileName, const int lineNumber, const char* psz);
AZAC_API_(void) diagnostics_log_trace_message(int level, const char* pszTitle, const char* fileName, const int lineNumber, const char* pszFormat, ...);
AZAC_API_(void) diagnostics_log_trace_message2(int level, const char* pszTitle, const char* fileName, const int lineNumber, const char* pszFormat, va_list argptr);
AZAC_API_(void) diagnostics_set_log_level(const char * logger, const char * level);
AZAC_API_(bool) diagnostics_is_log_level_enabled(int level);
//
// Memory tracking API's
//
AZAC_API_(size_t) diagnostics_get_handle_count();
AZAC_API__(const char*) diagnostics_get_handle_info();
AZAC_API diagnostics_free_string(const char* value);

24
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_api_c_error.h

@ -0,0 +1,24 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/azai/vision/license for the full license information.
//
#pragma once
// TODO: TFS#3671215 - Vision: C/C++ azac_api* files are in shared include directory, speech and vision share
#ifndef AZAC_SUPPRESS_COMMON_INCLUDE_FROM_ERROR
#define AZAC_SUPPRESS_ERROR_INCLUDE_FROM_COMMON
#include <azac_api_c_common.h>
#undef AZAC_SUPPRESS_ERROR_INCLUDE_FROM_COMMON
#endif
typedef const char * const_char_ptr;
AZAC_API_(const_char_ptr) error_get_message(AZAC_HANDLE errorHandle);
AZAC_API_(const_char_ptr) error_get_call_stack(AZAC_HANDLE errorHandle);
AZAC_API error_get_error_code(AZAC_HANDLE errorHandle);
AZAC_API error_release(AZAC_HANDLE errorHandle);

13
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_api_c_pal.h

@ -0,0 +1,13 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/azai/license202106 for the full license information.
//
#pragma once
// TODO: TFS#3671215 - Vision: C/C++ azac_api* files are in shared include directory, speech and vision share
#include "azac_api_c_common.h"
AZAC_API_(size_t) pal_wstring_to_string(char * dst, const wchar_t * src, size_t dstSize);
AZAC_API_(size_t) pal_string_to_wstring(wchar_t * dst, const char * src, size_t dstSize);

845
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_debug.h

@ -0,0 +1,845 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/azai/license202106 for the full license information.
//
#pragma once
#include <azac_error.h>
#include <inttypes.h>
// TODO: TFS#3671215 - Vision: C/C++ azac_api* files are in shared include directory, speech and vision share
#ifndef _MSC_VER
// macros in this header generate a bunch of
// "ISO C++11 requires at least one argument for the "..." in a variadic macro" errors.
// system_header pragma is the only mechanism that helps to suppress them.
// https://stackoverflow.com/questions/35587137/how-to-suppress-gcc-variadic-macro-argument-warning-for-zero-arguments-for-a-par
// TODO: try to make macros standard-compliant.
#pragma GCC system_header
#endif
#ifndef __cplusplus
#define static_assert _Static_assert
#endif
#define UNUSED(x) (void)(x)
//-------------------------------------------------------
// Re-enabled ability to compile out all macros...
// However, currently still need to keep all macros until
// final review of all macros is complete.
//-------------------------------------------------------
#define AZAC_CONFIG_TRACE_INCLUDE_DBG_WITH_ALL 1
#ifdef AZAC_CONFIG_TRACE_INCLUDE_DBG_WITH_ALL
#if defined(AZAC_CONFIG_TRACE_ALL) && !defined(AZAC_CONFIG_DBG_TRACE_ALL) && (!defined(DEBUG) || !defined(_DEBUG))
#define AZAC_CONFIG_DBG_TRACE_ALL 1
#endif
#endif
//-------------------------------------------------------
// AZAC_ and AZAC_DBG_ macro configuration
//-------------------------------------------------------
#ifdef AZAC_CONFIG_DBG_TRACE_ALL
#define AZAC_CONFIG_DBG_TRACE_VERBOSE 1
#define AZAC_CONFIG_DBG_TRACE_INFO 1
#define AZAC_CONFIG_DBG_TRACE_WARNING 1
#define AZAC_CONFIG_DBG_TRACE_ERROR 1
#define AZAC_CONFIG_DBG_TRACE_FUNCTION 1
#define AZAC_CONFIG_DBG_TRACE_SCOPE 1
#define AZAC_CONFIG_DBG_TRACE_ASSERT 1
#define AZAC_CONFIG_DBG_TRACE_VERIFY 1
#ifndef AZAC_CONFIG_TRACE_ALL
#define AZAC_CONFIG_TRACE_ALL 1
#endif
#endif
#ifdef AZAC_CONFIG_TRACE_ALL
#define AZAC_CONFIG_TRACE_VERBOSE 1
#define AZAC_CONFIG_TRACE_INFO 1
#define AZAC_CONFIG_TRACE_WARNING 1
#define AZAC_CONFIG_TRACE_ERROR 1
#define AZAC_CONFIG_TRACE_FUNCTION 1
#define AZAC_CONFIG_TRACE_SCOPE 1
#define AZAC_CONFIG_TRACE_THROW_ON_FAIL 1
#define AZAC_CONFIG_TRACE_REPORT_ON_FAIL 1
#define AZAC_CONFIG_TRACE_RETURN_ON_FAIL 1
#define AZAC_CONFIG_TRACE_EXITFN_ON_FAIL 1
#endif
//-----------------------------------------------------------
// AZAC_TRACE macro common implementations
//-----------------------------------------------------------
#define __AZAC_TRACE_LEVEL_INFO 0x08 // Trace_Info
#define __AZAC_TRACE_LEVEL_WARNING 0x04 // Trace_Warning
#define __AZAC_TRACE_LEVEL_ERROR 0x02 // Trace_Error
#define __AZAC_TRACE_LEVEL_VERBOSE 0x10 // Trace_Verbose
#ifndef __AZAC_DO_TRACE_IMPL
#ifdef __cplusplus
#include <algorithm>
#include <stdio.h>
#include <stdarg.h>
#include <string>
inline void __azac_do_trace_message(int level, const char* pszTitle, const char* fileName, const int lineNumber, const char* pszFormat, ...) throw()
{
UNUSED(level);
bool logToConsole = false;
#if defined(DEBUG) || defined(_DEBUG)
logToConsole = true;
#endif
if (!logToConsole)
{
return;
}
try
{
va_list argptr;
va_start(argptr, pszFormat);
std::string format;
while (*pszFormat == '\n' || *pszFormat == '\r')
{
if (*pszFormat == '\r')
{
pszTitle = nullptr;
}
format += *pszFormat++;
}
if (pszTitle != nullptr)
{
format += pszTitle;
}
std::string fileNameOnly(fileName);
std::replace(fileNameOnly.begin(), fileNameOnly.end(), '\\', '/');
std::string fileNameLineNumber = " " + fileNameOnly.substr(fileNameOnly.find_last_of('/', std::string::npos) + 1) + ":" + std::to_string(lineNumber) + " ";
format += fileNameLineNumber;
format += pszFormat;
if (format.length() < 1 || format[format.length() - 1] != '\n')
{
format += "\n";
}
vfprintf(stderr, format.c_str(), argptr);
va_end(argptr);
}
catch(...)
{
}
}
#define __AZAC_DO_TRACE_IMPL __azac_do_trace_message
#else // __cplusplus
#define __AZAC_DO_TRACE_IMPL
#endif // __cplusplus
#endif
#define __AZAC_DOTRACE(level, title, fileName, lineNumber, ...) \
do { \
__AZAC_DO_TRACE_IMPL(level, title, fileName, lineNumber, ##__VA_ARGS__); \
} while (0)
#define __AZAC_TRACE_INFO(title, fileName, lineNumber, msg, ...) __AZAC_DOTRACE(__AZAC_TRACE_LEVEL_INFO, title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __AZAC_TRACE_INFO_IF(cond, title, fileName, lineNumber, msg, ...) \
do { \
int fCond = !!(cond); \
if (fCond) { \
__AZAC_TRACE_INFO(title, fileName, lineNumber, msg, ##__VA_ARGS__); \
} } while (0)
#define __AZAC_TRACE_WARNING(title, fileName, lineNumber, msg, ...) __AZAC_DOTRACE(__AZAC_TRACE_LEVEL_WARNING, title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __AZAC_TRACE_WARNING_IF(cond, title, fileName, lineNumber, msg, ...) \
do { \
int fCond = !!(cond); \
if (fCond) { \
__AZAC_TRACE_WARNING(title, fileName, lineNumber, msg, ##__VA_ARGS__); \
} } while (0)
#define __AZAC_TRACE_ERROR(title, fileName, lineNumber, msg, ...) __AZAC_DOTRACE(__AZAC_TRACE_LEVEL_ERROR, title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __AZAC_TRACE_ERROR_IF(cond, title, fileName, lineNumber, msg, ...) \
do { \
int fCond = !!(cond); \
if (fCond) { \
__AZAC_TRACE_ERROR(title, fileName, lineNumber, msg, ##__VA_ARGS__); \
} } while (0)
#define __AZAC_TRACE_VERBOSE(title, fileName, lineNumber, msg, ...) __AZAC_DOTRACE(__AZAC_TRACE_LEVEL_VERBOSE, title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __AZAC_TRACE_VERBOSE_IF(cond, title, fileName, lineNumber, msg, ...) \
do { \
int fCond = !!(cond); \
if (fCond) { \
__AZAC_TRACE_VERBOSE(title, fileName, lineNumber, msg, ##__VA_ARGS__); \
} } while (0)
#define ___AZAC_EXPR_AS_STRING(_String) "" #_String
#define __AZAC_EXPR_AS_STRING(_String) ___AZAC_EXPR_AS_STRING(_String)
#define __AZAC_TRACE_HR(title, fileName, lineNumber, hr, x) __AZAC_TRACE_ERROR(title, fileName, lineNumber, __AZAC_EXPR_AS_STRING(hr) " = 0x%0" PRIxPTR, x)
#define __AZAC_REPORT_ON_FAIL(title, fileName, lineNumber, hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
} } while (0)
#define __AZAC_REPORT_ON_FAIL_IFNOT(title, fileName, lineNumber, hr, hrNot) \
do { \
AZACHR x = hr; \
if (x != hrNot) { \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
} } } while (0)
#define __AZAC_T_RETURN_HR(title, fileName, lineNumber, hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
} \
return x; \
} while (0)
#define __AZAC_T_RETURN_HR_IF(title, fileName, lineNumber, hr, cond) \
do { \
int fCond = !!(cond); \
if (fCond) { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
} \
return x; \
} } while (0)
#define __AZAC_T_RETURN_ON_FAIL(title, fileName, lineNumber, hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
return x; \
} } while (0)
#define __AZAC_T_RETURN_ON_FAIL_IF_NOT(title, fileName, lineNumber, hr, hrNot) \
do { \
AZACHR x = hr; \
if (x != hrNot) { \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
return x; \
} } } while (0)
#define __AZAC_RETURN_HR(hr) return hr
#define __AZAC_RETURN_HR_IF(hr, cond) \
do { \
int fCond = !!(cond); \
if (fCond) { \
return hr; \
} } while (0)
#define __AZAC_RETURN_ON_FAIL(hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
return x; \
} } while (0)
#define __AZAC_RETURN_ON_FAIL_IF_NOT(hr, hrNot) \
do { \
AZACHR x = hr; \
if (x != hrNot) { \
if (AZAC_FAILED(x)) { \
return x; \
} } } while (0)
#define __AZAC_T_EXITFN_HR(title, fileName, lineNumber, hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
} \
goto AZAC_EXITFN_CLEANUP; \
} while (0)
#define __AZAC_T_EXITFN_HR_IF(title, fileName, lineNumber, hr, cond) \
do { \
int fCond = !!(cond); \
if (fCond) { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
} \
goto AZAC_EXITFN_CLEANUP; \
} } while (0)
#define __AZAC_T_EXITFN_ON_FAIL(title, fileName, lineNumber, hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
goto AZAC_EXITFN_CLEANUP; \
} } while (0)
#define __AZAC_T_EXITFN_ON_FAIL_IF_NOT(title, fileName, lineNumber, hr, hrNot) \
do { \
AZACHR x = hr; \
if (x != hrNot) { \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
goto AZAC_EXITFN_CLEANUP; \
} } } while (0)
#define __AZAC_EXITFN_HR(hr) \
do { \
AZACHR x = hr; \
goto AZAC_EXITFN_CLEANUP; \
} while (0)
#define __AZAC_EXITFN_HR_IF(hr, cond) \
do { \
int fCond = !!(cond); \
if (fCond) { \
AZACHR x = hr; \
goto AZAC_EXITFN_CLEANUP; \
} } while (0)
#define __AZAC_EXITFN_ON_FAIL(hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
goto AZAC_EXITFN_CLEANUP; \
} } while (0)
#define __AZAC_EXITFN_ON_FAIL_IF_NOT(hr, hrNot) \
do { \
AZACHR x = hr; \
if (x != hrNot) { \
if (AZAC_FAILED(x)) { \
goto AZAC_EXITFN_CLEANUP; \
} } } while (0)
#define __AZAC_TRACE_ASSERT(title, fileName, lineNumber, expr) __AZAC_TRACE_ERROR(title, fileName, lineNumber, __AZAC_EXPR_AS_STRING(expr) " = false")
#define __AZAC_TRACE_ASSERT_MSG(title, fileName, lineNumber, expr, ...) __AZAC_TRACE_ERROR(title, fileName, lineNumber, __AZAC_EXPR_AS_STRING(expr) " = false; " __VA_ARGS__)
#define __AZAC_DBG_ASSERT(title, fileName, lineNumber, expr) \
do { \
int fCond = !!(expr); \
if (!fCond) { \
__AZAC_TRACE_ASSERT(title, fileName, lineNumber, expr); \
abort(); \
} } while (0)
#define __AZAC_DBG_ASSERT_WITH_MESSAGE(title, fileName, lineNumber, expr, ...) \
do { \
int fCond = !!(expr); \
if (!fCond) { \
__AZAC_TRACE_ASSERT_MSG(title, fileName, lineNumber, expr, ##__VA_ARGS__); \
abort(); \
} } while (0)
#define __AZAC_DBG_VERIFY(title, fileName, lineNumber, expr) \
do { \
int fCond = !!(expr); \
if (!fCond) { \
__AZAC_TRACE_ASSERT(title, fileName, lineNumber, expr); \
abort(); \
} } while (0)
#define __AZAC_DBG_VERIFY_WITH_MESSAGE(title, fileName, lineNumber, expr, ...) \
do { \
int fCond = !!(expr); \
if (!fCond) { \
__AZAC_TRACE_ASSERT_MSG(title, fileName, lineNumber, expr, ##__VA_ARGS__); \
abort(); \
} } while (0)
#ifdef __cplusplus
#include <memory>
#define __AZAC_TRACE_SCOPE(t1, fileName, lineNumber, t2, x, y) \
__AZAC_TRACE_INFO(t1, fileName, lineNumber, "%s", x); \
auto evaluateYInScopeInMacros##lineNumber = y; \
auto leavingScopePrinterInMacros##lineNumber = [&evaluateYInScopeInMacros##lineNumber](int*) -> void { \
__AZAC_TRACE_INFO(t2, fileName, lineNumber, "%s", evaluateYInScopeInMacros##lineNumber); \
}; \
std::unique_ptr<int, decltype(leavingScopePrinterInMacros##lineNumber)> onExit##lineNumber((int*)1, leavingScopePrinterInMacros##lineNumber)
#ifndef __AZAC_THROW_HR_IMPL
#define __AZAC_THROW_HR_IMPL(hr) __azac_rethrow(hr)
#endif
#ifndef __AZAC_THROW_HR
#define __AZAC_THROW_HR(hr) __AZAC_THROW_HR_IMPL(hr)
#endif
#ifndef __AZAC_LOG_HR_IMPL
#define __AZAC_LOG_HR_IMPL(hr) __azac_log_only(hr)
#endif
#ifndef __AZAC_LOG_HR
#define __AZAC_LOG_HR(hr) __AZAC_LOG_HR_IMPL(hr)
#endif
#define __AZAC_T_LOG_ON_FAIL(title, fileName, lineNumber, hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
__AZAC_LOG_HR(x); \
} } while (0)
#define __AZAC_T_THROW_ON_FAIL(title, fileName, lineNumber, hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
__AZAC_THROW_HR(x); \
} } while (0)
#define __AZAC_T_THROW_ON_FAIL_IF_NOT(title, fileName, lineNumber, hr, hrNot) \
do { \
AZACHR x = hr; \
if (x != hrNot) { \
if (AZAC_FAILED(x)) { \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
__AZAC_THROW_HR(x); \
} } } while (0)
#define __AZAC_T_THROW_HR_IF(title, fileName, lineNumber, hr, cond) \
do { \
int fCond = !!(cond); \
if (fCond) { \
AZACHR x = hr; \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
__AZAC_THROW_HR(x); \
} } while (0)
#define __AZAC_T_THROW_HR(title, fileName, lineNumber, hr) \
do { \
AZACHR x = hr; \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x); \
__AZAC_THROW_HR(x); \
} while (0)
#define __AZAC_LOG_ON_FAIL(hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_LOG_HR(x); \
} } while (0)
#define __AZAC_THROW_ON_FAIL(hr) \
do { \
AZACHR x = hr; \
if (AZAC_FAILED(x)) { \
__AZAC_THROW_HR(x); \
} } while (0)
#define __AZAC_THROW_ON_FAIL_IF_NOT(hr, hrNot) \
do { \
AZACHR x = hr; \
if (x != hrNot) { \
if (AZAC_FAILED(x)) { \
__AZAC_THROW_HR(x); \
} } } while (0)
#define __AZAC_THROW_HR_IF(hr, cond) \
do { \
int fCond = !!(cond); \
if (fCond) { \
AZACHR x = hr; \
__AZAC_THROW_HR(x); \
} } while (0)
#endif // __cplusplus
//-------------------------------------------------------
// AZAC_ macro definitions
//-------------------------------------------------------
#ifdef AZAC_CONFIG_TRACE_VERBOSE
#define AZAC_TRACE_VERBOSE(msg, ...) __AZAC_TRACE_VERBOSE("AZAC_TRACE_VERBOSE: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define AZAC_TRACE_VERBOSE_IF(cond, msg, ...) __AZAC_TRACE_VERBOSE_IF(cond, "AZAC_TRACE_VERBOSE: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define AZAC_TRACE_VERBOSE(...)
#define AZAC_TRACE_VERBOSE_IF(...)
#endif
#ifdef AZAC_CONFIG_DBG_TRACE_VERBOSE
#define AZAC_DBG_TRACE_VERBOSE(msg, ...) __AZAC_TRACE_VERBOSE("AZAC_DBG_TRACE_VERBOSE: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define AZAC_DBG_TRACE_VERBOSE_IF(cond, msg, ...) __AZAC_TRACE_VERBOSE_IF(cond, "AZAC_DBG_TRACE_VERBOSE: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define AZAC_DBG_TRACE_VERBOSE(...)
#define AZAC_DBG_TRACE_VERBOSE_IF(...)
#endif
#ifdef AZAC_CONFIG_TRACE_INFO
#define AZAC_TRACE_INFO(msg, ...) __AZAC_TRACE_INFO("AZAC_TRACE_INFO: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define AZAC_TRACE_INFO_IF(cond, msg, ...) __AZAC_TRACE_INFO_IF(cond, "AZAC_TRACE_INFO: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define AZAC_TRACE_INFO(...)
#define AZAC_TRACE_INFO_IF(...)
#endif
#ifdef AZAC_CONFIG_DBG_TRACE_INFO
#define AZAC_DBG_TRACE_INFO(msg, ...) __AZAC_TRACE_INFO("AZAC_DBG_TRACE_INFO: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define AZAC_DBG_TRACE_INFO_IF(cond, msg, ...) __AZAC_TRACE_INFO_IF(cond, "AZAC_DBG_TRACE_INFO: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define AZAC_DBG_TRACE_INFO(...)
#define AZAC_DBG_TRACE_INFO_IF(...)
#endif
#ifdef AZAC_CONFIG_TRACE_WARNING
#define AZAC_TRACE_WARNING(msg, ...) __AZAC_TRACE_WARNING("AZAC_TRACE_WARNING:", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define AZAC_TRACE_WARNING_IF(cond, msg, ...) __AZAC_TRACE_WARNING_IF(cond, "AZAC_TRACE_WARNING:", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define AZAC_TRACE_WARNING(...)
#define AZAC_TRACE_WARNING_IF(...)
#endif
#ifdef AZAC_CONFIG_DBG_TRACE_WARNING
#define AZAC_DBG_TRACE_WARNING(msg, ...) __AZAC_TRACE_WARNING("AZAC_DBG_TRACE_WARNING:", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define AZAC_DBG_TRACE_WARNING_IF(cond, msg, ...) __AZAC_TRACE_WARNING_IF(cond, "AZAC_DBG_TRACE_WARNING:", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define AZAC_DBG_TRACE_WARNING(...)
#define AZAC_DBG_TRACE_WARNING_IF(...)
#endif
#ifdef AZAC_CONFIG_TRACE_ERROR
#define AZAC_TRACE_ERROR(msg, ...) __AZAC_TRACE_ERROR("AZAC_TRACE_ERROR: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define AZAC_TRACE_ERROR_IF(cond, msg, ...) __AZAC_TRACE_ERROR_IF(cond, "AZAC_TRACE_ERROR: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define AZAC_TRACE_ERROR(...)
#define AZAC_TRACE_ERROR_IF(...)
#endif
#ifdef AZAC_CONFIG_DBG_TRACE_ERROR
#define AZAC_DBG_TRACE_ERROR(msg, ...) __AZAC_TRACE_ERROR("AZAC_DBG_TRACE_ERROR: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define AZAC_DBG_TRACE_ERROR_IF(cond, msg, ...) __AZAC_TRACE_ERROR_IF(cond, "AZAC_DBG_TRACE_ERROR: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define AZAC_DBG_TRACE_ERROR(...)
#define AZAC_DBG_TRACE_ERROR_IF(...)
#endif
#ifdef AZAC_CONFIG_TRACE_FUNCTION
#define AZAC_TRACE_FUNCTION(...) __AZAC_TRACE_VERBOSE("AZAC_TRACE_FUNCTION: ", __FILE__, __LINE__, __FUNCTION__)
#else
#define AZAC_TRACE_FUNCTION(...)
#endif
#ifdef AZAC_CONFIG_DBG_TRACE_FUNCTION
#define AZAC_DBG_TRACE_FUNCTION(...) __AZAC_TRACE_VERBOSE("AZAC_DBG_TRACE_FUNCTION: ", __FILE__, __LINE__, __FUNCTION__)
#else
#define AZAC_DBG_TRACE_FUNCTION(...)
#endif
#ifdef AZAC_CONFIG_TRACE_REPORT_ON_FAIL
#define AZAC_REPORT_ON_FAIL(hr) __AZAC_REPORT_ON_FAIL("AZAC_REPORT_ON_FAIL: ", __FILE__, __LINE__, hr)
#define AZAC_REPORT_ON_FAIL_IFNOT(hr, hrNot) __AZAC_REPORT_ON_FAIL_IFNOT("AZAC_REPORT_ON_FAIL: ", __FILE__, __LINE__, hr, hrNot)
#else
#define AZAC_REPORT_ON_FAIL(hr) UNUSED(hr)
#define AZAC_REPORT_ON_FAIL_IFNOT(hr, hrNot) UNUSED(hr); UNUSED(hrNot)
#endif
#ifdef AZAC_CONFIG_TRACE_RETURN_ON_FAIL
#define AZAC_RETURN_HR(hr) __AZAC_T_RETURN_HR("AZAC_RETURN_ON_FAIL: ", __FILE__, __LINE__, hr)
#define AZAC_RETURN_HR_IF(hr, cond) __AZAC_T_RETURN_HR_IF("AZAC_RETURN_ON_FAIL: ", __FILE__, __LINE__, hr, cond)
#define AZAC_RETURN_ON_FAIL(hr) __AZAC_T_RETURN_ON_FAIL("AZAC_RETURN_ON_FAIL: ", __FILE__, __LINE__, hr)
#define AZAC_RETURN_ON_FAIL_IF_NOT(hr, hrNot) __AZAC_T_RETURN_ON_FAIL_IF_NOT("AZAC_RETURN_ON_FAIL: ", __FILE__, __LINE__, hr, hrNot)
#else
#define AZAC_RETURN_HR(hr) __AZAC_RETURN_HR(hr)
#define AZAC_RETURN_HR_IF(hr, cond) __AZAC_RETURN_HR_IF(hr, cond)
#define AZAC_RETURN_ON_FAIL(hr) __AZAC_RETURN_ON_FAIL(hr)
#define AZAC_RETURN_ON_FAIL_IF_NOT(hr, hrNot) __AZAC_RETURN_ON_FAIL_IF_NOT(hr, hrNot)
#endif
#define AZAC_IFTRUE_RETURN_HR(cond, hr) AZAC_RETURN_HR_IF(hr, cond)
#define AZAC_IFFALSE_RETURN_HR(cond, hr) AZAC_RETURN_HR_IF(hr, !(cond))
#define AZAC_IFFAILED_RETURN_HR(hr) AZAC_RETURN_ON_FAIL(hr)
#define AZAC_IFFAILED_RETURN_HR_IFNOT(hr, hrNot) AZAC_RETURN_ON_FAIL_IF_NOT(hr, hrNot)
#ifdef AZAC_CONFIG_TRACE_EXITFN_ON_FAIL
#define AZAC_EXITFN_HR(hr) __AZAC_T_EXITFN_HR("AZAC_EXITFN_ON_FAIL: ", __FILE__, __LINE__, hr)
#define AZAC_EXITFN_HR_IF(hr, cond) __AZAC_T_EXITFN_HR_IF("AZAC_EXITFN_ON_FAIL: ", __FILE__, __LINE__, hr, cond)
#define AZAC_EXITFN_ON_FAIL(hr) __AZAC_T_EXITFN_ON_FAIL("AZAC_EXITFN_ON_FAIL: ", __FILE__, __LINE__, hr)
#define AZAC_EXITFN_ON_FAIL_IF_NOT(hr, hrNot) __AZAC_EXITFN_ON_FAIL_IF_NOT("AZAC_EXITFN_ON_FAIL: ", __FILE__, __LINE__, hr, hrNot)
#else
#define AZAC_EXITFN_HR(hr) __AZAC_EXITFN_HR(hr)
#define AZAC_EXITFN_HR_IF(hr, cond) __AZAC_EXITFN_HR_IF(hr, cond)
#define AZAC_EXITFN_ON_FAIL(hr) __AZAC_EXITFN_ON_FAIL(hr)
#define AZAC_EXITFN_ON_FAIL_IF_NOT(hr, hrNot) __AZAC_EXITFN_ON_FAIL_IF_NOT(hr, hrNot)
#endif
#define AZAC_IFTRUE_EXITFN_WHR(cond, hr) AZAC_EXITFN_HR_IF(hr, cond)
#define AZAC_IFFALSE_EXITFN_WHR(cond, hr) AZAC_EXITFN_HR_IF(hr, !(cond))
#define AZAC_IFFAILED_EXITFN_WHR(hr) AZAC_EXITFN_ON_FAIL(hr)
#define AZAC_IFFAILED_EXITFN_WHR_IFNOT(hr, hrNot) AZAC_EXITFN_ON_FAIL_IF_NOT(hr, hrNot)
#define AZAC_IFTRUE_EXITFN_CLEANUP(cond, expr) \
do { \
int fCondT = !!(cond); \
if (fCondT) { \
expr; \
goto AZAC_EXITFN_CLEANUP; \
} } while (0)
#define AZAC_IFFALSE_EXITFN_CLEANUP(cond, expr) \
do { \
int fCondF = !!(cond); \
if (!fCondF) { \
expr; \
goto AZAC_EXITFN_CLEANUP; \
} } while (0)
#if defined(AZAC_CONFIG_DBG_TRACE_ASSERT) && (defined(DEBUG) || defined(_DEBUG))
#define AZAC_DBG_ASSERT(expr) __AZAC_DBG_ASSERT("AZAC_ASSERT: ", __FILE__, __LINE__, expr)
#define AZAC_DBG_ASSERT_WITH_MESSAGE(expr, ...) __AZAC_DBG_ASSERT_WITH_MESSAGE("AZAC_ASSERT: ", __FILE__, __LINE__, expr, ##__VA_ARGS__)
#else
#define AZAC_DBG_ASSERT(expr)
#define AZAC_DBG_ASSERT_WITH_MESSAGE(expr, ...)
#endif
#if defined(AZAC_CONFIG_DBG_TRACE_VERIFY) && (defined(DEBUG) || defined(_DEBUG))
#define AZAC_DBG_VERIFY(expr) __AZAC_DBG_VERIFY("AZAC_VERIFY: ", __FILE__, __LINE__, expr)
#define AZAC_DBG_VERIFY_WITH_MESSAGE(expr, ...) __AZAC_DBG_VERIFY_WITH_MESSAGE("AZAC_VERIFY: ", __FILE__, __LINE__, expr, ##__VA_ARGS__)
#else
#define AZAC_DBG_VERIFY(expr) (expr)
#define AZAC_DBG_VERIFY_WITH_MESSAGE(expr, ...) (expr)
#endif
#define AZAC_IFTRUE(cond, expr) \
do { \
int fCondT = !!(cond); \
if (fCondT) { \
expr; \
} } while (0)
#define AZAC_IFFALSE(cond, expr) \
do { \
int fCondF = !!(cond); \
if (!fCondF) { \
expr; \
} } while (0)
// handle circular dependency
#ifndef AZAC_SUPPRESS_COMMON_INCLUDE_FROM_DEBUG
#define AZAC_SUPPRESS_DEBUG_INCLUDE_FROM_COMMON
#include <azac_api_c_common.h>
#undef AZAC_SUPPRESS_DEBUG_INCLUDE_FROM_COMMON
#endif
#ifdef __cplusplus
#ifdef AZAC_CONFIG_TRACE_SCOPE
#define AZAC_TRACE_SCOPE(x, y) __AZAC_TRACE_SCOPE("AZAC_TRACE_SCOPE_ENTER: ", __FILE__, __LINE__, "AZAC_TRACE_SCOPE_EXIT: ", x, y)
#else
#define AZAC_TRACE_SCOPE(x, y)
#endif
#ifdef AZAC_CONFIG_DBG_TRACE_SCOPE
#define AZAC_DBG_TRACE_SCOPE(x, y) __AZAC_TRACE_SCOPE("AZAC_DBG_TRACE_SCOPE_ENTER: ", __FILE__, __LINE__, "AZAC_DBG_TRACE_SCOPE_EXIT: ", x, y)
#else
#define AZAC_DBG_TRACE_SCOPE(x, y)
#endif
#ifdef AZAC_CONFIG_TRACE_THROW_ON_FAIL
#define AZAC_THROW_ON_FAIL(hr) __AZAC_T_THROW_ON_FAIL("AZAC_THROW_ON_FAIL: ", __FILE__, __LINE__, hr)
#define AZAC_THROW_ON_FAIL_IF_NOT(hr, hrNot) __AZAC_T_THROW_ON_FAIL_IF_NOT("AZAC_THROW_ON_FAIL: ", __FILE__, __LINE__, hr, hrNot)
#define AZAC_LOG_ON_FAIL(hr) __AZAC_T_LOG_ON_FAIL("AZAC_LOG_ON_FAIL: ", __FILE__, __LINE__, hr)
#define AZAC_THROW_HR_IF(hr, cond) __AZAC_T_THROW_HR_IF("AZAC_THROW_HR_IF: ", __FILE__, __LINE__, hr, cond)
#define AZAC_THROW_HR(hr) __AZAC_T_THROW_HR("AZAC_THROW_HR: ", __FILE__, __LINE__, hr)
#else
#define AZAC_THROW_ON_FAIL(hr) __AZAC_THROW_ON_FAIL(hr)
#define AZAC_THROW_ON_FAIL_IF_NOT(hr, hrNot) __AZAC_THROW_ON_FAIL_IF_NOT(hr, hrNot)
#define AZAC_LOG_ON_FAIL(hr) __AZAC_LOG_ON_FAIL(hr)
#define AZAC_THROW_HR_IF(hr, cond) __AZAC_THROW_HR_IF(hr, cond)
#define AZAC_THROW_HR(hr) __AZAC_THROW_HR(hr)
#endif
#define AZAC_IFTRUE_THROW_HR(cond, hr) AZAC_THROW_HR_IF(hr, cond)
#define AZAC_IFFALSE_THROW_HR(cond, hr) AZAC_THROW_HR_IF(hr, !(cond))
#define AZAC_IFFAILED_THROW_HR(hr) AZAC_THROW_ON_FAIL(hr)
#define AZAC_IFFAILED_THROW_HR_IFNOT(hr, hrNot) AZAC_THROW_ON_FAIL_IF_NOT(hr, hrNot)
#include <azac_api_c_error.h>
#include <azac_api_c_diagnostics.h>
#include <stdexcept>
#include <string>
inline void __azac_handle_native_ex(AZACHR hr, bool throwException)
{
AZAC_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
auto handle = reinterpret_cast<AZAC_HANDLE>(hr);
auto error = error_get_error_code(handle);
if (error == AZAC_ERR_NONE)
{
if (throwException)
{
throw hr;
}
else
{
// do nothing. This is already logged by the macros that call this function
return;
}
}
std::string errorMsg;
try
{
auto callstack = error_get_call_stack(handle);
auto what = error_get_message(handle);
if (what)
{
errorMsg += what;
}
else
{
errorMsg += "Exception with error code: ";
errorMsg += std::to_string(error);
}
if (callstack)
{
errorMsg += callstack;
}
}
catch (...)
{
error_release(handle);
throw hr;
}
error_release(handle);
if (throwException)
{
throw std::runtime_error(errorMsg);
}
else
{
AZAC_TRACE_ERROR("Error details: %s", errorMsg.c_str());
}
}
inline void __azac_log_only(AZACHR hr)
{
__azac_handle_native_ex(hr, false);
}
inline void __azac_rethrow(AZACHR hr)
{
__azac_handle_native_ex(hr, true);
}
#else // __cplusplus
#define AZAC_TRACE_SCOPE(x, y) static_assert(false)
#define AZAC_DBG_TRACE_SCOPE(x, y) static_assert(false)
#define AZAC_LOG_ON_FAIL(hr) static_assert(false)
#define AZAC_THROW_ON_FAIL(hr) static_assert(false)
#define AZAC_THROW_ON_FAIL_IF_NOT(hr, hrNot) static_assert(false)
#define AZAC_THROW_HR_IF(hr, cond) static_assert(false)
#define AZAC_THROW_HR(hr) static_assert(false)
#define AZAC_IFTRUE_THROW_HR(cond, hr) static_assert(false)
#define AZAC_IFFALSE_THROW_HR(cond, hr) static_assert(false)
#define AZAC_IFFAILED_THROW_HR(hr) static_assert(false)
#define AZAC_IFFAILED_THROW_HR_IFNOT(hr, hrNot) static_assert(false)
#endif // __cplusplus
//---------------------------------------------------------------------------
#ifdef __AZAC_DEBUG_H_EXAMPLES_IN_MAIN
void main()
{
int x = 4;
printf("%s = %d\n", __AZAC_EXPR_AS_STRING(x + 3), x + 3);
AZAC_TRACE_INFO("hello there");
AZAC_TRACE_ERROR("hello there");
AZAC_TRACE_WARNING("hello there");
AZAC_TRACE_VERBOSE("hello there");
AZAC_TRACE_INFO("hello there %d", 5);
AZAC_TRACE_ERROR("hello there %d", 5);
AZAC_TRACE_WARNING("hello there %d", 5);
AZAC_TRACE_VERBOSE("hello there %d", 5);
AZAC_TRACE_INFO_IF(false, "hello there false");
AZAC_TRACE_ERROR_IF(false, "hello there false");
AZAC_TRACE_WARNING_IF(false, "hello there false");
AZAC_TRACE_VERBOSE_IF(false, "hello there false");
AZAC_TRACE_INFO_IF(false, "hello there false %d", 5);
AZAC_TRACE_ERROR_IF(false, "hello there false %d", 5);
AZAC_TRACE_WARNING_IF(false, "hello there false %d", 5);
AZAC_TRACE_VERBOSE_IF(false, "hello there false %d", 5);
AZAC_TRACE_INFO_IF(true, "hello there true");
AZAC_TRACE_ERROR_IF(true, "hello there true");
AZAC_TRACE_WARNING_IF(true, "hello there true");
AZAC_TRACE_VERBOSE_IF(true, "hello there true");
AZAC_TRACE_INFO_IF(true, "hello there true %d", 5);
AZAC_TRACE_ERROR_IF(true, "hello there true %d", 5);
AZAC_TRACE_WARNING_IF(true, "hello there true %d", 5);
AZAC_TRACE_VERBOSE_IF(true, "hello there true %d", 5);
AZAC_DBG_TRACE_INFO("hello there");
AZAC_DBG_TRACE_ERROR("hello there");
AZAC_DBG_TRACE_WARNING("hello there");
AZAC_DBG_TRACE_VERBOSE("hello there");
AZAC_DBG_TRACE_INFO("hello there %d", 5);
AZAC_DBG_TRACE_ERROR("hello there %d", 5);
AZAC_DBG_TRACE_WARNING("hello there %d", 5);
AZAC_DBG_TRACE_VERBOSE("hello there %d", 5);
AZAC_DBG_TRACE_INFO_IF(false, "hello there false");
AZAC_DBG_TRACE_ERROR_IF(false, "hello there false");
AZAC_DBG_TRACE_WARNING_IF(false, "hello there false");
AZAC_DBG_TRACE_VERBOSE_IF(false, "hello there false");
AZAC_DBG_TRACE_INFO_IF(false, "hello there false %d", 5);
AZAC_DBG_TRACE_ERROR_IF(false, "hello there false %d", 5);
AZAC_DBG_TRACE_WARNING_IF(false, "hello there false %d", 5);
AZAC_DBG_TRACE_VERBOSE_IF(false, "hello there false %d", 5);
AZAC_DBG_TRACE_INFO_IF(true, "hello there true");
AZAC_DBG_TRACE_ERROR_IF(true, "hello there true");
AZAC_DBG_TRACE_WARNING_IF(true, "hello there true");
AZAC_DBG_TRACE_VERBOSE_IF(true, "hello there true");
AZAC_DBG_TRACE_INFO_IF(true, "hello there true %d", 5);
AZAC_DBG_TRACE_ERROR_IF(true, "hello there true %d", 5);
AZAC_DBG_TRACE_WARNING_IF(true, "hello there true %d", 5);
AZAC_DBG_TRACE_VERBOSE_IF(true, "hello there true %d", 5);
AZAC_TRACE_SCOPE("A", "B");
AZAC_TRACE_FUNCTION();
AZAC_DBG_TRACE_FUNCTION();
AZAC_DBG_ASSERT(false);
AZAC_DBG_ASSERT(true);
AZAC_DBG_ASSERT_WITH_MESSAGE(false, "HEY!");
AZAC_DBG_ASSERT_WITH_MESSAGE(true, "HEY!!");
AZAC_DBG_VERIFY(false);
AZAC_DBG_VERIFY(true);
AZAC_DBG_VERIFY_WITH_MESSAGE(false, "HEY!");
AZAC_DBG_VERIFY_WITH_MESSAGE(true, "HEY!!");
AZACHR hr1 { 0x80001111 };
AZACHR hr2 { 0x00001111 };
AZAC_TRACE_VERBOSE("Testing out AZAC_REPORT_ON_FAIL, should see two failures...");
AZAC_REPORT_ON_FAIL(hr1);
AZAC_REPORT_ON_FAIL_IFNOT(hr1, 0x80001000);
AZAC_TRACE_VERBOSE("Testing out AZAC_REPORT_ON_FAIL, should see two failures... Done!");
AZAC_TRACE_VERBOSE("Testing out AZAC_REPORT_ON_FAIL, should see zero failures...");
AZAC_REPORT_ON_FAIL(hr2);
AZAC_REPORT_ON_FAIL_IFNOT(hr1, 0x80001111);
AZAC_REPORT_ON_FAIL_IFNOT(hr2, 0x80001111);
AZAC_REPORT_ON_FAIL_IFNOT(hr2, 0x80001000);
AZAC_TRACE_VERBOSE("Testing out AZAC_REPORT_ON_FAIL, should see zero failures... Done!");
}
#endif

455
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/azac_error.h

@ -0,0 +1,455 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/azai/license202106 for the full license information.
#pragma once
// TODO: TFS#3671215 - Vision: C/C++ azac_api* files are in shared include directory, speech and vision share
#include <stdint.h>
/// <summary>
/// Type definition for Azure AI Core result codes.
/// </summary>
typedef uintptr_t AZACHR;
/// <summary>
/// Default result code indicating no error.
/// </summary>
#define AZAC_ERR_NONE 0
/// <summary>
/// Declare and initialize result code variable.
/// </summary>
#define AZAC_INIT_HR(hr) AZACHR hr = AZAC_ERR_NONE; \
(void)(hr)
/// <summary>
/// Check if result code indicates success.
/// </summary>
#define AZAC_SUCCEEDED(x) ((x) == AZAC_ERR_NONE)
/// <summary>
/// Check if result code indicates error.
/// </summary>
#define AZAC_FAILED(x) (!AZAC_SUCCEEDED(x))
/// <summary>
/// Base macros for all error codes.
/// </summary>
#define __AZAC_ERRCODE_FAILED(x) (x)
/// <summary>
/// The function is not implemented.
/// </summary>
#define AZAC_ERR_NOT_IMPL __AZAC_ERRCODE_FAILED(0xfff)
/// <summary>
/// The object has not been properly initialized.
/// </summary>
#define AZAC_ERR_UNINITIALIZED __AZAC_ERRCODE_FAILED(0x001)
/// <summary>
/// The object has already been initialized.
/// </summary>
#define AZAC_ERR_ALREADY_INITIALIZED __AZAC_ERRCODE_FAILED(0x002)
/// <summary>
/// An unhandled exception was detected.
/// </summary>
#define AZAC_ERR_UNHANDLED_EXCEPTION __AZAC_ERRCODE_FAILED(0x003)
/// <summary>
/// The object or property was not found.
/// </summary>
#define AZAC_ERR_NOT_FOUND __AZAC_ERRCODE_FAILED(0x004)
/// <summary>
/// One or more arguments are not valid.
/// </summary>
#define AZAC_ERR_INVALID_ARG __AZAC_ERRCODE_FAILED(0x005)
/// <summary>
/// The specified timeout value has elapsed.
/// </summary>
#define AZAC_ERR_TIMEOUT __AZAC_ERRCODE_FAILED(0x006)
/// <summary>
/// The asynchronous operation is already in progress.
/// </summary>
#define AZAC_ERR_ALREADY_IN_PROGRESS __AZAC_ERRCODE_FAILED(0x007)
/// <summary>
/// The attempt to open the file failed.
/// </summary>
#define AZAC_ERR_FILE_OPEN_FAILED __AZAC_ERRCODE_FAILED(0x008)
/// <summary>
/// The end of the file was reached unexpectedly.
/// </summary>
#define AZAC_ERR_UNEXPECTED_EOF __AZAC_ERRCODE_FAILED(0x009)
/// <summary>
/// Invalid audio header encountered.
/// </summary>
#define AZAC_ERR_INVALID_HEADER __AZAC_ERRCODE_FAILED(0x00a)
/// <summary>
/// The requested operation cannot be performed while audio is pumping
/// </summary>
#define AZAC_ERR_AUDIO_IS_PUMPING __AZAC_ERRCODE_FAILED(0x00b)
/// <summary>
/// Unsupported audio format.
/// </summary>
#define AZAC_ERR_UNSUPPORTED_FORMAT __AZAC_ERRCODE_FAILED(0x00c)
/// <summary>
/// Operation aborted.
/// </summary>
#define AZAC_ERR_ABORT __AZAC_ERRCODE_FAILED(0x00d)
/// <summary>
/// Microphone is not available.
/// </summary>
#define AZAC_ERR_MIC_NOT_AVAILABLE __AZAC_ERRCODE_FAILED(0x00e)
/// <summary>
/// An invalid state was encountered.
/// </summary>
#define AZAC_ERR_INVALID_STATE __AZAC_ERRCODE_FAILED(0x00f)
/// <summary>
/// Attempting to create a UUID failed.
/// </summary>
#define AZAC_ERR_UUID_CREATE_FAILED __AZAC_ERRCODE_FAILED(0x010)
/// <summary>
/// An unexpected session state transition was encountered when setting the session audio format.
/// </summary>
/// <remarks>
/// Valid transitions are:
/// * WaitForPumpSetFormatStart --> ProcessingAudio (at the beginning of stream)
/// * StoppingPump --> WaitForAdapterCompletedSetFormatStop (at the end of stream)
/// * ProcessingAudio --> WaitForAdapterCompletedSetFormatStop (when the stream runs out of data)
/// All other state transitions are invalid.
/// </remarks>
#define AZAC_ERR_SETFORMAT_UNEXPECTED_STATE_TRANSITION __AZAC_ERRCODE_FAILED(0x011)
/// <summary>
/// An unexpected session state was encountered in while processing audio.
/// </summary>
/// <remarks>
/// Valid states to encounter are:
/// * ProcessingAudio: We're allowed to process audio while in this state.
/// * StoppingPump: We're allowed to be called to process audio, but we'll ignore the data passed in while we're attempting to stop the pump.
/// All other states are invalid while processing audio.
/// </remarks>
#define AZAC_ERR_PROCESS_AUDIO_INVALID_STATE __AZAC_ERRCODE_FAILED(0x012)
/// <summary>
/// An unexpected state transition was encountered while attempting to start recognizing.
/// </summary>
/// <remarks>
/// A valid transition is:
/// * Idle --> WaitForPumpSetFormatStart
/// All other state transitions are invalid when attempting to start recognizing
/// </remarks>
#define AZAC_ERR_START_RECOGNIZING_INVALID_STATE_TRANSITION __AZAC_ERRCODE_FAILED(0x013)
/// <summary>
/// An unexpected error was encountered when trying to create an internal object.
/// </summary>
#define AZAC_ERR_UNEXPECTED_CREATE_OBJECT_FAILURE __AZAC_ERRCODE_FAILED(0x014)
/// <summary>
/// An error in the audio-capturing system.
/// </summary>
#define AZAC_ERR_MIC_ERROR __AZAC_ERRCODE_FAILED(0x015)
/// <summary>
/// The requested operation cannot be performed; there is no audio input.
/// </summary>
#define AZAC_ERR_NO_AUDIO_INPUT __AZAC_ERRCODE_FAILED(0x016)
/// <summary>
/// An unexpected error was encountered when trying to access the USP site.
/// </summary>
#define AZAC_ERR_UNEXPECTED_USP_SITE_FAILURE __AZAC_ERRCODE_FAILED(0x017)
/// <summary>
/// An unexpected error was encountered when trying to access the LU site.
/// </summary>
#define AZAC_ERR_UNEXPECTED_LU_SITE_FAILURE __AZAC_ERRCODE_FAILED(0x018)
/// <summary>
/// The buffer is too small.
/// </summary>
#define AZAC_ERR_BUFFER_TOO_SMALL __AZAC_ERRCODE_FAILED(0x019)
/// <summary>
/// A method failed to allocate memory.
/// </summary>
#define AZAC_ERR_OUT_OF_MEMORY __AZAC_ERRCODE_FAILED(0x01A)
/// <summary>
/// An unexpected runtime error occurred.
/// </summary>
#define AZAC_ERR_RUNTIME_ERROR __AZAC_ERRCODE_FAILED(0x01B)
/// <summary>
/// The url specified is invalid.
/// </summary>
#define AZAC_ERR_INVALID_URL __AZAC_ERRCODE_FAILED(0x01C)
/// <summary>
/// The region specified is invalid or missing.
/// </summary>
#define AZAC_ERR_INVALID_REGION __AZAC_ERRCODE_FAILED(0x01D)
/// <summary>
/// Switch between single shot and continuous recognition is not supported.
/// </summary>
#define AZAC_ERR_SWITCH_MODE_NOT_ALLOWED __AZAC_ERRCODE_FAILED(0x01E)
/// <summary>
/// Changing connection status is not supported in the current recognition state.
/// </summary>
#define AZAC_ERR_CHANGE_CONNECTION_STATUS_NOT_ALLOWED __AZAC_ERRCODE_FAILED(0x01F)
/// <summary>
/// Explicit connection management is not supported by the specified recognizer.
/// </summary>
#define AZAC_ERR_EXPLICIT_CONNECTION_NOT_SUPPORTED_BY_RECOGNIZER __AZAC_ERRCODE_FAILED(0x020)
/// <summary>
/// The handle is invalid.
/// </summary>
#define AZAC_ERR_INVALID_HANDLE __AZAC_ERRCODE_FAILED(0x021)
/// <summary>
/// The recognizer is invalid.
/// </summary>
#define AZAC_ERR_INVALID_RECOGNIZER __AZAC_ERRCODE_FAILED(0x022)
/// <summary>
/// The value is out of range.
/// Added in version 1.3.0.
/// </summary>
#define AZAC_ERR_OUT_OF_RANGE __AZAC_ERRCODE_FAILED(0x023)
/// <summary>
/// Extension library not found.
/// Added in version 1.3.0.
/// </summary>
#define AZAC_ERR_EXTENSION_LIBRARY_NOT_FOUND __AZAC_ERRCODE_FAILED(0x024)
/// <summary>
/// An unexpected error was encountered when trying to access the TTS engine site.
/// Added in version 1.4.0.
/// </summary>
#define AZAC_ERR_UNEXPECTED_TTS_ENGINE_SITE_FAILURE __AZAC_ERRCODE_FAILED(0x025)
/// <summary>
/// An unexpected error was encountered when trying to access the audio output stream.
/// Added in version 1.4.0.
/// </summary>
#define AZAC_ERR_UNEXPECTED_AUDIO_OUTPUT_FAILURE __AZAC_ERRCODE_FAILED(0x026)
/// <summary>
/// Gstreamer internal error.
/// Added in version 1.4.0.
/// </summary>
#define AZAC_ERR_GSTREAMER_INTERNAL_ERROR __AZAC_ERRCODE_FAILED(0x027)
/// <summary>
/// Compressed container format not supported.
/// Added in version 1.4.0.
/// </summary>
#define AZAC_ERR_CONTAINER_FORMAT_NOT_SUPPORTED_ERROR __AZAC_ERRCODE_FAILED(0x028)
/// <summary>
/// Codec extension or gstreamer not found.
/// Added in version 1.4.0.
/// </summary>
#define AZAC_ERR_GSTREAMER_NOT_FOUND_ERROR __AZAC_ERRCODE_FAILED(0x029)
/// <summary>
/// The language specified is missing.
/// Added in version 1.5.0.
/// </summary>
#define AZAC_ERR_INVALID_LANGUAGE __AZAC_ERRCODE_FAILED(0x02A)
/// <summary>
/// The API is not applicable.
/// Added in version 1.5.0.
/// </summary>
#define AZAC_ERR_UNSUPPORTED_API_ERROR __AZAC_ERRCODE_FAILED(0x02B)
/// <summary>
/// The ring buffer is unavailable.
/// Added in version 1.8.0.
/// </summary>
#define AZAC_ERR_RINGBUFFER_DATA_UNAVAILABLE __AZAC_ERRCODE_FAILED(0x02C)
/// <summary>
/// An unexpected error was encountered when trying to access the Conversation site.
/// Added in version 1.5.0.
/// </summary>
#define AZAC_ERR_UNEXPECTED_CONVERSATION_SITE_FAILURE __AZAC_ERRCODE_FAILED(0x030)
/// <summary>
/// An unexpected error was encountered when trying to access the Conversation site.
/// Added in version 1.8.0.
/// </summary>
#define AZAC_ERR_UNEXPECTED_CONVERSATION_TRANSLATOR_SITE_FAILURE __AZAC_ERRCODE_FAILED(0x031)
/// <summary>
/// An asynchronous operation was canceled before it was executed.
/// Added in version 1.8.0.
/// </summary>
#define AZAC_ERR_CANCELED __AZAC_ERRCODE_FAILED(0x032)
/// <summary>
/// Codec for compression could not be initialized.
/// Added in version 1.10.0.
/// </summary>
#define AZAC_ERR_COMPRESS_AUDIO_CODEC_INITIFAILED __AZAC_ERRCODE_FAILED(0x033)
/// <summary>
/// Data not available.
/// Added in version 1.10.0.
/// </summary>
#define AZAC_ERR_DATA_NOT_AVAILABLE __AZAC_ERRCODE_FAILED(0x034)
/// <summary>
/// Invalid result reason.
/// Added in version 1.12.0
/// </summary>
#define AZAC_ERR_INVALID_RESULT_REASON __AZAC_ERRCODE_FAILED(0x035)
/// <summary>
/// An unexpected error was encountered when trying to access the RNN-T site.
/// </summary>
#define AZAC_ERR_UNEXPECTED_RNNT_SITE_FAILURE __AZAC_ERRCODE_FAILED(0x036)
/// <summary>
/// Sending of a network message failed.
/// </summary>
#define AZAC_ERR_NETWORK_SEND_FAILED __AZAC_ERRCODE_FAILED(0x037)
/// <summary>
/// Audio extension library not found.
/// Added in version 1.16.0.
/// </summary>
#define AZAC_ERR_AUDIO_SYS_LIBRARY_NOT_FOUND __AZAC_ERRCODE_FAILED(0x038)
/// <summary>
/// An error in the audio-rendering system.
/// Added in version 1.20.0
/// </summary>
#define AZAC_ERR_LOUDSPEAKER_ERROR __AZAC_ERRCODE_FAILED(0x039)
/// <summary>
/// An unexpected error was encountered when trying to access the Vision site.
/// Added in version 1.15.0.
/// </summary>
#define AZAC_ERR_VISION_SITE_FAILURE __AZAC_ERRCODE_FAILED(0x050)
/// <summary>
/// Stream number provided was invalid in the current context.
/// Added in version 1.15.0.
/// </summary>
#define AZAC_ERR_MEDIA_INVALID_STREAM __AZAC_ERRCODE_FAILED(0x060)
/// <summary>
/// Offset required is invalid in the current context.
/// Added in version 1.15.0.
/// </summary>
#define AZAC_ERR_MEDIA_INVALID_OFFSET __AZAC_ERRCODE_FAILED(0x061)
/// <summary>
/// No more data is available in source.
/// Added in version 1.15.0.
/// </summary>
#define AZAC_ERR_MEDIA_NO_MORE_DATA __AZAC_ERRCODE_FAILED(0x062)
/// <summary>
/// Source has not been started.
/// Added in version 1.15.0.
/// </summary>
#define AZAC_ERR_MEDIA_NOT_STARTED __AZAC_ERRCODE_FAILED(0x063)
/// <summary>
/// Source has already been started.
/// Added in version 1.15.0.
/// </summary>
#define AZAC_ERR_MEDIA_ALREADY_STARTED __AZAC_ERRCODE_FAILED(0x064)
/// <summary>
/// Media device creation failed.
/// Added in version 1.18.0.
/// </summary>
#define AZAC_ERR_MEDIA_DEVICE_CREATION_FAILED __AZAC_ERRCODE_FAILED(0x065)
/// <summary>
/// No devices of the selected category are available.
/// Added in version 1.18.0.
/// </summary>
#define AZAC_ERR_MEDIA_NO_DEVICE_AVAILABLE __AZAC_ERRCODE_FAILED(0x066)
/// <summary>
/// Enabled Voice Activity Detection while using keyword recognition is not allowed.
/// </summary>
#define AZAC_ERR_VAD_COULD_NOT_USE_WITH_KEYWORD_RECOGNIZER __AZAC_ERRCODE_FAILED(0x067)
/// <summary>
/// The specified RecoEngineAdapter could not be created.
/// </summary>
#define AZAC_ERR_COULD_NOT_CREATE_ENGINE_ADAPTER __AZAC_ERRCODE_FAILED(0x070)
/// <summary>
/// The input file has a size of 0 bytes.
/// </summary>
#define AZAC_ERR_INPUT_FILE_SIZE_IS_ZERO_BYTES __AZAC_ERRCODE_FAILED(0x072)
/// <summary>
/// Cannot open the input media file for reading. Does it exist?
/// </summary>
#define AZAC_ERR_FAILED_TO_OPEN_INPUT_FILE_FOR_READING __AZAC_ERRCODE_FAILED(0x073)
/// <summary>
/// Failed to read from the input media file.
/// </summary>
#define AZAC_ERR_FAILED_TO_READ_FROM_INPUT_FILE __AZAC_ERRCODE_FAILED(0x074)
/// <summary>
/// Input media file is too large.
/// </summary>
#define AZAC_ERR_INPUT_FILE_TOO_LARGE __AZAC_ERRCODE_FAILED(0x075)
/// <summary>
/// The input URL is unsupported. It should start with `http://`, `https://` or `rtsp://`.
/// </summary>
#define AZAC_ERR_UNSUPPORTED_URL_PROTOCOL __AZAC_ERRCODE_FAILED(0x076)
/// <summary>
/// The Nullable value is empty. Check HasValue() before getting the value.
/// </summary>
#define AZAC_ERR_EMPTY_NULLABLE __AZAC_ERRCODE_FAILED(0x077)
/// <summary>
/// The given model version string is not in the expected format. The format
/// is specified by the regular expression `^(latest|\d{4}-\d{2}-\d{2})(-preview)?$`.
/// </summary>
#define AZAC_ERR_INVALID_MODEL_VERSION_FORMAT __AZAC_ERRCODE_FAILED(0x078)
/// <summary>
/// Malformed network message
/// </summary>
#define AZAC_ERR_NETWORK_MALFORMED __AZAC_ERRCODE_FAILED(0x090)
/// <summary>
/// Unexpected message received
/// </summary>
#define AZAC_ERR_NETWORK_PROTOCOL_VIOLATION __AZAC_ERRCODE_FAILED(0x091)

51
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c.h

@ -0,0 +1,51 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c.h: Master include header for public C API declarations
//
#pragma once
#include <speechapi_c_common.h>
#include <speechapi_c_error.h>
#include <speechapi_c_diagnostics.h>
#include <speechapi_c_property_bag.h>
#include <speechapi_c_intent_result.h>
#include <speechapi_c_intent_trigger.h>
#include <speechapi_c_intent_recognizer.h>
#include <speechapi_c_translation_result.h>
#include <speechapi_c_translation_recognizer.h>
#include <speechapi_c_pattern_matching_model.h>
#include <speechapi_c_language_understanding_model.h>
#include <speechapi_c_keyword_recognition_model.h>
#include <speechapi_c_audio_stream_format.h>
#include <speechapi_c_audio_stream.h>
#include <speechapi_c_audio_config.h>
#include <speechapi_c_audio_processing_options.h>
#include <speechapi_c_speech_config.h>
#include <speechapi_c_embedded_speech_config.h>
#include <speechapi_c_hybrid_speech_config.h>
#include <speechapi_c_speech_translation_config.h>
#include <speechapi_c_factory.h>
#include <speechapi_c_recognizer.h>
#include <speechapi_c_synthesis_request.h>
#include <speechapi_c_synthesizer.h>
#include <speechapi_c_result.h>
#include <speechapi_c_grammar.h>
#include <speechapi_c_session.h>
#include <speechapi_c_connection.h>
#include <speechapi_c_dialog_service_config.h>
#include <speechapi_c_dialog_service_connector.h>
#include <speechapi_c_conversation.h>
#include <speechapi_c_conversation_transcription_result.h>
#include <speechapi_c_meeting.h>
#include <speechapi_c_meeting_transcription_result.h>
#include <speechapi_c_user.h>
#include <speechapi_c_participant.h>
#include <speechapi_c_conversation_translator.h>
#include <speechapi_c_ext_audiocompression.h>
#include <speechapi_c_speaker_recognition.h>
#include <speechapi_c_pronunciation_assessment_config.h>
#include <speechapi_c_speech_recognition_model.h>
#include <speechapi_c_speech_translation_model.h>

27
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_audio_config.h

@ -0,0 +1,27 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_audio_config.h: Public API declarations for audio configuration related C methods and types
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI_(bool) audio_config_is_handle_valid(SPXAUDIOCONFIGHANDLE haudioConfig);
SPXAPI audio_config_create_audio_input_from_default_microphone(SPXAUDIOCONFIGHANDLE* haudioConfig);
SPXAPI audio_config_create_audio_input_from_a_microphone(SPXAUDIOCONFIGHANDLE* haudioConfig, const char* deviceName);
SPXAPI audio_config_create_audio_input_from_wav_file_name(SPXAUDIOCONFIGHANDLE* haudioConfig, const char* fileName);
SPXAPI audio_config_create_audio_input_from_stream(SPXAUDIOCONFIGHANDLE* haudioConfig, SPXAUDIOSTREAMHANDLE haudioStream);
SPXAPI audio_config_create_push_audio_input_stream(SPXAUDIOCONFIGHANDLE* haudioConfig, SPXAUDIOSTREAMHANDLE* haudioStream, SPXAUDIOSTREAMFORMATHANDLE hformat);
SPXAPI audio_config_create_pull_audio_input_stream(SPXAUDIOCONFIGHANDLE* haudioConfig, SPXAUDIOSTREAMHANDLE* haudioStream, SPXAUDIOSTREAMFORMATHANDLE hformat);
SPXAPI audio_config_create_audio_output_from_default_speaker(SPXAUDIOCONFIGHANDLE* haudioConfig);
SPXAPI audio_config_create_audio_output_from_a_speaker(SPXAUDIOCONFIGHANDLE* haudioConfig, const char* deviceName);
SPXAPI audio_config_create_audio_output_from_wav_file_name(SPXAUDIOCONFIGHANDLE* haudioConfig, const char* fileName);
SPXAPI audio_config_create_audio_output_from_stream(SPXAUDIOCONFIGHANDLE* haudioConfig, SPXAUDIOSTREAMHANDLE haudioStream);
SPXAPI audio_config_set_audio_processing_options(SPXAUDIOCONFIGHANDLE haudioConfig, SPXAUDIOPROCESSINGOPTIONSHANDLE haudioProcessingOptions);
SPXAPI audio_config_get_audio_processing_options(SPXAUDIOCONFIGHANDLE haudioConfig, SPXAUDIOPROCESSINGOPTIONSHANDLE* haudioProcessingOptions);
SPXAPI audio_config_release(SPXAUDIOCONFIGHANDLE haudioConfig);
SPXAPI audio_config_get_property_bag(SPXAUDIOCONFIGHANDLE haudioConfig, SPXPROPERTYBAGHANDLE* hpropbag);

173
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_audio_processing_options.h

@ -0,0 +1,173 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_audio_processing_options.h: Public API declarations for audio processing options related C methods and types
//
#pragma once
#include <speechapi_c_common.h>
/// <summary>
/// Types of preset microphone array geometries.
/// See [Microphone Array Recommendations](/azure/cognitive-services/speech-service/speech-devices-sdk-microphone) for more details.
/// </summary>
typedef enum
{
/// <summary>
/// Indicates that no geometry specified. Speech SDK will determine the microphone array geometry.
/// </summary>
AudioProcessingOptions_PresetMicrophoneArrayGeometry_Uninitialized,
/// <summary>
/// Indicates a microphone array with one microphone in the center and six microphones evenly spaced
/// in a circle with radius approximately equal to 42.5 mm.
/// </summary>
AudioProcessingOptions_PresetMicrophoneArrayGeometry_Circular7,
/// <summary>
/// Indicates a microphone array with one microphone in the center and three microphones evenly spaced
/// in a circle with radius approximately equal to 42.5 mm.
/// </summary>
AudioProcessingOptions_PresetMicrophoneArrayGeometry_Circular4,
/// <summary>
/// Indicates a microphone array with four linearly placed microphones with 40 mm spacing between them.
/// </summary>
AudioProcessingOptions_PresetMicrophoneArrayGeometry_Linear4,
/// <summary>
/// Indicates a microphone array with two linearly placed microphones with 40 mm spacing between them.
/// </summary>
AudioProcessingOptions_PresetMicrophoneArrayGeometry_Linear2,
/// <summary>
/// Indicates a microphone array with a single microphone.
/// </summary>
AudioProcessingOptions_PresetMicrophoneArrayGeometry_Mono,
/// <summary>
/// Indicates a microphone array with custom geometry.
/// </summary>
AudioProcessingOptions_PresetMicrophoneArrayGeometry_Custom
} AudioProcessingOptions_PresetMicrophoneArrayGeometry;
/// <summary>
/// Types of microphone arrays.
/// </summary>
typedef enum
{
AudioProcessingOptions_MicrophoneArrayType_Linear,
AudioProcessingOptions_MicrophoneArrayType_Planar
} AudioProcessingOptions_MicrophoneArrayType;
/// <summary>
/// Defines speaker reference channel position in input audio.
/// </summary>
typedef enum
{
/// <summary>
/// Indicates that the input audio does not have a speaker reference channel.
/// </summary>
AudioProcessingOptions_SpeakerReferenceChannel_None,
/// <summary>
/// Indicates that the last channel in the input audio corresponds to the speaker
/// reference for echo cancellation.
/// </summary>
AudioProcessingOptions_SpeakerReferenceChannel_LastChannel
} AudioProcessingOptions_SpeakerReferenceChannel;
#pragma pack(push, 1)
/// <summary>
/// Represents coordinates of a microphone.
/// </summary>
typedef struct
{
/// <summary>
/// X-coordinate of the microphone in millimeters.
/// </summary>
int X;
/// <summary>
/// Y-coordinate of the microphone in millimeters.
/// </summary>
int Y;
/// <summary>
/// Z-coordinate of the microphone in millimeters.
/// </summary>
int Z;
} AudioProcessingOptions_MicrophoneCoordinates;
/// <summary>
/// Represents the geometry of a microphone array.
/// </summary>
typedef struct
{
/// <summary>
/// Type of microphone array.
/// </summary>
AudioProcessingOptions_MicrophoneArrayType microphoneArrayType;
/// <summary>
/// Start angle for beamforming in degrees.
/// </summary>
uint16_t beamformingStartAngle;
/// <summary>
/// End angle for beamforming in degrees.
/// </summary>
uint16_t beamformingEndAngle;
/// <summary>
/// Number of microphones in the microphone array.
/// </summary>
uint16_t numberOfMicrophones;
/// <summary>
/// Coordinates of microphones in the microphone array.
/// </summary>
AudioProcessingOptions_MicrophoneCoordinates* microphoneCoordinates;
} AudioProcessingOptions_MicrophoneArrayGeometry;
#pragma pack(pop)
/// <summary>
/// Disables built-in input audio processing.
/// </summary>
const int AUDIO_INPUT_PROCESSING_NONE = 0x00000000;
/// <summary>
/// Enables default built-in input audio processing.
/// </summary>
const int AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT = 0x00000001;
/// <summary>
/// Disables dereverberation in the default audio processing pipeline.
/// </summary>
const int AUDIO_INPUT_PROCESSING_DISABLE_DEREVERBERATION = 0x00000002;
/// <summary>
/// Disables noise suppression in the default audio processing pipeline.
/// </summary>
const int AUDIO_INPUT_PROCESSING_DISABLE_NOISE_SUPPRESSION = 0x00000004;
/// <summary>
/// Disables automatic gain control in the default audio processing pipeline.
/// </summary>
const int AUDIO_INPUT_PROCESSING_DISABLE_GAIN_CONTROL = 0x00000008;
/// <summary>
/// Disables echo cancellation in the default audio processing pipeline.
/// </summary>
const int AUDIO_INPUT_PROCESSING_DISABLE_ECHO_CANCELLATION = 0x00000010;
/// <summary>
/// Enables voice activity detection in input audio processing.
/// </summary>
const int AUDIO_INPUT_PROCESSING_ENABLE_VOICE_ACTIVITY_DETECTION = 0x00000020;
/// <summary>
/// Enables the new version (V2) of input audio processing with improved echo cancellation performance.
/// This flag is mutually exclusive with AUDIO_INPUT_PROCESSING_ENABLE_DEFAULT flag.
/// AUDIO_INPUT_PROCESSING_DISABLE_* flags do not affect this pipeline.
/// This feature is currently in preview and only available for Windows x64 and ARM64 platform.
/// </summary>
const int AUDIO_INPUT_PROCESSING_ENABLE_V2 = 0x00000040;
SPXAPI_(bool) audio_processing_options_is_handle_valid(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions);
SPXAPI audio_processing_options_create(SPXAUDIOPROCESSINGOPTIONSHANDLE* hoptions, int audioProcessingFlags);
SPXAPI audio_processing_options_create_from_preset_microphone_array_geometry(SPXAUDIOPROCESSINGOPTIONSHANDLE* hoptions, int audioProcessingFlags, AudioProcessingOptions_PresetMicrophoneArrayGeometry microphoneArrayGeometry, AudioProcessingOptions_SpeakerReferenceChannel speakerReferenceChannel);
SPXAPI audio_processing_options_create_from_microphone_array_geometry(SPXAUDIOPROCESSINGOPTIONSHANDLE* hoptions, int audioProcessingFlags, const AudioProcessingOptions_MicrophoneArrayGeometry* microphoneArrayGeometry, AudioProcessingOptions_SpeakerReferenceChannel speakerReferenceChannel);
SPXAPI audio_processing_options_get_audio_processing_flags(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions, int* audioProcessingFlags);
SPXAPI audio_processing_options_get_preset_microphone_array_geometry(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions, AudioProcessingOptions_PresetMicrophoneArrayGeometry* microphoneArrayGeometry);
SPXAPI audio_processing_options_get_microphone_array_type(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions, AudioProcessingOptions_MicrophoneArrayType* microphoneArrayType);
SPXAPI audio_processing_options_get_beamforming_start_angle(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions, uint16_t* startAngle);
SPXAPI audio_processing_options_get_beamforming_end_angle(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions, uint16_t* endAngle);
SPXAPI audio_processing_options_get_microphone_count(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions, uint16_t* microphoneCount);
SPXAPI audio_processing_options_get_microphone_coordinates(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions, AudioProcessingOptions_MicrophoneCoordinates* microphoneCoordinates, uint16_t microphoneCount);
SPXAPI audio_processing_options_get_speaker_reference_channel(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions, AudioProcessingOptions_SpeakerReferenceChannel* speakerReferenceChannel);
SPXAPI audio_processing_options_release(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions);
SPXAPI audio_processing_options_get_property_bag(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions, SPXPROPERTYBAGHANDLE* hpropbag);

67
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_audio_stream.h

@ -0,0 +1,67 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_audio_stream.h: Public API declarations for audio stream related C methods and types
//
#pragma once
#include <speechapi_c_common.h>
#include <speechapi_c_result.h>
typedef enum
{
StreamStatus_Unknown = 0,
StreamStatus_NoData = 1,
StreamStatus_PartialData = 2,
StreamStatus_AllData = 3,
StreamStatus_Canceled = 4
} Stream_Status;
// audio_stream
SPXAPI_(bool) audio_stream_is_handle_valid(SPXAUDIOSTREAMHANDLE haudioStream);
SPXAPI audio_stream_create_push_audio_input_stream(SPXAUDIOSTREAMHANDLE* haudioStream, SPXAUDIOSTREAMFORMATHANDLE hformat);
SPXAPI audio_stream_create_pull_audio_input_stream(SPXAUDIOSTREAMHANDLE* haudioStream, SPXAUDIOSTREAMFORMATHANDLE hformat);
SPXAPI audio_stream_create_pull_audio_output_stream(SPXAUDIOSTREAMHANDLE* haudioStream);
SPXAPI audio_stream_create_push_audio_output_stream(SPXAUDIOSTREAMHANDLE* haudioStream);
SPXAPI audio_stream_release(SPXAUDIOSTREAMHANDLE haudioStream);
// pull_audio_input_stream
typedef int (*CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK)(void* pvContext, uint8_t* buffer, uint32_t size);
typedef void (*CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK)(void* pvContext);
typedef void (*CUSTOM_AUDIO_PULL_STREAM_GET_PROPERTY_CALLBACK)(void* pvContext, int id, uint8_t* value, uint32_t size);
SPXAPI pull_audio_input_stream_set_callbacks(SPXAUDIOSTREAMHANDLE haudioStream, void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback);
SPXAPI pull_audio_input_stream_set_getproperty_callback(SPXAUDIOSTREAMHANDLE haudioStream, void* pvContext, CUSTOM_AUDIO_PULL_STREAM_GET_PROPERTY_CALLBACK getPropertyCallback);
// push_audio_input_stream
SPXAPI push_audio_input_stream_write(SPXAUDIOSTREAMHANDLE haudioStream, uint8_t* buffer, uint32_t size);
SPXAPI push_audio_input_stream_close(SPXAUDIOSTREAMHANDLE haudioStream);
SPXAPI push_audio_input_stream_set_property_by_id(SPXAUDIOSTREAMHANDLE haudioStream, int id, const char* value);
SPXAPI push_audio_input_stream_set_property_by_name(SPXAUDIOSTREAMHANDLE haudioStream, const char* name, const char* value);
// pull audio output stream
SPXAPI pull_audio_output_stream_read(SPXAUDIOSTREAMHANDLE haudioStream, uint8_t* buffer, uint32_t bufferSize, uint32_t* pfilledSize);
// push_audio_output_stream
typedef int(*CUSTOM_AUDIO_PUSH_STREAM_WRITE_CALLBACK)(void* pvContext, uint8_t* buffer, uint32_t size);
typedef void(*CUSTOM_AUDIO_PUSH_STREAM_CLOSE_CALLBACK)(void* pvContext);
SPXAPI push_audio_output_stream_set_callbacks(SPXAUDIOSTREAMHANDLE haudioStream, void* pvContext, CUSTOM_AUDIO_PUSH_STREAM_WRITE_CALLBACK writeCallback, CUSTOM_AUDIO_PUSH_STREAM_CLOSE_CALLBACK closeCallback);
// audio data stream
SPXAPI_(bool) audio_data_stream_is_handle_valid(SPXAUDIOSTREAMHANDLE haudioStream);
SPXAPI audio_data_stream_create_from_file(SPXAUDIOSTREAMHANDLE* haudioStream, const char* fileName);
SPXAPI audio_data_stream_create_from_result(SPXAUDIOSTREAMHANDLE* haudioStream, SPXRESULTHANDLE hresult);
SPXAPI audio_data_stream_create_from_keyword_result(SPXAUDIOSTREAMHANDLE* audioStreamHandle, SPXRESULTHANDLE resultHandle);
SPXAPI audio_data_stream_get_status(SPXAUDIOSTREAMHANDLE haudioStream, Stream_Status* status);
SPXAPI audio_data_stream_get_reason_canceled(SPXAUDIOSTREAMHANDLE haudioStream, Result_CancellationReason* reason);
SPXAPI audio_data_stream_get_canceled_error_code(SPXAUDIOSTREAMHANDLE haudioStream, Result_CancellationErrorCode* errorCode);
SPXAPI_(bool) audio_data_stream_can_read_data(SPXAUDIOSTREAMHANDLE haudioStream, uint32_t requestedSize);
SPXAPI_(bool) audio_data_stream_can_read_data_from_position(SPXAUDIOSTREAMHANDLE haudioStream, uint32_t requestedSize, uint32_t position);
SPXAPI audio_data_stream_read(SPXAUDIOSTREAMHANDLE haudioStream, uint8_t* buffer, uint32_t bufferSize, uint32_t* pfilledSize);
SPXAPI audio_data_stream_read_from_position(SPXAUDIOSTREAMHANDLE haudioStream, uint8_t* buffer, uint32_t bufferSize, uint32_t position, uint32_t* pfilledSize);
SPXAPI audio_data_stream_save_to_wave_file(SPXAUDIOSTREAMHANDLE haudioStream, const char* fileName);
SPXAPI audio_data_stream_get_position(SPXAUDIOSTREAMHANDLE haudioStream, uint32_t* position);
SPXAPI audio_data_stream_set_position(SPXAUDIOSTREAMHANDLE haudioStream, uint32_t position);
SPXAPI audio_data_stream_detach_input(SPXAUDIOSTREAMHANDLE audioStreamHandle);
SPXAPI audio_data_stream_get_property_bag(SPXAUDIOSTREAMHANDLE haudioStream, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI audio_data_stream_release(SPXAUDIOSTREAMHANDLE haudioStream);

93
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_audio_stream_format.h

@ -0,0 +1,93 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_audio_stream_format.h: Public API declarations for audio stream format related C methods and types
//
#pragma once
#include <speechapi_c_common.h>
/// <summary>
/// Defines supported audio stream container format.
/// Changed in version 1.4.0.
/// </summary>
enum Audio_Stream_Container_Format
{
/// <summary>
/// Stream ContainerFormat definition for OGG OPUS.
/// </summary>
StreamFormat_Ogg_Opus = 0x101,
/// <summary>
/// Stream ContainerFormat definition for MP3.
/// </summary>
StreamFormat_Mp3 = 0x102,
/// <summary>
/// Stream ContainerFormat definition for FLAC. Added in version 1.7.0.
/// </summary>
StreamFormat_Flac = 0x103,
/// <summary>
/// Stream ContainerFormat definition for ALAW. Added in version 1.7.0.
/// </summary>
StreamFormat_Alaw = 0x104,
/// <summary>
/// Stream ContainerFormat definition for MULAW. Added in version 1.7.0.
/// </summary>
StreamFormat_Mulaw = 0x105,
/// <summary>
/// Stream ContainerFormat definition for AMRNB. Currently not supported.
/// </summary>
StreamFormat_Amrnb = 0x106,
/// <summary>
/// Stream ContainerFormat definition for AMRWB. Currently not supported.
/// </summary>
StreamFormat_Amrwb = 0x107,
/// <summary>
/// Stream ContainerFormat definition for any other or unknown format.
/// </summary>
StreamFormat_Any = 0x108,
};
/// <summary>
/// Defines supported audio stream wave format in WAV container.
/// </summary>
enum Audio_Stream_Wave_Format
{
/// <summary>
/// Stream WaveFormat definition for PCM (pulse-code modulated) data in integer format.
/// </summary>
StreamWaveFormat_PCM = 0x0001,
/// <summary>
/// Stream WaveFormat definition for A-law-encoded format.
/// </summary>
StreamWaveFormat_ALAW = 0x0006,
/// <summary>
/// Stream WaveFormat definition for Mu-law-encoded format.
/// </summary>
StreamWaveFormat_MULAW = 0x0007,
/// <summary>
/// Stream WaveFormat definition for G.722-encoded format.
/// </summary>
StreamWaveFormat_G722 = 0x028F
};
typedef enum Audio_Stream_Container_Format Audio_Stream_Container_Format;
typedef enum Audio_Stream_Wave_Format Audio_Stream_Wave_Format;
SPXAPI_(bool) audio_stream_format_is_handle_valid(SPXAUDIOSTREAMFORMATHANDLE hformat);
SPXAPI audio_stream_format_create_from_default_input(SPXAUDIOSTREAMFORMATHANDLE* hformat);
SPXAPI audio_stream_format_create_from_waveformat(SPXAUDIOSTREAMFORMATHANDLE* hformat, uint32_t samplesPerSecond, uint8_t bitsPerSample, uint8_t channels, Audio_Stream_Wave_Format waveFormat);
SPXAPI audio_stream_format_create_from_waveformat_pcm(SPXAUDIOSTREAMFORMATHANDLE* hformat, uint32_t samplesPerSecond, uint8_t bitsPerSample, uint8_t channels);
SPXAPI audio_stream_format_create_from_default_output(SPXAUDIOSTREAMFORMATHANDLE* hformat);
SPXAPI audio_stream_format_create_from_compressed_format(SPXAUDIOSTREAMFORMATHANDLE* hformat, Audio_Stream_Container_Format compressedFormat);
SPXAPI audio_stream_format_release(SPXAUDIOSTREAMFORMATHANDLE hformat);

15
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_auto_detect_source_lang_config.h

@ -0,0 +1,15 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI create_auto_detect_source_lang_config_from_open_range(SPXAUTODETECTSOURCELANGCONFIGHANDLE* hAutoDetectSourceLanguageconfig);
SPXAPI create_auto_detect_source_lang_config_from_languages(SPXAUTODETECTSOURCELANGCONFIGHANDLE* hAutoDetectSourceLanguageconfig, const char* languages);
SPXAPI create_auto_detect_source_lang_config_from_source_lang_config(SPXAUTODETECTSOURCELANGCONFIGHANDLE* hAutoDetectSourceLanguageconfig, SPXSOURCELANGCONFIGHANDLE hSourceLanguageConfig);
SPXAPI add_source_lang_config_to_auto_detect_source_lang_config(SPXAUTODETECTSOURCELANGCONFIGHANDLE hAutoDetectSourceLanguageconfig, SPXSOURCELANGCONFIGHANDLE hSourceLanguageConfig);
SPXAPI_(bool) auto_detect_source_lang_config_is_handle_valid(SPXAUTODETECTSOURCELANGCONFIGHANDLE hAutoDetectSourceLanguageconfig);
SPXAPI auto_detect_source_lang_config_release(SPXAUTODETECTSOURCELANGCONFIGHANDLE hAutoDetectSourceLanguageconfig);
SPXAPI auto_detect_source_lang_config_get_property_bag(SPXAUTODETECTSOURCELANGCONFIGHANDLE hAutoDetectSourceLanguageconfig, SPXPROPERTYBAGHANDLE* hpropbag);

81
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_common.h

@ -0,0 +1,81 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_common.h: Public API declarations for global C definitions and typedefs
//
#pragma once
#include <spxdebug.h>
#include <azac_api_c_common.h> // must include after spxdebug.h or speechapi*.h (can NOT be included before)
#include <stdbool.h>
#include <spxerror.h>
#define SPX_EXTERN_C AZAC_EXTERN_C
#ifndef SPXAPI_EXPORT
#define SPXAPI_EXPORT AZAC_API_EXPORT
#endif
#define SPXAPI_NOTHROW AZAC_API_NOTHROW
#define SPXAPI_RESULTTYPE SPXHR
#define SPXAPI_CALLTYPE AZAC_API_CALLTYPE
#define SPXAPI_VCALLTYPE AZAC_VCALLTYPE
#define SPXDLL_EXPORT AZAC_DLL_EXPORT
#define SPXAPI SPX_EXTERN_C SPXAPI_EXPORT SPXAPI_RESULTTYPE SPXAPI_NOTHROW SPXAPI_CALLTYPE
#define SPXAPI_(type) SPX_EXTERN_C SPXAPI_EXPORT type SPXAPI_NOTHROW SPXAPI_CALLTYPE
#define SPXAPI__(type) SPX_EXTERN_C SPXAPI_EXPORT SPXAPI_NOTHROW type SPXAPI_CALLTYPE
#define SPXAPIV SPX_EXTERN_C SPXAPI_EXPORT SPXAPI_NOTHROW SPXAPI_RESULTTYPE SPXAPI_VCALLTYPE
#define SPXAPIV_(type) SPX_EXTERN_C SPXAPI_EXPORT SPXAPI_NOTHROW type SPXAPI_VCALLTYPE
#define SPXAPI_PRIVATE SPX_EXTERN_C SPXAPI_RESULTTYPE SPXAPI_NOTHROW SPXAPI_CALLTYPE
#define SPXAPI_PRIVATE_(type) SPX_EXTERN_C type SPXAPI_NOTHROW SPXAPI_CALLTYPE
#define _spx_empty _azac_empty
#define _spxhandle _azac_handle
#define SPXHANDLE AZAC_HANDLE
#define SPXERRORHANDLE AZAC_HANDLE
#define SPXPROPERTYBAGHANDLE AZAC_HANDLE
typedef SPXHANDLE SPXASYNCHANDLE;
typedef SPXHANDLE SPXFACTORYHANDLE;
typedef SPXHANDLE SPXRECOHANDLE;
typedef SPXHANDLE SPXSYNTHHANDLE;
typedef SPXHANDLE SPXRESULTHANDLE;
typedef SPXHANDLE SPXEVENTHANDLE;
typedef SPXHANDLE SPXSESSIONHANDLE;
typedef SPXHANDLE SPXTRIGGERHANDLE;
typedef SPXHANDLE SPXLUMODELHANDLE;
typedef SPXHANDLE SPXKEYWORDHANDLE;
typedef SPXHANDLE SPXAUDIOSTREAMFORMATHANDLE;
typedef SPXHANDLE SPXAUDIOSTREAMHANDLE;
typedef SPXHANDLE SPXAUDIOCONFIGHANDLE;
typedef SPXHANDLE SPXSPEECHCONFIGHANDLE;
typedef SPXHANDLE SPXCONNECTIONHANDLE;
typedef SPXHANDLE SPXCONNECTIONMESSAGEHANDLE;
typedef SPXHANDLE SPXACTIVITYHANDLE;
typedef SPXHANDLE SPXACTIVITYJSONHANDLE;
typedef SPXHANDLE SPXGRAMMARHANDLE;
typedef SPXHANDLE SPXPHRASEHANDLE;
typedef SPXHANDLE SPXUSERHANDLE;
typedef SPXHANDLE SPXPARTICIPANTHANDLE;
typedef SPXHANDLE SPXAUTODETECTSOURCELANGCONFIGHANDLE;
typedef SPXHANDLE SPXSOURCELANGCONFIGHANDLE;
typedef SPXHANDLE SPXCONVERSATIONHANDLE;
typedef SPXHANDLE SPXMEETINGHANDLE;
typedef SPXHANDLE SPXCONVERSATIONTRANSLATORHANDLE;
typedef SPXHANDLE SPXVOICEPROFILECLIENTHANDLE;
typedef SPXHANDLE SPXVOICEPROFILEHANDLE;
typedef SPXHANDLE SPXSPEAKERIDHANDLE;
typedef SPXHANDLE SPXSIMODELHANDLE;
typedef SPXHANDLE SPXSVMODELHANDLE;
typedef SPXHANDLE SPXPRONUNCIATIONASSESSMENTCONFIGHANDLE;
typedef SPXHANDLE SPXAUDIOPROCESSINGOPTIONSHANDLE;
typedef SPXHANDLE SPXSPEECHRECOMODELHANDLE;
typedef SPXHANDLE SPXREQUESTHANDLE;
#define SPXHANDLE_INVALID ((SPXHANDLE)-1)
#define SPXHANDLE_RESERVED1 ((SPXHANDLE)+1)

46
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_connection.h

@ -0,0 +1,46 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI connection_from_recognizer(SPXRECOHANDLE recognizerHandle, SPXCONNECTIONHANDLE* connectionHandle);
SPXAPI connection_from_conversation_translator(SPXCONVERSATIONTRANSLATORHANDLE convTransHandle, SPXCONNECTIONHANDLE* connectionHandle);
SPXAPI connection_from_dialog_service_connector(SPXRECOHANDLE convTransHandle, SPXCONNECTIONHANDLE* connectionHandle);
SPXAPI connection_from_speech_synthesizer(SPXSYNTHHANDLE synthesizerHandle, SPXCONNECTIONHANDLE* connectionHandle);
SPXAPI_(bool) connection_handle_is_valid(SPXCONNECTIONHANDLE handle);
SPXAPI connection_handle_release(SPXCONNECTIONHANDLE handle);
SPXAPI connection_async_handle_release(SPXASYNCHANDLE hasync);
SPXAPI connection_open(SPXCONNECTIONHANDLE handle, bool forContinuousRecognition);
SPXAPI connection_close(SPXCONNECTIONHANDLE handle);
SPXAPI connection_set_message_property(SPXCONNECTIONHANDLE handle, const char* path, const char* name, const char* value);
SPXAPI connection_send_message(SPXCONNECTIONHANDLE handle, const char* path, const char* payload);
SPXAPI connection_send_message_async(SPXCONNECTIONHANDLE handle, const char* path, const char* payload, SPXASYNCHANDLE* phasync);
SPXAPI connection_send_message_data(SPXCONNECTIONHANDLE handle, const char* path, uint8_t* data, uint32_t size);
SPXAPI connection_send_message_data_async(SPXCONNECTIONHANDLE handle, const char* path, uint8_t* data, uint32_t size, SPXASYNCHANDLE* phasync);
SPXAPI connection_send_message_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds);
SPXAPI connection_get_property_bag(SPXRECOHANDLE hconn, SPXPROPERTYBAGHANDLE* hpropbag);
typedef void(*CONNECTION_CALLBACK_FUNC)(SPXEVENTHANDLE event, void* context);
SPXAPI connection_connected_set_callback(SPXCONNECTIONHANDLE connection, CONNECTION_CALLBACK_FUNC callback, void* context);
SPXAPI connection_disconnected_set_callback(SPXCONNECTIONHANDLE connection, CONNECTION_CALLBACK_FUNC callback, void* context);
SPXAPI connection_message_received_set_callback(SPXCONNECTIONHANDLE connection, CONNECTION_CALLBACK_FUNC callback, void* context);
SPXAPI_(bool) connection_message_received_event_handle_is_valid(SPXEVENTHANDLE hevent);
SPXAPI connection_message_received_event_handle_release(SPXEVENTHANDLE hevent);
SPXAPI connection_message_received_event_get_message(SPXEVENTHANDLE hevent, SPXCONNECTIONMESSAGEHANDLE* hcm);
SPXAPI_(bool) connection_message_handle_is_valid(SPXCONNECTIONMESSAGEHANDLE handle);
SPXAPI connection_message_handle_release(SPXCONNECTIONMESSAGEHANDLE handle);
SPXAPI connection_message_get_property_bag(SPXCONNECTIONMESSAGEHANDLE hcm, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI connection_message_get_data(SPXCONNECTIONMESSAGEHANDLE hcm, uint8_t* data, uint32_t size);
SPXAPI_(uint32_t) connection_message_get_data_size(SPXCONNECTIONMESSAGEHANDLE hcm);

28
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_conversation.h

@ -0,0 +1,28 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_conversation.h: Public API declarations for conversation related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI conversation_create_from_config(SPXCONVERSATIONHANDLE* phconv, SPXSPEECHCONFIGHANDLE hspeechconfig, const char* id);
SPXAPI conversation_update_participant_by_user_id(SPXCONVERSATIONHANDLE hconv, bool add, const char* userId);
SPXAPI conversation_update_participant_by_user(SPXCONVERSATIONHANDLE hconv, bool add, SPXUSERHANDLE huser);
SPXAPI conversation_update_participant(SPXCONVERSATIONHANDLE hconv, bool add, SPXPARTICIPANTHANDLE hparticipant);
SPXAPI conversation_get_conversation_id(SPXCONVERSATIONHANDLE hconv, char* id, size_t size);
SPXAPI conversation_end_conversation(SPXCONVERSATIONHANDLE hconv);
SPXAPI conversation_get_property_bag(SPXCONVERSATIONHANDLE hconv, SPXPROPERTYBAGHANDLE* phpropbag);
SPXAPI conversation_release_handle(SPXHANDLE handle);
SPXAPI conversation_start_conversation(SPXCONVERSATIONHANDLE hconv);
SPXAPI conversation_delete_conversation(SPXCONVERSATIONHANDLE hconv);
SPXAPI conversation_lock_conversation(SPXCONVERSATIONHANDLE hconv);
SPXAPI conversation_unlock_conversation(SPXCONVERSATIONHANDLE hconv);
SPXAPI conversation_mute_all_participants(SPXCONVERSATIONHANDLE hconv);
SPXAPI conversation_unmute_all_participants(SPXCONVERSATIONHANDLE hconv);
SPXAPI conversation_mute_participant(SPXCONVERSATIONHANDLE hconv, const char * participantId);
SPXAPI conversation_unmute_participant(SPXCONVERSATIONHANDLE hconv, const char * participantId);

11
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_conversation_transcription_result.h

@ -0,0 +1,11 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_conversation_transcriber_result.h: Public API declarations for ConversationTranscriberResult related C methods and enumerations
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI conversation_transcription_result_get_speaker_id(SPXRESULTHANDLE hresult, char* pszSpeakerId, uint32_t cchSpeakerId);

63
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_conversation_translator.h

@ -0,0 +1,63 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_conversation_translator.h: Public API declarations for conversation translator related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
#include <speechapi_c_connection.h>
#ifdef __cplusplus
#include <speechapi_cxx_enums.h>
typedef Microsoft::CognitiveServices::Speech::Transcription::ParticipantChangedReason ParticipantChangedReason;
#else
#include <speechapi_c_property_bag.h>
#endif
typedef void(*PCONV_TRANS_CALLBACK)(SPXCONVERSATIONTRANSLATORHANDLE hConvTrans, SPXEVENTHANDLE hEvent, void* pvContext);
SPXAPI conversation_translator_create_from_config(SPXCONVERSATIONTRANSLATORHANDLE* phandle, SPXAUDIOCONFIGHANDLE haudioinput);
SPXAPI conversation_translator_get_property_bag(SPXCONVERSATIONTRANSLATORHANDLE hconvtranslator, SPXPROPERTYBAGHANDLE* phpropertyBag);
SPXAPI conversation_translator_join(SPXCONVERSATIONTRANSLATORHANDLE hconvtranslator, SPXCONVERSATIONHANDLE hconv, const char* psznickname);
SPXAPI conversation_translator_join_with_id(SPXCONVERSATIONTRANSLATORHANDLE hconvtranslator, const char *pszconversationid, const char* psznickname, const char * pszlang);
SPXAPI conversation_translator_start_transcribing(SPXCONVERSATIONTRANSLATORHANDLE hconvtranslator);
SPXAPI conversation_translator_stop_transcribing(SPXCONVERSATIONTRANSLATORHANDLE hconvtranslator);
SPXAPI conversation_translator_send_text_message(SPXCONVERSATIONTRANSLATORHANDLE hconvtranslator, const char *pszmessage);
SPXAPI conversation_translator_leave(SPXCONVERSATIONTRANSLATORHANDLE hconvtranslator);
SPXAPI conversation_translator_set_authorization_token(SPXCONVERSATIONTRANSLATORHANDLE hconvtranslator, const char* pszAuthToken, const char* pszRegion);
SPXAPI_(bool) conversation_translator_handle_is_valid(SPXCONVERSATIONTRANSLATORHANDLE handle);
SPXAPI conversation_translator_handle_release(SPXHANDLE handle);
SPXAPI conversation_translator_session_started_set_callback(SPXCONVERSATIONTRANSLATORHANDLE hConvTrans, PCONV_TRANS_CALLBACK pCallback, void* pvContext);
SPXAPI conversation_translator_session_stopped_set_callback(SPXCONVERSATIONTRANSLATORHANDLE hConvTrans, PCONV_TRANS_CALLBACK pCallback, void* pvContext);
SPXAPI conversation_translator_canceled_set_callback(SPXCONVERSATIONTRANSLATORHANDLE hConvTrans, PCONV_TRANS_CALLBACK pCallback, void* pvContext);
SPXAPI conversation_translator_participants_changed_set_callback(SPXCONVERSATIONTRANSLATORHANDLE hConvTrans, PCONV_TRANS_CALLBACK pCallback, void* pvContext);
SPXAPI conversation_translator_conversation_expiration_set_callback(SPXCONVERSATIONTRANSLATORHANDLE hConvTrans, PCONV_TRANS_CALLBACK pCallback, void* pvContext);
SPXAPI conversation_translator_transcribing_set_callback(SPXCONVERSATIONTRANSLATORHANDLE hConvTrans, PCONV_TRANS_CALLBACK pCallback, void* pvContext);
SPXAPI conversation_translator_transcribed_set_callback(SPXCONVERSATIONTRANSLATORHANDLE hConvTrans, PCONV_TRANS_CALLBACK pCallback, void* pvContext);
SPXAPI conversation_translator_text_message_recevied_set_callback(SPXCONVERSATIONTRANSLATORHANDLE hConvTrans, PCONV_TRANS_CALLBACK pCallback, void* pvContext);
SPXAPI conversation_translator_connection_connected_set_callback(SPXCONNECTIONHANDLE hConnection, CONNECTION_CALLBACK_FUNC pCallback, void * pvContext);
SPXAPI conversation_translator_connection_disconnected_set_callback(SPXCONNECTIONHANDLE hConnection, CONNECTION_CALLBACK_FUNC pCallback, void * pvContext);
SPXAPI_(bool) conversation_translator_event_handle_is_valid(SPXCONVERSATIONTRANSLATORHANDLE handle);
SPXAPI conversation_translator_event_handle_release(SPXHANDLE handle);
SPXAPI conversation_translator_event_get_expiration_time(SPXEVENTHANDLE hevent, int32_t* pexpirationminutes);
SPXAPI conversation_translator_event_get_participant_changed_reason(SPXEVENTHANDLE hevent, ParticipantChangedReason* preason);
SPXAPI conversation_translator_event_get_participant_changed_at_index(SPXEVENTHANDLE hevent, int index, SPXPARTICIPANTHANDLE* phparticipant);
SPXAPI conversation_translator_result_get_user_id(SPXRESULTHANDLE hresult, char* pszUserId, uint32_t cchUserId);
SPXAPI conversation_translator_result_get_original_lang(SPXRESULTHANDLE hresult, char * psz, uint32_t * pcch);
SPXAPI conversation_translator_participant_get_avatar(SPXEVENTHANDLE hevent, char * psz, uint32_t * pcch);
SPXAPI conversation_translator_participant_get_displayname(SPXEVENTHANDLE hevent, char * psz, uint32_t * pcch);
SPXAPI conversation_translator_participant_get_id(SPXEVENTHANDLE hevent, char * psz, uint32_t * pcch);
SPXAPI conversation_translator_participant_get_is_muted(SPXEVENTHANDLE hevent, bool * pMuted);
SPXAPI conversation_translator_participant_get_is_host(SPXEVENTHANDLE hevent, bool * pIsHost);
SPXAPI conversation_translator_participant_get_is_using_tts(SPXEVENTHANDLE hevent, bool * ptts);

8
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_diagnostics.h

@ -0,0 +1,8 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
#include <azac_api_c_diagnostics.h> // must include after spxdebug.h or speechapi*.h (can NOT be included before)

15
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_dialog_service_config.h

@ -0,0 +1,15 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_dialog_service_config.h: Public API declarations for dialog service connector configuration related C methods and types
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI bot_framework_config_from_subscription(SPXSPEECHCONFIGHANDLE* ph_config, const char* subscription, const char* region, const char *bot_Id);
SPXAPI bot_framework_config_from_authorization_token(SPXSPEECHCONFIGHANDLE* ph_config, const char* auth_token, const char* region, const char* bot_Id);
SPXAPI custom_commands_config_from_subscription(SPXSPEECHCONFIGHANDLE* ph_dialog_service_config, const char* app_id, const char *subscription, const char* region);
SPXAPI custom_commands_config_from_authorization_token(SPXSPEECHCONFIGHANDLE* ph_dialog_service_config, const char* app_id, const char *auth_token, const char* region);

92
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_dialog_service_connector.h

@ -0,0 +1,92 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_dialog_service_connector.h: Public API declaration for Dialog Service Connector related C methods.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI_(bool) dialog_service_connector_handle_is_valid(SPXRECOHANDLE h_connector);
SPXAPI dialog_service_connector_handle_release(SPXRECOHANDLE h_connector);
SPXAPI_(bool) dialog_service_connector_async_handle_is_valid(SPXASYNCHANDLE h_async);
SPXAPI dialog_service_connector_async_handle_release(SPXASYNCHANDLE h_async);
SPXAPI_(bool) dialog_service_connector_async_void_handle_is_valid(SPXASYNCHANDLE h_async);
SPXAPI dialog_service_connector_async_void_handle_release(SPXASYNCHANDLE h_async);
SPXAPI_(bool) dialog_service_connector_async_string_handle_is_valid(SPXASYNCHANDLE h_async);
SPXAPI dialog_service_connector_async_string_handle_release(SPXASYNCHANDLE h_async);
SPXAPI_(bool) dialog_service_connector_async_reco_result_handle_is_valid(SPXASYNCHANDLE h_async);
SPXAPI dialog_service_connector_async_reco_result_handle_release(SPXASYNCHANDLE h_async);
SPXAPI_(bool) dialog_service_connector_activity_received_event_handle_is_valid(SPXEVENTHANDLE h_event);
SPXAPI dialog_service_connector_activity_received_event_release(SPXEVENTHANDLE h_event);
SPXAPI_(bool) dialog_service_connector_turn_status_received_handle_is_valid(SPXEVENTHANDLE h_event);
SPXAPI dialog_service_connector_turn_status_received_release(SPXEVENTHANDLE h_event);
SPXAPI dialog_service_connector_get_property_bag(SPXRECOHANDLE h_connector, SPXPROPERTYBAGHANDLE* h_prop_bag);
SPXAPI dialog_service_connector_connect(SPXRECOHANDLE h_connector);
SPXAPI dialog_service_connector_connect_async(SPXRECOHANDLE h_connector, SPXASYNCHANDLE* p_async);
SPXAPI dialog_service_connector_connect_async_wait_for(SPXASYNCHANDLE h_async, uint32_t milliseconds);
SPXAPI dialog_service_connector_disconnect(SPXRECOHANDLE h_connector);
SPXAPI dialog_service_connector_disconnect_async(SPXRECOHANDLE h_connector, SPXASYNCHANDLE* p_async);
SPXAPI dialog_service_connector_disconnect_async_wait_for(SPXASYNCHANDLE h_async, uint32_t milliseconds);
SPXAPI dialog_service_connector_send_activity(SPXRECOHANDLE h_connector, const char* activity, char* interaction_id);
SPXAPI dialog_service_connector_send_activity_async(SPXRECOHANDLE h_connector, const char* activity, SPXASYNCHANDLE* p_async);
SPXAPI dialog_service_connector_send_activity_async_wait_for(SPXASYNCHANDLE h_async, uint32_t milliseconds, char* interaction_id);
SPXAPI dialog_service_connector_start_keyword_recognition(SPXRECOHANDLE h_connector, SPXKEYWORDHANDLE h_keyword);
SPXAPI dialog_service_connector_start_keyword_recognition_async(SPXRECOHANDLE h_connector, SPXKEYWORDHANDLE h_keyword, SPXASYNCHANDLE* p_async);
SPXAPI dialog_service_connector_start_keyword_recognition_async_wait_for(SPXASYNCHANDLE h_async, uint32_t milliseconds);
SPXAPI dialog_service_connector_stop_keyword_recognition(SPXRECOHANDLE h_connector);
SPXAPI dialog_service_connector_stop_keyword_recognition_async(SPXRECOHANDLE h_connector, SPXASYNCHANDLE* p_async);
SPXAPI dialog_service_connector_stop_keyword_recognition_async_wait_for(SPXASYNCHANDLE h_async, uint32_t milliseconds);
SPXAPI dialog_service_connector_listen_once(SPXRECOHANDLE h_connector, SPXRESULTHANDLE* p_result);
SPXAPI dialog_service_connector_listen_once_async(SPXRECOHANDLE h_connector, SPXASYNCHANDLE* p_async);
SPXAPI dialog_service_connector_listen_once_async_wait_for(SPXASYNCHANDLE h_async, uint32_t milliseconds, SPXRESULTHANDLE* p_result);
SPXAPI dialog_service_connector_start_continuous_listening(SPXRECOHANDLE h_connector);
SPXAPI dialog_service_connector_start_continuous_listening_async(SPXRECOHANDLE h_connector, SPXASYNCHANDLE* p_async);
SPXAPI dialog_service_connector_stop_listening(SPXRECOHANDLE h_connector);
SPXAPI dialog_service_connector_stop_listening_async(SPXRECOHANDLE h_connector, SPXASYNCHANDLE* p_async);
typedef void(*PSESSION_CALLBACK_FUNC)(SPXRECOHANDLE h_connector, SPXEVENTHANDLE h_event, void* pv_context);
SPXAPI dialog_service_connector_session_started_set_callback(SPXRECOHANDLE h_connector, PSESSION_CALLBACK_FUNC p_callback, void *pv_context);
SPXAPI dialog_service_connector_session_stopped_set_callback(SPXRECOHANDLE h_connector, PSESSION_CALLBACK_FUNC p_callback, void *pv_context);
SPXAPI dialog_service_connector_speech_start_detected_set_callback(SPXRECOHANDLE h_connector, PSESSION_CALLBACK_FUNC p_callback, void* pv_context);
SPXAPI dialog_service_connector_speech_end_detected_set_callback(SPXRECOHANDLE h_connector, PSESSION_CALLBACK_FUNC p_callback, void* pv_context);
typedef void(*PRECOGNITION_CALLBACK_FUNC)(SPXRECOHANDLE h_connector, SPXEVENTHANDLE h_event, void* pv_context);
SPXAPI dialog_service_connector_recognized_set_callback(SPXRECOHANDLE h_connector, PRECOGNITION_CALLBACK_FUNC p_callback, void *pv_context);
SPXAPI dialog_service_connector_recognizing_set_callback(SPXRECOHANDLE h_connector, PRECOGNITION_CALLBACK_FUNC p_callback, void *pv_context);
SPXAPI dialog_service_connector_canceled_set_callback(SPXRECOHANDLE h_connector, PRECOGNITION_CALLBACK_FUNC p_callback, void *pv_context);
SPXAPI dialog_service_connector_activity_received_set_callback(SPXRECOHANDLE h_connector, PRECOGNITION_CALLBACK_FUNC p_callback, void *pv_context);
SPXAPI dialog_service_connector_turn_status_received_set_callback(SPXRECOHANDLE h_connector, PRECOGNITION_CALLBACK_FUNC p_callback, void* pv_context);
SPXAPI dialog_service_connector_activity_received_event_get_activity_size(SPXEVENTHANDLE h_event, size_t* size);
SPXAPI dialog_service_connector_activity_received_event_get_activity(SPXEVENTHANDLE h_event, char* p_activity, size_t size);
SPXAPI_(bool) dialog_service_connector_activity_received_event_has_audio(SPXEVENTHANDLE h_event);
SPXAPI dialog_service_connector_activity_received_event_get_audio(SPXEVENTHANDLE h_event, SPXAUDIOSTREAMHANDLE* p_audio);
SPXAPI dialog_service_connector_turn_status_received_get_interaction_id_size(SPXEVENTHANDLE h_event, size_t* size);
SPXAPI dialog_service_connector_turn_status_received_get_interaction_id(SPXEVENTHANDLE h_event, char* p_interaction_id, size_t size);
SPXAPI dialog_service_connector_turn_status_received_get_conversation_id_size(SPXEVENTHANDLE h_event, size_t* size);
SPXAPI dialog_service_connector_turn_status_received_get_conversation_id(SPXEVENTHANDLE h_event, char* p_interaction_id, size_t size);
SPXAPI dialog_service_connector_turn_status_received_get_status(SPXEVENTHANDLE h_event, int* p_status);
SPXAPI dialog_service_connector_recognized_size(SPXEVENTHANDLE h_event, uint32_t* size);
SPXAPI dialog_service_connector_recognized_get_result(SPXEVENTHANDLE h_event, uint32_t* size);

21
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_embedded_speech_config.h

@ -0,0 +1,21 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
#include <speechapi_c_speech_config.h>
#include <speechapi_c_speech_recognition_model.h>
#include <speechapi_c_speech_translation_model.h>
SPXAPI embedded_speech_config_create(SPXSPEECHCONFIGHANDLE* hconfig);
SPXAPI embedded_speech_config_add_path(SPXSPEECHCONFIGHANDLE hconfig, const char* path);
SPXAPI embedded_speech_config_get_num_speech_reco_models(SPXSPEECHCONFIGHANDLE hconfig, uint32_t* numModels);
SPXAPI embedded_speech_config_get_speech_reco_model(SPXSPEECHCONFIGHANDLE hconfig, uint32_t index, SPXSPEECHRECOMODELHANDLE* hmodel);
SPXAPI embedded_speech_config_get_num_speech_translation_models(SPXSPEECHCONFIGHANDLE hconfig, uint32_t* numModels);
SPXAPI embedded_speech_config_get_speech_translation_model(SPXSPEECHCONFIGHANDLE hconfig, uint32_t index, SPXSPEECHRECOMODELHANDLE* hmodel);
SPXAPI embedded_speech_config_set_speech_recognition_model(SPXSPEECHCONFIGHANDLE hconfig, const char* name, const char* license);
SPXAPI embedded_speech_config_set_speech_synthesis_voice(SPXSPEECHCONFIGHANDLE hconfig, const char* name, const char* license);
SPXAPI embedded_speech_config_set_speech_translation_model(SPXSPEECHCONFIGHANDLE hconfig, const char* name, const char* license);
SPXAPI embedded_speech_config_set_keyword_recognition_model(SPXSPEECHCONFIGHANDLE hconfig, const char* name, const char* license);

9
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_error.h

@ -0,0 +1,9 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
//
#pragma once
#include <speechapi_c_common.h>
#include <azac_api_c_error.h> // must include after spxdebug.h or speechapi*.h (can NOT be included before)

105
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_ext_audiocompression.h

@ -0,0 +1,105 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include "speechapi_c_common.h"
const char CODECCREATEEXPORTNAME[] = "codec_create";
struct codec_c_interface;
typedef struct codec_c_interface* codec_c_interface_P;
typedef codec_c_interface_P SPXCODECCTYPE;
/*! \cond INTERNAL */
/**
* The SPX_CODEC_CLIENT_GET_PROPERTY represents the function reading a property value
* @param id Property id.
* @param buffer caller provided buffer to receive the value of the property
* @param buffersize buffer size. If buffer is passed as null it will return the required buffer size.
* @param codecContext A pointer to caller data provided through the codec_create call.
* @return A return code or zero if successful.
*/
typedef SPXAPI_RESULTTYPE (SPXAPI_CALLTYPE *SPX_CODEC_CLIENT_GET_PROPERTY)(const char* id, char* buffer, uint64_t* buffersize, void* codecContext);
/**
* The AUDIO_ENCODER_ONENCODEDDATA type represents an application-defined
* status callback function used to provide the encoded data.
* @param pBuffer audio data buffer.
* @param bytesToWrite The length of pBuffer in bytes.
* @param duration_100nanos The duration of the audio sample
* @param pContext A pointer to the application-defined callback context.
*/
typedef void(SPXAPI_CALLTYPE *AUDIO_ENCODER_ONENCODEDDATA)(const uint8_t* pBuffer, size_t bytesToWrite, uint64_t duration_100nanos, void* pContext);
struct codec_c_interface
{
/**
* @param codec codec Object returned by the codec_create call to be initialized
* @param inputSamplesPerSecond sample rate for the input audio
* @param inputBitsPerSample bits per sample for the input audio
* @param inputChannels number of channel of the input audio
* @param dataCallback An application defined callback.
* @param pContext A pointer to the application-defined callback context.
* @return A return code or zero if successful.
*/
SPXAPI_RESULTTYPE (SPXAPI_CALLTYPE *init)(
SPXCODECCTYPE codec,
uint32_t inputSamplesPerSecond,
uint8_t inputBitsPerSample,
uint8_t inputChannels,
AUDIO_ENCODER_ONENCODEDDATA datacallback,
void* pContext);
/**
* @param codec codec object returned by the codec_create call.
* @param buffer caller provided buffer to receive the value of the property
* @param buffersize buffer size. If buffer is passed as null it will return the required buffer size.
* @return A return code or zero if successful.
*/
SPXAPI_RESULTTYPE (SPXAPI_CALLTYPE* get_format_type)(SPXCODECCTYPE codec, char* buffer, uint64_t* buffersize);
/**
* Encodes raw PCM data.
* @param codec codec object returned by the codec_create call.
* @param pBuffer The PCM data.
* @param bytesToWrite The length pBuffer.
* @return A return code or zero if successful.
*/
SPXAPI_RESULTTYPE (SPXAPI_CALLTYPE *encode) (SPXCODECCTYPE codec, const uint8_t* pBuffer, size_t bytesToWrite);
/**
* Flushes the encoder.
* @param codec codec object returned by the codec_create call.
* @return A return code or zero if successful.
*/
SPXAPI_RESULTTYPE(SPXAPI_CALLTYPE* flush)(SPXCODECCTYPE codec);
/**
* Terminate the encoded stream immediately
* @param codec codec object returned by the codec_create call.
* @return A return code or zero if successful.
*/
SPXAPI_RESULTTYPE (SPXAPI_CALLTYPE *endstream)(SPXCODECCTYPE codec);
/**
* Destroys the encoder. The codec object should not be used anymore after this call.
* @param codec codec object returned by the codec_create call.
* @return A return code or zero if successful.
*/
SPXAPI_RESULTTYPE (SPXAPI_CALLTYPE *destroy) (SPXCODECCTYPE codec);
};
/**
* Creates a codec object. This method needs to be exported from the dll
* @param codecid - codec id, can be null or empty if the library implements only one codec.
* @param codecContext - context to be used to call back to the caller
* @param property_read_func - function to read properties
* @return A codec object
*/
SPX_EXTERN_C SPXDLL_EXPORT SPXCODECCTYPE codec_create(const char* codecid, void* codecContext, SPX_CODEC_CLIENT_GET_PROPERTY property_read_func);
typedef SPXCODECCTYPE (*PCODEC_CREATE_FUNC)(const char* codecid, void* codecContext, SPX_CODEC_CLIENT_GET_PROPERTY property_read_func);
/*! \endcond */

29
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_factory.h

@ -0,0 +1,29 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI recognizer_create_speech_recognizer_from_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_create_speech_recognizer_from_auto_detect_source_lang_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUTODETECTSOURCELANGCONFIGHANDLE hautoDetectSourceLangConfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_create_speech_recognizer_from_source_lang_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXSOURCELANGCONFIGHANDLE hSourceLangConfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_create_translation_recognizer_from_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_create_translation_recognizer_from_auto_detect_source_lang_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUTODETECTSOURCELANGCONFIGHANDLE hautoDetectSourceLangConfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_create_intent_recognizer_from_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_create_keyword_recognizer_from_audio_config(SPXRECOHANDLE* phreco, SPXAUDIOCONFIGHANDLE haudio);
SPXAPI recognizer_create_source_language_recognizer_from_auto_detect_source_lang_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUTODETECTSOURCELANGCONFIGHANDLE hautoDetectSourceLangConfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI synthesizer_create_speech_synthesizer_from_config(SPXSYNTHHANDLE* phsynth, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUDIOCONFIGHANDLE haudioOuput);
SPXAPI synthesizer_create_speech_synthesizer_from_auto_detect_source_lang_config(SPXSYNTHHANDLE* phsynth, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUTODETECTSOURCELANGCONFIGHANDLE hautoDetectSourceLangConfig, SPXAUDIOCONFIGHANDLE haudioOutput);
SPXAPI dialog_service_connector_create_dialog_service_connector_from_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUDIOCONFIGHANDLE haudioInput);
//SPXAPI recognizer_create_conversation_transcriber_from_config(SPXRECOHANDLE* phreco, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_create_conversation_transcriber_from_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_create_conversation_transcriber_from_auto_detect_source_lang_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUTODETECTSOURCELANGCONFIGHANDLE hautoDetectSourceLangConfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_create_conversation_transcriber_from_source_lang_config(SPXRECOHANDLE* phreco, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXSOURCELANGCONFIGHANDLE hSourceLangConfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_join_conversation(SPXCONVERSATIONHANDLE hconv, SPXRECOHANDLE hreco);
SPXAPI recognizer_leave_conversation(SPXRECOHANDLE hreco);
SPXAPI recognizer_create_meeting_transcriber_from_config(SPXRECOHANDLE* phreco, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI recognizer_join_meeting(SPXMEETINGHANDLE hmeeting, SPXRECOHANDLE hreco);
SPXAPI recognizer_leave_meeting(SPXRECOHANDLE hreco);
SPXAPI transcriber_get_participants_list(SPXRECOHANDLE hreco, SPXPARTICIPANTHANDLE* participants, int size);

33
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_grammar.h

@ -0,0 +1,33 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_grammar.h: Public API declarations for Grammar related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
typedef enum
{
// A Recognition Factor will apply to grammars that are referenced as individual words.
PartialPhrase = 1
} GrammarList_RecognitionFactorScope;
SPXAPI_(bool) grammar_handle_is_valid(SPXGRAMMARHANDLE hgrammar);
SPXAPI phrase_list_grammar_from_recognizer_by_name(SPXGRAMMARHANDLE* hgrammar, SPXRECOHANDLE hreco, const char* name);
SPXAPI grammar_handle_release(SPXGRAMMARHANDLE hgrammar);
SPXAPI phrase_list_grammar_add_phrase(SPXGRAMMARHANDLE hgrammar, SPXPHRASEHANDLE hphrase);
SPXAPI phrase_list_grammar_clear(SPXGRAMMARHANDLE hgrammar);
SPXAPI_(bool) grammar_phrase_handle_is_valid(SPXPHRASEHANDLE hphrase);
SPXAPI grammar_phrase_create_from_text(SPXPHRASEHANDLE* hphrase, const char* phrase);
SPXAPI grammar_phrase_handle_release(SPXPHRASEHANDLE hphrase);
SPXAPI grammar_create_from_storage_id(SPXGRAMMARHANDLE *hgrammarlist, const char *id);
SPXAPI grammar_list_from_recognizer(SPXGRAMMARHANDLE *hgrammarlist, SPXRECOHANDLE hreco);
SPXAPI grammar_list_add_grammar(SPXGRAMMARHANDLE hgrammarlist, SPXGRAMMARHANDLE hgrammar);
SPXAPI grammar_list_set_recognition_factor(SPXGRAMMARHANDLE hgrammarlist, double factor, GrammarList_RecognitionFactorScope scope);
SPXAPI class_language_model_from_storage_id(SPXGRAMMARHANDLE* hclm, const char *storageid);
SPXAPI class_language_model_assign_class(SPXGRAMMARHANDLE hclm, const char *classname, SPXGRAMMARHANDLE hgrammar);

9
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_hybrid_speech_config.h

@ -0,0 +1,9 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI hybrid_speech_config_create(SPXSPEECHCONFIGHANDLE* hconfig, SPXSPEECHCONFIGHANDLE hcloudSpeechConfig, SPXSPEECHCONFIGHANDLE hembeddedSpeechConfig);

16
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_intent_recognizer.h

@ -0,0 +1,16 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_intent_recognizer.h: Public API declarations for IntentRecognizer related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI intent_recognizer_add_intent(SPXRECOHANDLE hreco, const char* intentId, SPXTRIGGERHANDLE htrigger);
SPXAPI intent_recognizer_add_intent_with_model_id(SPXRECOHANDLE hreco, SPXTRIGGERHANDLE htrigger, const char* modelId);
SPXAPI intent_recognizer_recognize_text_once(SPXRECOHANDLE hreco, const char* text, SPXRESULTHANDLE* hresult);
SPXAPI intent_recognizer_clear_language_models(SPXRECOHANDLE hreco);
SPXAPI intent_recognizer_import_pattern_matching_model(SPXRECOHANDLE hreco, const char* jsonData);
SPXAPI intent_recognizer_add_conversational_language_understanding_model(SPXRECOHANDLE hreco, const char* languageResourceKey, const char* endpoint, const char* projectName, const char* deploymentName);

11
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_intent_result.h

@ -0,0 +1,11 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_intent_result.h: Public API declarations for IntentResult related C methods and enumerations
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI intent_result_get_intent_id(SPXRESULTHANDLE hresult, char* pszIntentId, uint32_t cchIntentId);

17
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_intent_trigger.h

@ -0,0 +1,17 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_intent_trigger.h: Public API declarations for IntentTrigger related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI_(bool) intent_trigger_handle_is_valid(SPXTRIGGERHANDLE htrigger);
SPXAPI intent_trigger_create_from_phrase(SPXTRIGGERHANDLE* htrigger, const char* phrase);
SPXAPI intent_trigger_create_from_language_understanding_model(SPXTRIGGERHANDLE* htrigger, SPXLUMODELHANDLE hlumodel, const char* intentName);
SPXAPI intent_trigger_handle_release(SPXTRIGGERHANDLE htrigger);

37
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_json.h

@ -0,0 +1,37 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/azai/vision/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI__(const char*) ai_core_string_create(const char* str, size_t size);
SPXAPI_(void) ai_core_string_free(const char* str);
SPXAPI_(int) ai_core_json_parser_create(SPXHANDLE* parser, const char* json, size_t jsize); // returns item for root
SPXAPI_(bool) ai_core_json_parser_handle_is_valid(SPXHANDLE parser);
SPXAPI ai_core_json_parser_handle_release(SPXHANDLE parser);
SPXAPI_(int) ai_core_json_builder_create(SPXHANDLE* builder, const char* json, size_t jsize); // returns item for root
SPXAPI_(bool) ai_core_json_builder_handle_is_valid(SPXHANDLE builder);
SPXAPI ai_core_json_builder_handle_release(SPXHANDLE builder);
SPXAPI_(int) ai_core_json_item_count(SPXHANDLE parserOrBuilder, int item);
SPXAPI_(int) ai_core_json_item_at(SPXHANDLE parserOrBuilder, int item, int index, const char* find); // returns item found
SPXAPI_(int) ai_core_json_item_next(SPXHANDLE parserOrBuilder, int item); // returns next item
SPXAPI_(int) ai_core_json_item_name(SPXHANDLE parserOrBuilder, int item); // returns item representing name of item specified
SPXAPI_(int) ai_core_json_value_kind(SPXHANDLE parserOrBuilder, int item);
SPXAPI_(bool) ai_core_json_value_as_bool(SPXHANDLE parserOrBuilder, int item, bool defaultValue);
SPXAPI_(double) ai_core_json_value_as_double(SPXHANDLE parserOrBuilder, int item, double defaultValue);
SPXAPI_(int64_t) ai_core_json_value_as_int(SPXHANDLE parserOrBuilder, int item, int64_t defaultValue);
SPXAPI_(uint64_t) ai_core_json_value_as_uint(SPXHANDLE parserOrBuilder, int item, uint64_t defaultValue);
SPXAPI__(const char*) ai_core_json_value_as_string_ptr(SPXHANDLE parserOrBuilder, int item, size_t* size);
SPXAPI__(const char*) ai_core_json_value_as_string_copy(SPXHANDLE parserOrBuilder, int item, const char* defaultValue);
SPXAPI__(const char*) ai_core_json_value_as_json_copy(SPXHANDLE parserOrBuilder, int item);
SPXAPI_(int) ai_core_json_builder_item_add(SPXHANDLE builder, int item, int index, const char* find);
SPXAPI ai_core_json_builder_item_set(SPXHANDLE builder, int item, const char* json, size_t jsize, int kind, const char* str, size_t ssize, bool boolean, int integer, double number);

17
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_keyword_recognition_model.h

@ -0,0 +1,17 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_keyword_recognition_model.h: Public API declarations for KeywordRecognitionModel related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI_(bool) keyword_recognition_model_handle_is_valid(SPXKEYWORDHANDLE hkeyword);
SPXAPI keyword_recognition_model_handle_release(SPXKEYWORDHANDLE hkeyword);
SPXAPI keyword_recognition_model_create_from_file(const char* fileName, SPXKEYWORDHANDLE* phkwmodel);
SPXAPI keyword_recognition_model_create_from_config(SPXSPEECHCONFIGHANDLE hconfig, SPXKEYWORDHANDLE* phkwmodel);
SPXAPI keyword_recognition_model_add_user_defined_wake_word(SPXKEYWORDHANDLE hkwmodel, const char* wakeWord);

18
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_language_understanding_model.h

@ -0,0 +1,18 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_language_understanding_model.h: Public API declarations for LanguageUnderstandingModel related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI_(bool) language_understanding_model_handle_is_valid(SPXLUMODELHANDLE hlumodel);
SPXAPI language_understanding_model_create_from_uri(SPXLUMODELHANDLE* hlumodel, const char* uri);
SPXAPI language_understanding_model_create_from_app_id(SPXLUMODELHANDLE* hlumodel, const char* appId);
SPXAPI language_understanding_model_create_from_subscription(SPXLUMODELHANDLE* hlumodel, const char* subscriptionKey, const char* appId, const char* region);
SPXAPI language_understanding_model__handle_release(SPXLUMODELHANDLE hlumodel);
SPXAPI__(const char *) language_understanding_model_get_model_id(SPXLUMODELHANDLE hlumodel);

28
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_meeting.h

@ -0,0 +1,28 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_meeting.h: Public API declarations for meeting related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI meeting_create_from_config(SPXMEETINGHANDLE* phmeeting, SPXSPEECHCONFIGHANDLE hspeechconfig, const char* id);
SPXAPI meeting_update_participant_by_user_id(SPXMEETINGHANDLE hconv, bool add, const char* userId);
SPXAPI meeting_update_participant_by_user(SPXMEETINGHANDLE hconv, bool add, SPXUSERHANDLE huser);
SPXAPI meeting_update_participant(SPXMEETINGHANDLE hconv, bool add, SPXPARTICIPANTHANDLE hparticipant);
SPXAPI meeting_get_meeting_id(SPXMEETINGHANDLE hconv, char* id, size_t size);
SPXAPI meeting_end_meeting(SPXMEETINGHANDLE hconv);
SPXAPI meeting_get_property_bag(SPXMEETINGHANDLE hconv, SPXPROPERTYBAGHANDLE* phpropbag);
SPXAPI meeting_release_handle(SPXHANDLE handle);
SPXAPI meeting_start_meeting(SPXMEETINGHANDLE hconv);
SPXAPI meeting_delete_meeting(SPXMEETINGHANDLE hconv);
SPXAPI meeting_lock_meeting(SPXMEETINGHANDLE hconv);
SPXAPI meeting_unlock_meeting(SPXMEETINGHANDLE hconv);
SPXAPI meeting_mute_all_participants(SPXMEETINGHANDLE hconv);
SPXAPI meeting_unmute_all_participants(SPXMEETINGHANDLE hconv);
SPXAPI meeting_mute_participant(SPXMEETINGHANDLE hconv, const char * participantId);
SPXAPI meeting_unmute_participant(SPXMEETINGHANDLE hconv, const char * participantId);

12
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_meeting_transcription_result.h

@ -0,0 +1,12 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_meeting_transcriber_result.h: Public API declarations for MeetingTranscriberResult related C methods and enumerations
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI meeting_transcription_result_get_user_id(SPXRESULTHANDLE hresult, char* pszUserId, uint32_t cchUserId);
SPXAPI meeting_transcription_result_get_utterance_id(SPXRESULTHANDLE hresult, char* pszUtteranceId, uint32_t cchUtteranceId);

12
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_operations.h

@ -0,0 +1,12 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_operations.h: Public API declaration for common operation methods in the C API layer.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI speechapi_async_handle_release(SPXASYNCHANDLE h_async);
SPXAPI speechapi_async_wait_for(SPXASYNCHANDLE h_async, uint32_t milliseconds);

15
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_participant.h

@ -0,0 +1,15 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_participant.h: Public API declarations for conversation transcriber participant related C methods and enumerations
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI participant_create_handle(SPXPARTICIPANTHANDLE* hparticipant, const char* userId, const char* preferred_language, const char* voice_signature);
SPXAPI participant_release_handle(SPXPARTICIPANTHANDLE hparticipant);
SPXAPI participant_set_preferred_langugage(SPXPARTICIPANTHANDLE hparticipant, const char* preferred_language);
SPXAPI participant_set_voice_signature(SPXPARTICIPANTHANDLE hparticipant, const char* voice_signature);
SPXAPI participant_get_property_bag(SPXPARTICIPANTHANDLE hparticipant, SPXPROPERTYBAGHANDLE* hpropbag);

33
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_pattern_matching_model.h

@ -0,0 +1,33 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_pattern_matching_model.h: Public API declarations for PatternMatchingModel related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI_(bool) pattern_matching_model_handle_is_valid(SPXLUMODELHANDLE hlumodel);
SPXAPI pattern_matching_model_create(SPXLUMODELHANDLE* hlumodel, SPXRECOHANDLE hIntentReco, const char* id);
SPXAPI pattern_matching_model_create_from_id(SPXLUMODELHANDLE* hlumodel, const char* id);
typedef SPXAPI_RESULTTYPE(SPXAPI_CALLTYPE* PATTERN_MATCHING_MODEL_GET_STR_FROM_INDEX)(void* context, size_t index, const char** str, size_t* size);
SPXAPI pattern_matching_model_add_entity(
SPXLUMODELHANDLE hlumodel,
const char* id,
int32_t type,
int32_t mode,
size_t numPhrases,
void* phraseContext,
PATTERN_MATCHING_MODEL_GET_STR_FROM_INDEX phraseGetter);
SPXAPI pattern_matching_model_add_intent(
SPXLUMODELHANDLE hlumodel,
const char* id,
uint32_t priority,
size_t numPhrases,
void* phraseContext,
PATTERN_MATCHING_MODEL_GET_STR_FROM_INDEX phraseGetter);

33
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_pronunciation_assessment_config.h

@ -0,0 +1,33 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
typedef enum
{
PronunciationAssessmentGradingSystem_FivePoint = 1,
PronunciationAssessmentGradingSystem_HundredMark = 2
} Pronunciation_Assessment_Grading_System;
typedef enum
{
PronunciationAssessmentGranularity_Phoneme = 1,
PronunciationAssessmentGranularity_Word = 2,
PronunciationAssessmentGranularity_FullText = 3
} Pronunciation_Assessment_Granularity;
SPXAPI create_pronunciation_assessment_config(SPXPRONUNCIATIONASSESSMENTCONFIGHANDLE* hPronunciationAssessmentConfig,
const char* referenceText,
Pronunciation_Assessment_Grading_System gradingSystem,
Pronunciation_Assessment_Granularity granularity,
bool enableMiscue);
SPXAPI create_pronunciation_assessment_config_from_json(SPXPRONUNCIATIONASSESSMENTCONFIGHANDLE* hPronunciationAssessmentConfig, const char* json);
SPXAPI_(bool) pronunciation_assessment_config_is_handle_valid(SPXPRONUNCIATIONASSESSMENTCONFIGHANDLE hPronunciationAssessmentConfig);
SPXAPI pronunciation_assessment_config_release(SPXPRONUNCIATIONASSESSMENTCONFIGHANDLE hPronunciationAssessmentConfig);
SPXAPI pronunciation_assessment_config_get_property_bag(
SPXPRONUNCIATIONASSESSMENTCONFIGHANDLE hPronunciationAssessmentConfig, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI__(const char*) pronunciation_assessment_config_to_json(SPXPRONUNCIATIONASSESSMENTCONFIGHANDLE hPronunciationAssessmentConfig);
SPXAPI pronunciation_assessment_config_apply_to_recognizer(SPXPRONUNCIATIONASSESSMENTCONFIGHANDLE hPronunciationAssessmentConfig, SPXRECOHANDLE hreco);

159
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_property_bag.h

@ -0,0 +1,159 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_property_bag.h: Public API declarations for Property Bag related C methods
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI property_bag_create(SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI_(bool) property_bag_is_valid(SPXPROPERTYBAGHANDLE hpropbag);
SPXAPI property_bag_set_string(SPXPROPERTYBAGHANDLE hpropbag, int id, const char* name, const char* value);
SPXAPI__(const char*) property_bag_get_string(SPXPROPERTYBAGHANDLE hpropbag, int id, const char* name, const char* defaultValue);
SPXAPI property_bag_free_string(const char* value);
SPXAPI property_bag_release(SPXPROPERTYBAGHANDLE hpropbag);
SPXAPI property_bag_copy(SPXPROPERTYBAGHANDLE hfrom, SPXPROPERTYBAGHANDLE hto);
// NOTE: Currently this enum is duplicated with C++ side,
// because SWIG cannot properly resolve conditional compilation.
#ifndef __cplusplus
enum PropertyId
{
SpeechServiceConnection_Key = 1000,
SpeechServiceConnection_Endpoint = 1001,
SpeechServiceConnection_Region = 1002,
SpeechServiceAuthorization_Token = 1003,
SpeechServiceAuthorization_Type = 1004,
SpeechServiceConnection_EndpointId = 1005,
SpeechServiceConnection_Host = 1006,
SpeechServiceConnection_ProxyHostName = 1100,
SpeechServiceConnection_ProxyPort = 1101,
SpeechServiceConnection_ProxyUserName = 1102,
SpeechServiceConnection_ProxyPassword = 1103,
SpeechServiceConnection_Url = 1104,
SpeechServiceConnection_ProxyHostBypass = 1105,
SpeechServiceConnection_TranslationToLanguages = 2000,
SpeechServiceConnection_TranslationVoice = 2001,
SpeechServiceConnection_TranslationFeatures = 2002,
SpeechServiceConnection_IntentRegion = 2003,
SpeechServiceConnection_RecoMode = 3000,
SpeechServiceConnection_RecoLanguage = 3001,
Speech_SessionId = 3002,
SpeechServiceConnection_UserDefinedQueryParameters = 3003,
SpeechServiceConnection_RecoModelBackend = 3004,
SpeechServiceConnection_RecoModelName = 3005,
SpeechServiceConnection_RecoModelKey = 3006,
SpeechServiceConnection_RecoModelIniFile = 3007,
SpeechServiceConnection_SynthLanguage = 3100,
SpeechServiceConnection_SynthVoice = 3101,
SpeechServiceConnection_SynthOutputFormat = 3102,
SpeechServiceConnection_SynthEnableCompressedAudioTransmission = 3103,
SpeechServiceConnection_SynthBackend = 3110,
SpeechServiceConnection_SynthOfflineDataPath = 3112,
SpeechServiceConnection_SynthOfflineVoice = 3113,
SpeechServiceConnection_SynthModelKey = 3114,
SpeechServiceConnection_VoicesListEndpoint = 3130,
SpeechServiceConnection_InitialSilenceTimeoutMs = 3200,
SpeechServiceConnection_EndSilenceTimeoutMs = 3201,
SpeechServiceConnection_EnableAudioLogging = 3202,
SpeechServiceConnection_LanguageIdMode = 3205,
SpeechServiceConnection_TranslationCategoryId = 3206,
SpeechServiceConnection_AutoDetectSourceLanguages = 3300,
SpeechServiceConnection_AutoDetectSourceLanguageResult = 3301,
SpeechServiceResponse_RequestDetailedResultTrueFalse = 4000,
SpeechServiceResponse_RequestProfanityFilterTrueFalse = 4001,
SpeechServiceResponse_ProfanityOption = 4002,
SpeechServiceResponse_PostProcessingOption = 4003,
SpeechServiceResponse_RequestWordLevelTimestamps = 4004,
SpeechServiceResponse_StablePartialResultThreshold = 4005,
SpeechServiceResponse_OutputFormatOption = 4006,
SpeechServiceResponse_RequestSnr = 4007,
SpeechServiceResponse_TranslationRequestStablePartialResult = 4100,
SpeechServiceResponse_RequestWordBoundary = 4200,
SpeechServiceResponse_RequestPunctuationBoundary = 4201,
SpeechServiceResponse_RequestSentenceBoundary = 4202,
SpeechServiceResponse_SynthesisEventsSyncToAudio = 4210,
SpeechServiceResponse_JsonResult = 5000,
SpeechServiceResponse_JsonErrorDetails = 5001,
SpeechServiceResponse_RecognitionLatencyMs = 5002,
SpeechServiceResponse_RecognitionBackend = 5003,
SpeechServiceResponse_SynthesisFirstByteLatencyMs = 5010,
SpeechServiceResponse_SynthesisFinishLatencyMs = 5011,
SpeechServiceResponse_SynthesisUnderrunTimeMs = 5012,
SpeechServiceResponse_SynthesisConnectionLatencyMs = 5013,
SpeechServiceResponse_SynthesisNetworkLatencyMs = 5014,
SpeechServiceResponse_SynthesisServiceLatencyMs = 5015,
SpeechServiceResponse_DiarizeIntermediateResults = 5025,
CancellationDetails_Reason = 6000,
CancellationDetails_ReasonText = 6001,
CancellationDetails_ReasonDetailedText = 6002,
LanguageUnderstandingServiceResponse_JsonResult = 7000,
AudioConfig_DeviceNameForCapture = 8000,
AudioConfig_NumberOfChannelsForCapture = 8001,
AudioConfig_SampleRateForCapture = 8002,
AudioConfig_BitsPerSampleForCapture = 8003,
AudioConfig_AudioSource = 8004,
AudioConfig_DeviceNameForRender = 8005,
AudioConfig_PlaybackBufferLengthInMs = 8006,
Speech_LogFilename = 9001,
Speech_SegmentationSilenceTimeoutMs = 9002,
Speech_SegmentationMaximumTimeMs = 9003,
Speech_SegmentationMaximumTimeMs = 9004,
Conversation_ApplicationId = 10000,
Conversation_DialogType = 10001,
Conversation_Initial_Silence_Timeout = 10002,
Conversation_From_Id = 10003,
Conversation_Conversation_Id = 10004,
Conversation_Custom_Voice_Deployment_Ids = 10005,
Conversation_Speech_Activity_Template = 10006,
Conversation_ParticipantId = 10007,
DataBuffer_TimeStamp = 11001,
DataBuffer_UserId = 11002,
PronunciationAssessment_ReferenceText = 12001,
PronunciationAssessment_GradingSystem = 12002,
PronunciationAssessment_Granularity = 12003,
PronunciationAssessment_EnableMiscue = 12005,
PronunciationAssessment_PhonemeAlphabet = 12006,
PronunciationAssessment_NBestPhonemeCount = 12007,
PronunciationAssessment_EnableProsodyAssessment = 12008,
PronunciationAssessment_Json = 12009,
PronunciationAssessment_Params = 12010,
PronunciationAssessment_ContentTopic = 12020,
SpeakerRecognition_Api_Version = 13001,
SpeechTranslation_ModelName = 13100,
SpeechTranslation_ModelKey = 13101,
KeywordRecognition_ModelName = 13200,
KeywordRecognition_ModelKey = 13201,
EmbeddedSpeech_EnablePerformanceMetrics = 13300
};
typedef enum _ParticipantChangedReason
{
JoinedConversation,
LeftConversation,
Updated
} ParticipantChangedReason;
#endif

66
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_recognizer.h

@ -0,0 +1,66 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_recognizer.h: Public API declarations for Recognizer related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI_(bool) recognizer_handle_is_valid(SPXRECOHANDLE hreco);
SPXAPI recognizer_handle_release(SPXRECOHANDLE hreco);
SPXAPI_(bool) recognizer_async_handle_is_valid(SPXASYNCHANDLE hasync);
SPXAPI recognizer_async_handle_release(SPXASYNCHANDLE hasync);
SPXAPI_(bool) recognizer_result_handle_is_valid(SPXRESULTHANDLE hresult);
SPXAPI recognizer_result_handle_release(SPXRESULTHANDLE hresult);
SPXAPI_(bool) recognizer_event_handle_is_valid(SPXEVENTHANDLE hevent);
SPXAPI recognizer_event_handle_release(SPXEVENTHANDLE hevent);
SPXAPI recognizer_get_property_bag(SPXRECOHANDLE hreco, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI recognizer_recognize_once(SPXRECOHANDLE hreco, SPXRESULTHANDLE* phresult);
SPXAPI recognizer_recognize_once_async(SPXRECOHANDLE hreco, SPXASYNCHANDLE* phasync);
SPXAPI recognizer_recognize_text_once_async(SPXRECOHANDLE hreco, const char* text, SPXASYNCHANDLE* phasync);
SPXAPI recognizer_recognize_once_async_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds, SPXRESULTHANDLE* phresult);
SPXAPI recognizer_start_continuous_recognition(SPXRECOHANDLE hreco);
SPXAPI recognizer_start_continuous_recognition_async(SPXRECOHANDLE hreco, SPXASYNCHANDLE* phasync);
SPXAPI recognizer_start_continuous_recognition_async_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds);
SPXAPI recognizer_stop_continuous_recognition(SPXRECOHANDLE hreco);
SPXAPI recognizer_stop_continuous_recognition_async(SPXRECOHANDLE hreco, SPXASYNCHANDLE* phasync);
SPXAPI recognizer_stop_continuous_recognition_async_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds);
SPXAPI recognizer_start_keyword_recognition(SPXRECOHANDLE hreco, SPXKEYWORDHANDLE hkeyword);
SPXAPI recognizer_start_keyword_recognition_async(SPXRECOHANDLE hreco, SPXKEYWORDHANDLE hkeyword, SPXASYNCHANDLE* phasync);
SPXAPI recognizer_start_keyword_recognition_async_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds);
SPXAPI recognizer_recognize_keyword_once(SPXRECOHANDLE hreco, SPXKEYWORDHANDLE hkeyword, SPXRESULTHANDLE* phresult);
SPXAPI recognizer_recognize_keyword_once_async(SPXRECOHANDLE hreco, SPXKEYWORDHANDLE hkeyword, SPXASYNCHANDLE* phasync);
SPXAPI recognizer_recognize_keyword_once_async_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds, SPXRESULTHANDLE* phresult);
SPXAPI recognizer_stop_keyword_recognition(SPXRECOHANDLE hreco);
SPXAPI recognizer_stop_keyword_recognition_async(SPXRECOHANDLE hreco, SPXASYNCHANDLE* phasync);
SPXAPI recognizer_stop_keyword_recognition_async_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds);
typedef void (*PSESSION_CALLBACK_FUNC)(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext);
SPXAPI recognizer_session_started_set_callback(SPXRECOHANDLE hreco, PSESSION_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI recognizer_session_stopped_set_callback(SPXRECOHANDLE hreco, PSESSION_CALLBACK_FUNC pCallback, void* pvContext);
typedef void (*PRECOGNITION_CALLBACK_FUNC)(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext);
SPXAPI recognizer_recognizing_set_callback(SPXRECOHANDLE hreco, PRECOGNITION_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI recognizer_recognized_set_callback(SPXRECOHANDLE hreco, PRECOGNITION_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI recognizer_canceled_set_callback(SPXRECOHANDLE hreco, PRECOGNITION_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI recognizer_speech_start_detected_set_callback(SPXRECOHANDLE hreco, PRECOGNITION_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI recognizer_speech_end_detected_set_callback(SPXRECOHANDLE hreco, PRECOGNITION_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI recognizer_session_event_get_session_id(SPXEVENTHANDLE hevent, char* pszSessionId, uint32_t cchSessionId);
SPXAPI recognizer_recognition_event_get_offset(SPXEVENTHANDLE hevent, uint64_t *pszOffset);
SPXAPI recognizer_recognition_event_get_result(SPXEVENTHANDLE hevent, SPXRESULTHANDLE* phresult);
SPXAPI recognizer_connection_event_get_property_bag(SPXEVENTHANDLE hevent, SPXPROPERTYBAGHANDLE* hpropbag);

108
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_result.h

@ -0,0 +1,108 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_result.h: Public API declarations for Result related C methods and enumerations
//
#pragma once
#include <speechapi_c_common.h>
enum Result_Reason
{
ResultReason_NoMatch = 0,
ResultReason_Canceled = 1,
ResultReason_RecognizingSpeech = 2,
ResultReason_RecognizedSpeech = 3,
ResultReason_RecognizingIntent = 4,
ResultReason_RecognizedIntent = 5,
ResultReason_TranslatingSpeech = 6,
ResultReason_TranslatedSpeech = 7,
ResultReason_SynthesizingAudio = 8,
ResultReason_SynthesizingAudioComplete = 9,
ResultReason_RecognizingKeyword = 10,
ResultReason_RecognizedKeyword = 11,
ResultReason_SynthesizingAudioStart = 12
};
typedef enum Result_Reason Result_Reason;
enum Result_CancellationReason
{
CancellationReason_Error = 1,
CancellationReason_EndOfStream = 2,
CancellationReason_UserCancelled = 3,
};
typedef enum Result_CancellationReason Result_CancellationReason;
enum Result_CancellationErrorCode
{
CancellationErrorCode_NoError = 0,
CancellationErrorCode_AuthenticationFailure = 1,
CancellationErrorCode_BadRequest = 2,
CancellationErrorCode_TooManyRequests = 3,
CancellationErrorCode_Forbidden = 4,
CancellationErrorCode_ConnectionFailure = 5,
CancellationErrorCode_ServiceTimeout = 6,
CancellationErrorCode_ServiceError = 7,
CancellationErrorCode_ServiceUnavailable = 8,
CancellationErrorCode_RuntimeError = 9
};
typedef enum Result_CancellationErrorCode Result_CancellationErrorCode;
enum Result_NoMatchReason
{
NoMatchReason_NotRecognized = 1,
NoMatchReason_InitialSilenceTimeout = 2,
NoMatchReason_InitialBabbleTimeout = 3,
NoMatchReason_KeywordNotRecognized = 4,
NoMatchReason_EndSilenceTimeout = 5
};
typedef enum Result_NoMatchReason Result_NoMatchReason;
enum Synthesis_VoiceType
{
SynthesisVoiceType_OnlineNeural = 1,
SynthesisVoiceType_OnlineStandard = 2,
SynthesisVoiceType_OfflineNeural = 3,
SynthesisVoiceType_OfflineStandard = 4
};
typedef enum Synthesis_VoiceType Synthesis_VoiceType;
SPXAPI result_get_reason(SPXRESULTHANDLE hresult, Result_Reason* reason);
SPXAPI result_get_reason_canceled(SPXRESULTHANDLE hresult, Result_CancellationReason* reason);
SPXAPI result_get_canceled_error_code(SPXRESULTHANDLE hresult, Result_CancellationErrorCode* errorCode);
SPXAPI result_get_no_match_reason(SPXRESULTHANDLE hresult, Result_NoMatchReason* reason);
SPXAPI result_get_result_id(SPXRESULTHANDLE hresult, char* pszResultId, uint32_t cchResultId);
SPXAPI result_get_text(SPXRESULTHANDLE hresult, char* pszText, uint32_t cchText);
SPXAPI result_get_offset(SPXRESULTHANDLE hresult, uint64_t* offset);
SPXAPI result_get_duration(SPXRESULTHANDLE hresult, uint64_t* duration);
SPXAPI result_get_property_bag(SPXRESULTHANDLE hresult, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI synth_result_get_result_id(SPXRESULTHANDLE hresult, char* resultId, uint32_t resultIdLength);
SPXAPI synth_result_get_reason(SPXRESULTHANDLE hresult, Result_Reason* reason);
SPXAPI synth_result_get_reason_canceled(SPXRESULTHANDLE hresult, Result_CancellationReason* reason);
SPXAPI synth_result_get_canceled_error_code(SPXRESULTHANDLE hresult, Result_CancellationErrorCode* errorCode);
SPXAPI synth_result_get_audio_data(SPXRESULTHANDLE hresult, uint8_t* buffer, uint32_t bufferSize, uint32_t* filledSize);
SPXAPI synth_result_get_audio_length_duration(SPXRESULTHANDLE hresult, uint32_t* audioLength, uint64_t* audioDuration);
SPXAPI synth_result_get_audio_format(SPXRESULTHANDLE hresult, SPXAUDIOSTREAMFORMATHANDLE* hformat);
SPXAPI synth_result_get_property_bag(SPXRESULTHANDLE hresult, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI synthesis_voices_result_get_result_id(SPXRESULTHANDLE hresult, char* resultId, uint32_t resultIdLength);
SPXAPI synthesis_voices_result_get_reason(SPXRESULTHANDLE hresult, Result_Reason* reason);
SPXAPI synthesis_voices_result_get_voice_num(SPXRESULTHANDLE hresult, uint32_t* voiceNum);
SPXAPI synthesis_voices_result_get_voice_info(SPXRESULTHANDLE hresult, uint32_t index, SPXRESULTHANDLE* hVoiceInfo);
SPXAPI synthesis_voices_result_get_property_bag(SPXRESULTHANDLE hresult, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI voice_info_handle_release(SPXRESULTHANDLE hVoiceInfo);
SPXAPI__(const char*) voice_info_get_name(SPXRESULTHANDLE hVoiceInfo);
SPXAPI__(const char*) voice_info_get_locale(SPXRESULTHANDLE hVoiceInfo);
SPXAPI__(const char*) voice_info_get_short_name(SPXRESULTHANDLE hVoiceInfo);
SPXAPI__(const char*) voice_info_get_local_name(SPXRESULTHANDLE hVoiceInfo);
SPXAPI__(const char*) voice_info_get_style_list(SPXRESULTHANDLE hVoiceInfo);
SPXAPI__(const char*) voice_info_get_voice_path(SPXRESULTHANDLE hVoiceInfo);
SPXAPI voice_info_get_voice_type(SPXRESULTHANDLE hVoiceInfo, Synthesis_VoiceType* voiceType);
SPXAPI voice_info_get_property_bag(SPXRESULTHANDLE hVoiceInfo, SPXPROPERTYBAGHANDLE* hpropbag);

16
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_session.h

@ -0,0 +1,16 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_session.h: Public API declarations for Session related C methods
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI session_from_recognizer(SPXRECOHANDLE hreco, SPXSESSIONHANDLE* phsession);
SPXAPI_(bool) session_handle_is_valid(SPXSESSIONHANDLE hsession);
SPXAPI session_handle_release(SPXSESSIONHANDLE hsession);
SPXAPI session_get_property_bag(SPXSESSIONHANDLE hsession, SPXPROPERTYBAGHANDLE* hpropbag);

13
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_source_lang_config.h

@ -0,0 +1,13 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI source_lang_config_from_language(SPXSOURCELANGCONFIGHANDLE* hconfig, const char* language);
SPXAPI source_lang_config_from_language_and_endpointId(SPXSOURCELANGCONFIGHANDLE* hconfig, const char* language, const char* endpointId);
SPXAPI_(bool) source_lang_config_is_handle_valid(SPXSOURCELANGCONFIGHANDLE hconfig);
SPXAPI source_lang_config_release(SPXSOURCELANGCONFIGHANDLE hconfig);
SPXAPI source_lang_config_get_property_bag(SPXSOURCELANGCONFIGHANDLE hconfig, SPXPROPERTYBAGHANDLE* hpropbag);

37
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speaker_recognition.h

@ -0,0 +1,37 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_speaker_recogntion.h: c API declarations for speaker recognition.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI create_voice_profile_client_from_config(SPXVOICEPROFILECLIENTHANDLE* phclient, SPXSPEECHCONFIGHANDLE hSpeechConfig);
SPXAPI voice_profile_client_release_handle(SPXVOICEPROFILECLIENTHANDLE hVoiceClient);
SPXAPI create_voice_profile(SPXVOICEPROFILECLIENTHANDLE hVoiceProfileClient, int id, const char* locale, SPXVOICEPROFILEHANDLE* pProfileHandle);
SPXAPI enroll_voice_profile(SPXVOICEPROFILECLIENTHANDLE hVoiceProfileClient, SPXVOICEPROFILEHANDLE hProfileHandle, SPXAUDIOCONFIGHANDLE hAudioInput, SPXRESULTHANDLE* phresult);
SPXAPI voice_profile_client_get_property_bag(SPXVOICEPROFILECLIENTHANDLE hVoiceProfileClient, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI create_voice_profile_from_id_and_type(SPXVOICEPROFILEHANDLE* phVoiceProfile, const char* id, int type);
SPXAPI voice_profile_get_id(SPXVOICEPROFILEHANDLE hVoiceProfile, char* psz, uint32_t* pcch);
SPXAPI voice_profile_get_type(SPXVOICEPROFILEHANDLE hVoiceProfile, int* ptype);
SPXAPI voice_profile_release_handle(SPXVOICEPROFILEHANDLE hVoiceProfile);
SPXAPI voice_profile_get_property_bag(SPXVOICEPROFILEHANDLE voiceprofilehandle, SPXPROPERTYBAGHANDLE* pProperties);
SPXAPI delete_voice_profile(SPXVOICEPROFILECLIENTHANDLE hclient, SPXVOICEPROFILEHANDLE hProfileHandle, SPXRESULTHANDLE* phresult);
SPXAPI reset_voice_profile(SPXVOICEPROFILECLIENTHANDLE hVoiceProfileClient, SPXVOICEPROFILEHANDLE hProfileHandle, SPXRESULTHANDLE* phresult);
SPXAPI get_profiles_json(SPXVOICEPROFILECLIENTHANDLE hVoiceProfileClient, int type, char** ppsz, size_t* pcch);
SPXAPI retrieve_enrollment_result(SPXVOICEPROFILECLIENTHANDLE hVoiceProfileClient, const char* pId, int type, SPXVOICEPROFILEHANDLE* phVoiceProfile);
SPXAPI get_activation_phrases(SPXVOICEPROFILECLIENTHANDLE hVoiceProfileClient, const char* pLocale, int type, SPXRESULTHANDLE* phresult);
SPXAPI recognizer_create_speaker_recognizer_from_config(SPXSPEAKERIDHANDLE* phspeakerid, SPXSPEECHCONFIGHANDLE hspeechconfig, SPXAUDIOCONFIGHANDLE haudioInput);
SPXAPI speaker_recognizer_release_handle(SPXSPEAKERIDHANDLE phspeakerid);
SPXAPI speaker_recognizer_get_property_bag(SPXSPEAKERIDHANDLE phspeakerid, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI speaker_identification_model_create(SPXSIMODELHANDLE* psimodel);
SPXAPI speaker_identification_model_add_profile(SPXSIMODELHANDLE hsimodel, SPXVOICEPROFILEHANDLE hprofile);
SPXAPI speaker_identification_model_release_handle(SPXSIMODELHANDLE hmodel);
SPXAPI speaker_recognizer_identify(SPXSPEAKERIDHANDLE phspeakerid, SPXSIMODELHANDLE hsimodel, SPXRESULTHANDLE* phresult);
SPXAPI speaker_recognizer_verify(SPXSPEAKERIDHANDLE phspeakerid, SPXSVMODELHANDLE hsvmodel, SPXRESULTHANDLE* phresult);
SPXAPI speaker_verification_model_create(SPXSVMODELHANDLE* psvmodel, SPXVOICEPROFILEHANDLE hprofile);
SPXAPI speaker_verification_model_release_handle(SPXSVMODELHANDLE hsvmodel);

171
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speech_config.h

@ -0,0 +1,171 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
typedef enum { SpeechOutputFormat_Simple = 0, SpeechOutputFormat_Detailed = 1 } SpeechOutputFormat;
typedef enum
{
// raw-8khz-8bit-mono-mulaw
SpeechSynthesisOutputFormat_Raw8Khz8BitMonoMULaw = 1,
// riff-16khz-16kbps-mono-siren
// Unsupported by the service. Do not use this value.
SpeechSynthesisOutputFormat_Riff16Khz16KbpsMonoSiren = 2,
// audio-16khz-16kbps-mono-siren
// Unsupported by the service. Do not use this value.
SpeechSynthesisOutputFormat_Audio16Khz16KbpsMonoSiren = 3,
// audio-16khz-32kbitrate-mono-mp3
SpeechSynthesisOutputFormat_Audio16Khz32KBitRateMonoMp3 = 4,
// audio-16khz-128kbitrate-mono-mp3
SpeechSynthesisOutputFormat_Audio16Khz128KBitRateMonoMp3 = 5,
// audio-16khz-64kbitrate-mono-mp3
SpeechSynthesisOutputFormat_Audio16Khz64KBitRateMonoMp3 = 6,
// audio-24khz-48kbitrate-mono-mp3
SpeechSynthesisOutputFormat_Audio24Khz48KBitRateMonoMp3 = 7,
// audio-24khz-96kbitrate-mono-mp3
SpeechSynthesisOutputFormat_Audio24Khz96KBitRateMonoMp3 = 8,
// audio-24khz-160kbitrate-mono-mp3
SpeechSynthesisOutputFormat_Audio24Khz160KBitRateMonoMp3 = 9,
// raw-16khz-16bit-mono-truesilk
SpeechSynthesisOutputFormat_Raw16Khz16BitMonoTrueSilk = 10,
// riff-16khz-16bit-mono-pcm
SpeechSynthesisOutputFormat_Riff16Khz16BitMonoPcm = 11,
// riff-8khz-16bit-mono-pcm
SpeechSynthesisOutputFormat_Riff8Khz16BitMonoPcm = 12,
// riff-24khz-16bit-mono-pcm
SpeechSynthesisOutputFormat_Riff24Khz16BitMonoPcm = 13,
// riff-8khz-8bit-mono-mulaw
SpeechSynthesisOutputFormat_Riff8Khz8BitMonoMULaw = 14,
// raw-16khz-16bit-mono-pcm
SpeechSynthesisOutputFormat_Raw16Khz16BitMonoPcm = 15,
// raw-24khz-16bit-mono-pcm
SpeechSynthesisOutputFormat_Raw24Khz16BitMonoPcm = 16,
// raw-8khz-16bit-mono-pcm
SpeechSynthesisOutputFormat_Raw8Khz16BitMonoPcm = 17,
// ogg-16khz-16bit-mono-opus
SpeechSynthesisOutputFormat_Ogg16khz16BitMonoOpus = 18,
// ogg-24khz-24bit-mono-opus
SpeechSynthesisOutputFormat_Ogg24Khz16BitMonoOpus = 19,
// raw-48khz-16bit-mono-pcm
SpeechSynthesisOutputFormat_Raw48Khz16BitMonoPcm = 20,
// riff-48khz-16bit-mono-pcm
SpeechSynthesisOutputFormat_Riff48Khz16BitMonoPcm = 21,
// audio-48khz-96kbitrate-mono-mp3
SpeechSynthesisOutputFormat_Audio48Khz96KBitRateMonoMp3 = 22,
// audio-48khz-192kbitrate-mono-mp3
SpeechSynthesisOutputFormat_Audio48Khz192KBitRateMonoMp3 = 23,
// ogg-48khz-16bit-mono-opus
SpeechSynthesisOutputFormat_Ogg48Khz16BitMonoOpus = 24,
// webm-16khz-16bit-mono-opus
SpeechSynthesisOutputFormat_Webm16Khz16BitMonoOpus = 25,
// webm-24khz-16bit-mono-opus
SpeechSynthesisOutputFormat_Webm24Khz16BitMonoOpus = 26,
// raw-24khz-16bit-mono-truesilk
SpeechSynthesisOutputFormat_Raw24Khz16BitMonoTrueSilk = 27,
// raw-8khz-8bit-mono-alaw
SpeechSynthesisOutputFormat_Raw8Khz8BitMonoALaw = 28,
// riff-8khz-8bit-mono-alaw
SpeechSynthesisOutputFormat_Riff8Khz8BitMonoALaw = 29,
// webm-24khz-16bit-24kbps-mono-opus
// Audio compressed by OPUS codec in a WebM container, with bitrate of 24kbps, optimized for IoT scenario.
SpeechSynthesisOutputFormat_Webm24Khz16Bit24KbpsMonoOpus = 30,
// audio-16khz-16bit-32kbps-mono-opus
// Audio compressed by OPUS codec without container, with bitrate of 32kbps.
SpeechSynthesisOutputFormat_Audio16Khz16Bit32KbpsMonoOpus = 31,
// audio-24khz-48bit-mono-opus
// Audio compressed by OPUS codec without container, with bitrate of 48kbps.
SpeechSynthesisOutputFormat_Audio24Khz16Bit48KbpsMonoOpus = 32,
// audio-24khz-24bit-mono-opus
// Audio compressed by OPUS codec without container, with bitrate of 24kbps.
SpeechSynthesisOutputFormat_Audio24Khz16Bit24KbpsMonoOpus = 33,
// raw-22050hz-16bit-mono-pcm
// Raw PCM audio at 22050Hz sampling rate and 16-bit depth.
SpeechSynthesisOutputFormat_Raw22050Hz16BitMonoPcm = 34,
// riff-22050hz-16bit-mono-pcm
// PCM audio at 22050Hz sampling rate and 16-bit depth, with RIFF header.
SpeechSynthesisOutputFormat_Riff22050Hz16BitMonoPcm = 35,
// raw-44100hz-16bit-mono-pcm
// Raw PCM audio at 44100Hz sampling rate and 16-bit depth.
SpeechSynthesisOutputFormat_Raw44100Hz16BitMonoPcm = 36,
// riff-44100hz-16bit-mono-pcm
// PCM audio at 44100Hz sampling rate and 16-bit depth, with RIFF header.
SpeechSynthesisOutputFormat_Riff44100Hz16BitMonoPcm = 37,
/// amr-wb-16000hz
/// AMR-WB audio at 16kHz sampling rate.
/// (Added in 1.24.0)
SpeechSynthesisOutputFormat_AmrWb16000Hz = 38,
/// g722-16khz-64kbps
/// G.722 audio at 16kHz sampling rate and 64kbps bitrate.
/// (Added in 1.38.0)
SpeechSynthesisOutputFormat_G72216Khz64Kbps = 39,
} Speech_Synthesis_Output_Format;
typedef enum
{
// Using URI query parameter to pass property settings to service.
SpeechConfig_ServicePropertyChannel_UriQueryParameter = 0,
// Using HttpHeader to set a key/value in a HTTP header.
SpeechConfig_ServicePropertyChannel_HttpHeader = 1
} SpeechConfig_ServicePropertyChannel;
typedef enum
{
SpeechConfig_ProfanityMasked = 0,
SpeechConfig_ProfanityRemoved = 1,
SpeechConfig_ProfanityRaw = 2
} SpeechConfig_ProfanityOption;
SPXAPI_(bool) speech_config_is_handle_valid(SPXSPEECHCONFIGHANDLE hconfig);
SPXAPI speech_config_from_subscription(SPXSPEECHCONFIGHANDLE* hconfig, const char* subscription, const char* region);
SPXAPI speech_config_from_authorization_token(SPXSPEECHCONFIGHANDLE* hconfig, const char* authToken, const char* region);
SPXAPI speech_config_from_endpoint(SPXSPEECHCONFIGHANDLE * hconfig, const char* endpoint, const char* subscription);
SPXAPI speech_config_from_host(SPXSPEECHCONFIGHANDLE* hconfig, const char* host, const char* subscription);
SPXAPI speech_config_release(SPXSPEECHCONFIGHANDLE hconfig);
SPXAPI speech_config_get_property_bag(SPXSPEECHCONFIGHANDLE hconfig, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI speech_config_set_audio_output_format(SPXSPEECHCONFIGHANDLE hconfig, Speech_Synthesis_Output_Format formatId);
SPXAPI speech_config_set_service_property(SPXSPEECHCONFIGHANDLE configHandle, const char* propertyName, const char* propertyValue, SpeechConfig_ServicePropertyChannel channel);
SPXAPI speech_config_set_profanity(SPXSPEECHCONFIGHANDLE configHandle, SpeechConfig_ProfanityOption profanity);

13
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speech_recognition_model.h

@ -0,0 +1,13 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI speech_recognition_model_handle_release(SPXSPEECHRECOMODELHANDLE hmodel);
SPXAPI__(const char*) speech_recognition_model_get_name(SPXSPEECHRECOMODELHANDLE hmodel);
SPXAPI__(const char*) speech_recognition_model_get_locales(SPXSPEECHRECOMODELHANDLE hmodel);
SPXAPI__(const char*) speech_recognition_model_get_path(SPXSPEECHRECOMODELHANDLE hmodel);
SPXAPI__(const char*) speech_recognition_model_get_version(SPXSPEECHRECOMODELHANDLE hmodel);

16
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speech_translation_config.h

@ -0,0 +1,16 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI speech_translation_config_from_subscription(SPXSPEECHCONFIGHANDLE* configHandle, const char* subscription, const char* region);
SPXAPI speech_translation_config_from_authorization_token(SPXSPEECHCONFIGHANDLE* configHandle, const char* authToken, const char* region);
SPXAPI speech_translation_config_from_endpoint(SPXSPEECHCONFIGHANDLE* configHandle, const char* endpoint, const char* subscription);
SPXAPI speech_translation_config_from_host(SPXSPEECHCONFIGHANDLE* configHandle, const char* host, const char* subscription);
SPXAPI speech_translation_config_add_target_language(SPXSPEECHCONFIGHANDLE configHandle, const char* language);
SPXAPI speech_translation_config_remove_target_language(SPXSPEECHCONFIGHANDLE configHandle, const char* language);
SPXAPI speech_translation_config_set_custom_model_category_id(SPXSPEECHCONFIGHANDLE configHandle, const char* categoryId);

14
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_speech_translation_model.h

@ -0,0 +1,14 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI speech_translation_model_handle_release(SPXSPEECHRECOMODELHANDLE hmodel);
SPXAPI__(const char*) speech_translation_model_get_name(SPXSPEECHRECOMODELHANDLE hmodel);
SPXAPI__(const char*) speech_translation_model_get_source_languages(SPXSPEECHRECOMODELHANDLE hmodel);
SPXAPI__(const char*) speech_translation_model_get_target_languages(SPXSPEECHRECOMODELHANDLE hmodel);
SPXAPI__(const char*) speech_translation_model_get_path(SPXSPEECHRECOMODELHANDLE hmodel);
SPXAPI__(const char*) speech_translation_model_get_version(SPXSPEECHRECOMODELHANDLE hmodel);

17
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_synthesis_request.h

@ -0,0 +1,17 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI speech_synthesis_request_create(bool textStreamingEnabled, bool isSSML, const char* inputText, uint32_t textLength, SPXREQUESTHANDLE* hrequest);
SPXAPI speech_synthesis_request_set_voice(SPXREQUESTHANDLE hrequest, const char* voice, const char* personalVoice, const char* modelName);
SPXAPI speech_synthesis_request_send_text_piece(SPXREQUESTHANDLE hrequest, const char* text, uint32_t textLength);
SPXAPI speech_synthesis_request_finish(SPXREQUESTHANDLE hrequest);
SPXAPI speech_synthesis_request_handle_is_valid(SPXREQUESTHANDLE hrequest);
SPXAPI speech_synthesis_request_release(SPXREQUESTHANDLE hrequest);
SPXAPI speech_synthesis_request_get_property_bag(SPXREQUESTHANDLE hrequest, SPXPROPERTYBAGHANDLE* hpropbag);

74
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_synthesizer.h

@ -0,0 +1,74 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_synthesizer.h: Public API declarations for Synthesizer related C methods and typedefs
//
#pragma once
#include <speechapi_c_common.h>
#include <speechapi_c_connection.h>
#include <speechapi_c_synthesis_request.h>
enum SpeechSynthesis_BoundaryType
{
SpeechSynthesis_BoundaryType_Word = 0,
SpeechSynthesis_BoundaryType_Punctuation = 1,
SpeechSynthesis_BoundaryType_Sentence = 2
};
typedef enum SpeechSynthesis_BoundaryType SpeechSynthesis_BoundaryType;
SPXAPI_(bool) synthesizer_handle_is_valid(SPXSYNTHHANDLE hsynth);
SPXAPI synthesizer_handle_release(SPXSYNTHHANDLE hsynth);
SPXAPI_(bool) synthesizer_async_handle_is_valid(SPXASYNCHANDLE hasync);
SPXAPI synthesizer_async_handle_release(SPXASYNCHANDLE hasync);
SPXAPI_(bool) synthesizer_result_handle_is_valid(SPXRESULTHANDLE hresult);
SPXAPI synthesizer_result_handle_release(SPXRESULTHANDLE hresult);
SPXAPI_(bool) synthesizer_event_handle_is_valid(SPXEVENTHANDLE hevent);
SPXAPI synthesizer_event_handle_release(SPXEVENTHANDLE hevent);
SPXAPI synthesizer_get_property_bag(SPXSYNTHHANDLE hsynth, SPXPROPERTYBAGHANDLE* hpropbag);
SPXAPI synthesizer_speak_text(SPXSYNTHHANDLE hsynth, const char* text, uint32_t textLength, SPXRESULTHANDLE* phresult);
SPXAPI synthesizer_speak_ssml(SPXSYNTHHANDLE hsynth, const char* ssml, uint32_t ssmlLength, SPXRESULTHANDLE* phresult);
SPXAPI synthesizer_speak_request(SPXSYNTHHANDLE hsynth, SPXREQUESTHANDLE hrequest, SPXRESULTHANDLE* phresult);
SPXAPI synthesizer_speak_text_async(SPXSYNTHHANDLE hsynth, const char* text, uint32_t textLength, SPXASYNCHANDLE* phasync);
SPXAPI synthesizer_speak_ssml_async(SPXSYNTHHANDLE hsynth, const char* ssml, uint32_t ssmlLength, SPXASYNCHANDLE* phasync);
SPXAPI synthesizer_speak_request_async(SPXSYNTHHANDLE hsynth, SPXREQUESTHANDLE hrequest, SPXASYNCHANDLE* phasync);
SPXAPI synthesizer_start_speaking_text(SPXSYNTHHANDLE hsynth, const char* text, uint32_t textLength, SPXRESULTHANDLE* phresult);
SPXAPI synthesizer_start_speaking_ssml(SPXSYNTHHANDLE hsynth, const char* ssml, uint32_t ssmlLength, SPXRESULTHANDLE* phresult);
SPXAPI synthesizer_start_speaking_request(SPXSYNTHHANDLE hsynth, SPXREQUESTHANDLE hrequest, SPXRESULTHANDLE* phresult);
SPXAPI synthesizer_start_speaking_text_async(SPXSYNTHHANDLE hsynth, const char* text, uint32_t textLength, SPXASYNCHANDLE* phasync);
SPXAPI synthesizer_start_speaking_ssml_async(SPXSYNTHHANDLE hsynth, const char* ssml, uint32_t ssmlLength, SPXASYNCHANDLE* phasync);
SPXAPI synthesizer_speak_async_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds, SPXRESULTHANDLE* phresult);
SPXAPI synthesizer_stop_speaking(SPXSYNTHHANDLE hsynth);
SPXAPI synthesizer_stop_speaking_async(SPXSYNTHHANDLE hsynth, SPXASYNCHANDLE* phasync);
SPXAPI synthesizer_stop_speaking_async_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds);
SPXAPI synthesizer_get_voices_list(SPXSYNTHHANDLE hsynth, const char* locale, SPXRESULTHANDLE* phresult);
SPXAPI synthesizer_get_voices_list_async(SPXSYNTHHANDLE hsynth, const char* locale, SPXASYNCHANDLE* phasync);
SPXAPI synthesizer_get_voices_list_async_wait_for(SPXASYNCHANDLE hasync, uint32_t milliseconds, SPXRESULTHANDLE* phresult);
typedef void(*PSYNTHESIS_CALLBACK_FUNC)(SPXSYNTHHANDLE hsynth, SPXEVENTHANDLE hevent, void* pvContext);
SPXAPI synthesizer_started_set_callback(SPXSYNTHHANDLE hsynth, PSYNTHESIS_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI synthesizer_synthesizing_set_callback(SPXSYNTHHANDLE hsynth, PSYNTHESIS_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI synthesizer_completed_set_callback(SPXSYNTHHANDLE hsynth, PSYNTHESIS_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI synthesizer_canceled_set_callback(SPXSYNTHHANDLE hsynth, PSYNTHESIS_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI synthesizer_word_boundary_set_callback(SPXSYNTHHANDLE hsynth, PSYNTHESIS_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI synthesizer_viseme_received_set_callback(SPXSYNTHHANDLE hsynth, PSYNTHESIS_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI synthesizer_bookmark_reached_set_callback(SPXSYNTHHANDLE hsynth, PSYNTHESIS_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI synthesizer_connection_connected_set_callback(SPXCONNECTIONHANDLE hConnection, CONNECTION_CALLBACK_FUNC pCallback, void * pvContext);
SPXAPI synthesizer_connection_disconnected_set_callback(SPXCONNECTIONHANDLE hConnection, CONNECTION_CALLBACK_FUNC pCallback, void * pvContext);
SPXAPI synthesizer_synthesis_event_get_result(SPXEVENTHANDLE hevent, SPXRESULTHANDLE* phresult);
SPXAPI synthesizer_word_boundary_event_get_values(SPXEVENTHANDLE hevent, uint64_t *pAudioOffset, uint64_t *pDuration,
uint32_t *pTextOffset, uint32_t *pWordLength, SpeechSynthesis_BoundaryType *pBoundaryType);
SPXAPI synthesizer_event_get_result_id(SPXEVENTHANDLE hEvent, char* resultId, uint32_t resultIdLength);
SPXAPI__(const char*) synthesizer_event_get_text(SPXEVENTHANDLE hEvent);
SPXAPI synthesizer_viseme_event_get_values(SPXEVENTHANDLE hevent, uint64_t* pAudioOffset, uint32_t* pVisemeId);
SPXAPI__(const char*) synthesizer_viseme_event_get_animation(SPXEVENTHANDLE hEvent);
SPXAPI synthesizer_bookmark_event_get_values(SPXEVENTHANDLE hevent, uint64_t* pAudioOffset);

17
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_translation_recognizer.h

@ -0,0 +1,17 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
// Todo: Translation recognizer management API.
typedef void(*PTRANSLATIONSYNTHESIS_CALLBACK_FUNC)(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext);
SPXAPI translator_synthesizing_audio_set_callback(SPXRECOHANDLE hreco, PTRANSLATIONSYNTHESIS_CALLBACK_FUNC pCallback, void* pvContext);
SPXAPI translator_add_target_language(SPXRECOHANDLE hreco, const char* language);
SPXAPI translator_remove_target_language(SPXRECOHANDLE hreco, const char* language);

14
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_translation_result.h

@ -0,0 +1,14 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI translation_text_result_get_translation_count(SPXRESULTHANDLE handle, size_t * size);
SPXAPI translation_text_result_get_translation(SPXRESULTHANDLE handle, size_t index, char * language, char * text, size_t * language_size, size_t * text_size);
// audioBuffer: point to the header for storing synthesis audio data. The parameter lengthPointer points to the variable saving the size of buffer. On return, *lengthPointer is set to the size of the buffer returned.
// If textBuffer is nullptr or the length is smaller than the size required, the function returns SPXERR_BUFFER_TOO_SMALL.
SPXAPI translation_synthesis_result_get_audio_data(SPXRESULTHANDLE handle, uint8_t* audioBuffer, size_t* lengthPointer);

13
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/speechapi_c_user.h

@ -0,0 +1,13 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_c_user.h: Public API declarations for user related C methods and enumerations
//
#pragma once
#include <speechapi_c_common.h>
SPXAPI user_create_from_id(const char* user_id, SPXUSERHANDLE* huser);
SPXAPI user_release_handle(SPXUSERHANDLE huser);
SPXAPI user_get_id(SPXUSERHANDLE huser, char* user_id, size_t user_id_size);

548
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/spxdebug.h

@ -0,0 +1,548 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// spxdebug.h: Public API definitions for global C Trace/Debug methods and related #defines
//
#pragma once
//-------------------------------------------------------
// Re-enabled ability to compile out all macros...
// However, currently still need to keep all macros until
// final review of all macros is complete.
//-------------------------------------------------------
#define SPX_CONFIG_TRACE_INCLUDE_DBG_WITH_ALL 1
#ifdef SPX_CONFIG_TRACE_INCLUDE_DBG_WITH_ALL
#if defined(SPX_CONFIG_TRACE_ALL) && !defined(SPX_CONFIG_DBG_TRACE_ALL) && (!defined(DEBUG) || !defined(_DEBUG))
#define SPX_CONFIG_DBG_TRACE_ALL 1
#endif
#endif
//-------------------------------------------------------
// SPX_ and AZAC_ compatibility section
// (must preceed #include <azac_debug.h>)
//-------------------------------------------------------
#if defined(SPX_CONFIG_DBG_TRACE_ALL) && !defined(AZAC_CONFIG_DBG_TRACE_ALL)
#define AZAC_CONFIG_DBG_TRACE_ALL SPX_CONFIG_DBG_TRACE_ALL
#elif !defined(SPX_CONFIG_DBG_TRACE_ALL) && defined(AZAC_CONFIG_DBG_TRACE_ALL)
#define SPX_CONFIG_DBG_TRACE_ALL AZAC_CONFIG_DBG_TRACE_ALL
#endif
#if defined(SPX_CONFIG_DBG_TRACE_VERBOSE) && !defined(AZAC_CONFIG_DBG_TRACE_VERBOSE)
#define AZAC_CONFIG_DBG_TRACE_VERBOSE SPX_CONFIG_DBG_TRACE_VERBOSE
#elif !defined(SPX_CONFIG_DBG_TRACE_VERBOSE) && defined(AZAC_CONFIG_DBG_TRACE_VERBOSE)
#define SPX_CONFIG_DBG_TRACE_VERBOSE AZAC_CONFIG_DBG_TRACE_VERBOSE
#endif
#if defined(SPX_CONFIG_DBG_TRACE_INFO) && !defined(AZAC_CONFIG_DBG_TRACE_INFO)
#define AZAC_CONFIG_DBG_TRACE_INFO SPX_CONFIG_DBG_TRACE_INFO
#elif !defined(SPX_CONFIG_DBG_TRACE_INFO) && defined(AZAC_CONFIG_DBG_TRACE_INFO)
#define SPX_CONFIG_DBG_TRACE_INFO AZAC_CONFIG_DBG_TRACE_INFO
#endif
#if defined(SPX_CONFIG_DBG_TRACE_WARNING) && !defined(AZAC_CONFIG_DBG_TRACE_WARNING)
#define AZAC_CONFIG_DBG_TRACE_WARNING SPX_CONFIG_DBG_TRACE_WARNING
#elif !defined(SPX_CONFIG_DBG_TRACE_WARNING) && defined(AZAC_CONFIG_DBG_TRACE_WARNING)
#define SPX_CONFIG_DBG_TRACE_WARNING AZAC_CONFIG_DBG_TRACE_WARNING
#endif
#if defined(SPX_CONFIG_DBG_TRACE_ERROR) && !defined(AZAC_CONFIG_DBG_TRACE_ERROR)
#define AZAC_CONFIG_DBG_TRACE_ERROR SPX_CONFIG_DBG_TRACE_ERROR
#elif !defined(SPX_CONFIG_DBG_TRACE_ERROR) && defined(AZAC_CONFIG_DBG_TRACE_ERROR)
#define SPX_CONFIG_DBG_TRACE_ERROR AZAC_CONFIG_DBG_TRACE_ERROR
#endif
#if defined(SPX_CONFIG_DBG_TRACE_FUNCTION) && !defined(AZAC_CONFIG_DBG_TRACE_FUNCTION)
#define AZAC_CONFIG_DBG_TRACE_FUNCTION SPX_CONFIG_DBG_TRACE_FUNCTION
#elif !defined(SPX_CONFIG_DBG_TRACE_FUNCTION) && defined(AZAC_CONFIG_DBG_TRACE_FUNCTION)
#define SPX_CONFIG_DBG_TRACE_FUNCTION AZAC_CONFIG_DBG_TRACE_FUNCTION
#endif
#if defined(SPX_CONFIG_DBG_TRACE_SCOPE) && !defined(AZAC_CONFIG_DBG_TRACE_SCOPE)
#define AZAC_CONFIG_DBG_TRACE_SCOPE SPX_CONFIG_DBG_TRACE_SCOPE
#elif !defined(SPX_CONFIG_DBG_TRACE_SCOPE) && defined(AZAC_CONFIG_DBG_TRACE_SCOPE)
#define SPX_CONFIG_DBG_TRACE_SCOPE AZAC_CONFIG_DBG_TRACE_SCOPE
#endif
#if defined(SPX_CONFIG_DBG_TRACE_ASSERT) && !defined(AZAC_CONFIG_DBG_TRACE_ASSERT)
#define AZAC_CONFIG_DBG_TRACE_ASSERT SPX_CONFIG_DBG_TRACE_ASSERT
#elif !defined(SPX_CONFIG_DBG_TRACE_ASSERT) && defined(AZAC_CONFIG_DBG_TRACE_ASSERT)
#define SPX_CONFIG_DBG_TRACE_ASSERT AZAC_CONFIG_DBG_TRACE_ASSERT
#endif
#if defined(SPX_CONFIG_DBG_TRACE_VERIFY) && !defined(AZAC_CONFIG_DBG_TRACE_VERIFY)
#define AZAC_CONFIG_DBG_TRACE_VERIFY SPX_CONFIG_DBG_TRACE_VERIFY
#elif !defined(SPX_CONFIG_DBG_TRACE_VERIFY) && defined(AZAC_CONFIG_DBG_TRACE_VERIFY)
#define SPX_CONFIG_DBG_TRACE_VERIFY AZAC_CONFIG_DBG_TRACE_VERIFY
#endif
#if defined(SPX_CONFIG_TRACE_ALL) && !defined(AZAC_CONFIG_TRACE_ALL)
#define AZAC_CONFIG_TRACE_ALL SPX_CONFIG_TRACE_ALL
#elif !defined(SPX_CONFIG_TRACE_ALL) && defined(AZAC_CONFIG_TRACE_ALL)
#define SPX_CONFIG_TRACE_ALL AZAC_CONFIG_TRACE_ALL
#endif
#if defined(SPX_CONFIG_TRACE_VERBOSE) && !defined(AZAC_CONFIG_TRACE_VERBOSE)
#define AZAC_CONFIG_TRACE_VERBOSE SPX_CONFIG_TRACE_VERBOSE
#elif !defined(SPX_CONFIG_TRACE_VERBOSE) && defined(AZAC_CONFIG_TRACE_VERBOSE)
#define SPX_CONFIG_TRACE_VERBOSE AZAC_CONFIG_TRACE_VERBOSE
#endif
#if defined(SPX_CONFIG_TRACE_INFO) && !defined(AZAC_CONFIG_TRACE_INFO)
#define AZAC_CONFIG_TRACE_INFO SPX_CONFIG_TRACE_INFO
#elif !defined(SPX_CONFIG_TRACE_INFO) && defined(AZAC_CONFIG_TRACE_INFO)
#define SPX_CONFIG_TRACE_INFO AZAC_CONFIG_TRACE_INFO
#endif
#if defined(SPX_CONFIG_TRACE_WARNING) && !defined(AZAC_CONFIG_TRACE_WARNING)
#define AZAC_CONFIG_TRACE_WARNING SPX_CONFIG_TRACE_WARNING
#elif !defined(SPX_CONFIG_TRACE_WARNING) && defined(AZAC_CONFIG_TRACE_WARNING)
#define SPX_CONFIG_TRACE_WARNING AZAC_CONFIG_TRACE_WARNING
#endif
#if defined(SPX_CONFIG_TRACE_ERROR) && !defined(AZAC_CONFIG_TRACE_ERROR)
#define AZAC_CONFIG_TRACE_ERROR SPX_CONFIG_TRACE_ERROR
#elif !defined(SPX_CONFIG_TRACE_ERROR) && defined(AZAC_CONFIG_TRACE_ERROR)
#define SPX_CONFIG_TRACE_ERROR AZAC_CONFIG_TRACE_ERROR
#endif
#if defined(SPX_CONFIG_TRACE_FUNCTION) && !defined(AZAC_CONFIG_TRACE_FUNCTION)
#define AZAC_CONFIG_TRACE_FUNCTION SPX_CONFIG_TRACE_FUNCTION
#elif !defined(SPX_CONFIG_TRACE_FUNCTION) && defined(AZAC_CONFIG_TRACE_FUNCTION)
#define SPX_CONFIG_TRACE_FUNCTION AZAC_CONFIG_TRACE_FUNCTION
#endif
#if defined(SPX_CONFIG_TRACE_SCOPE) && !defined(AZAC_CONFIG_TRACE_SCOPE)
#define AZAC_CONFIG_TRACE_SCOPE SPX_CONFIG_TRACE_SCOPE
#elif !defined(SPX_CONFIG_TRACE_SCOPE) && defined(AZAC_CONFIG_TRACE_SCOPE)
#define SPX_CONFIG_TRACE_SCOPE AZAC_CONFIG_TRACE_SCOPE
#endif
#if defined(SPX_CONFIG_TRACE_THROW_ON_FAIL) && !defined(AZAC_CONFIG_TRACE_THROW_ON_FAIL)
#define AZAC_CONFIG_TRACE_THROW_ON_FAIL SPX_CONFIG_TRACE_THROW_ON_FAIL
#elif !defined(SPX_CONFIG_TRACE_THROW_ON_FAIL) && defined(AZAC_CONFIG_TRACE_THROW_ON_FAIL)
#define SPX_CONFIG_TRACE_THROW_ON_FAIL AZAC_CONFIG_TRACE_THROW_ON_FAIL
#endif
#if defined(SPX_CONFIG_TRACE_REPORT_ON_FAIL) && !defined(AZAC_CONFIG_TRACE_REPORT_ON_FAIL)
#define AZAC_CONFIG_TRACE_REPORT_ON_FAIL SPX_CONFIG_TRACE_REPORT_ON_FAIL
#elif !defined(SPX_CONFIG_TRACE_REPORT_ON_FAIL) && defined(AZAC_CONFIG_TRACE_REPORT_ON_FAIL)
#define SPX_CONFIG_TRACE_REPORT_ON_FAIL AZAC_CONFIG_TRACE_REPORT_ON_FAIL
#endif
#if defined(SPX_CONFIG_TRACE_RETURN_ON_FAIL) && !defined(AZAC_CONFIG_TRACE_RETURN_ON_FAIL)
#define AZAC_CONFIG_TRACE_RETURN_ON_FAIL SPX_CONFIG_TRACE_RETURN_ON_FAIL
#elif !defined(SPX_CONFIG_TRACE_RETURN_ON_FAIL) && defined(AZAC_CONFIG_TRACE_RETURN_ON_FAIL)
#define SPX_CONFIG_TRACE_RETURN_ON_FAIL AZAC_CONFIG_TRACE_RETURN_ON_FAIL
#endif
#if defined(SPX_CONFIG_TRACE_EXITFN_ON_FAIL) && !defined(AZAC_CONFIG_TRACE_EXITFN_ON_FAIL)
#define AZAC_CONFIG_TRACE_EXITFN_ON_FAIL SPX_CONFIG_TRACE_EXITFN_ON_FAIL
#elif !defined(SPX_CONFIG_TRACE_EXITFN_ON_FAIL) && defined(AZAC_CONFIG_TRACE_EXITFN_ON_FAIL)
#define SPX_CONFIG_TRACE_EXITFN_ON_FAIL AZAC_CONFIG_TRACE_EXITFN_ON_FAIL
#endif
#if !defined(__AZAC_THROW_HR_IMPL) && defined(__SPX_THROW_HR_IMPL)
#define __AZAC_THROW_HR_IMPL __SPX_THROW_HR_IMPL
#elif !defined(__SPX_THROW_HR_IMPL) && defined(__AZAC_THROW_HR_IMPL)
#define __SPX_THROW_HR_IMPL __AZAC_THROW_HR_IMPL
#elif !defined(__AZAC_THROW_HR_IMPL) && !defined(__SPX_THROW_HR_IMPL)
#define __AZAC_THROW_HR_IMPL __azac_rethrow
#define __SPX_THROW_HR_IMPL __azac_rethrow
#else
#error Both __AZAC_THROW_HR_IMPL and __SPX_THROW_HR_IMPL cannot be defined at the same time
#endif
//-------------------------------------------------------
// SPX_ and SPX_DBG_ macro configuration
//-------------------------------------------------------
#ifdef SPX_CONFIG_DBG_TRACE_ALL
#define SPX_CONFIG_DBG_TRACE_VERBOSE 1
#define SPX_CONFIG_DBG_TRACE_INFO 1
#define SPX_CONFIG_DBG_TRACE_WARNING 1
#define SPX_CONFIG_DBG_TRACE_ERROR 1
#define SPX_CONFIG_DBG_TRACE_FUNCTION 1
#define SPX_CONFIG_DBG_TRACE_SCOPE 1
#define SPX_CONFIG_DBG_TRACE_ASSERT 1
#define SPX_CONFIG_DBG_TRACE_VERIFY 1
#ifndef SPX_CONFIG_TRACE_ALL
#define SPX_CONFIG_TRACE_ALL 1
#endif
#endif // SPX_CONFIG_DBG_TRACE_ALL
#ifdef SPX_CONFIG_TRACE_ALL
#define SPX_CONFIG_TRACE_VERBOSE 1
#define SPX_CONFIG_TRACE_INFO 1
#define SPX_CONFIG_TRACE_WARNING 1
#define SPX_CONFIG_TRACE_ERROR 1
#define SPX_CONFIG_TRACE_FUNCTION 1
#define SPX_CONFIG_TRACE_SCOPE 1
#define SPX_CONFIG_TRACE_THROW_ON_FAIL 1
#define SPX_CONFIG_TRACE_REPORT_ON_FAIL 1
#define SPX_CONFIG_TRACE_RETURN_ON_FAIL 1
#define SPX_CONFIG_TRACE_EXITFN_ON_FAIL 1
#endif // SPX_CONFIG_TRACE_ALL
//-------------------------------------------------------
// #include section ...
// (must come after everything above)
//-------------------------------------------------------
#include <azac_debug.h>
#include <inttypes.h>
#include <spxerror.h>
#ifndef _MSC_VER
// macros in this header generate a bunch of
// "ISO C++11 requires at least one argument for the "..." in a variadic macro" errors.
// system_header pragma is the only mechanism that helps to suppress them.
// https://stackoverflow.com/questions/35587137/how-to-suppress-gcc-variadic-macro-argument-warning-for-zero-arguments-for-a-par
// TODO: try to make macros standard-compliant.
#pragma GCC system_header
#endif
//-----------------------------------------------------------
// SPX_TRACE macro common implementations
//-----------------------------------------------------------
#define __SPX_TRACE_LEVEL_INFO __AZAC_TRACE_LEVEL_INFO // Trace_Info
#define __SPX_TRACE_LEVEL_WARNING __AZAC_TRACE_LEVEL_WARNING // Trace_Warning
#define __SPX_TRACE_LEVEL_ERROR __AZAC_TRACE_LEVEL_ERROR // Trace_Error
#define __SPX_TRACE_LEVEL_VERBOSE __AZAC_TRACE_LEVEL_VERBOSE // Trace_Verbose
#ifndef __SPX_DO_TRACE_IMPL
#define __SPX_DO_TRACE_IMPL __AZAC_DO_TRACE_IMPL
#endif
#define __SPX_DOTRACE(level, title, fileName, lineNumber, ...) \
__AZAC_DOTRACE(level, title, fileName, lineNumber, ##__VA_ARGS__)
#define __SPX_TRACE_INFO(title, fileName, lineNumber, msg, ...) \
__AZAC_TRACE_INFO(title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __SPX_TRACE_INFO_IF(cond, title, fileName, lineNumber, msg, ...) \
__AZAC_TRACE_INFO_IF(cond, title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __SPX_TRACE_WARNING(title, fileName, lineNumber, msg, ...) \
__AZAC_TRACE_WARNING(title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __SPX_TRACE_WARNING_IF(cond, title, fileName, lineNumber, msg, ...) \
__AZAC_TRACE_WARNING_IF(cond, title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __SPX_TRACE_ERROR(title, fileName, lineNumber, msg, ...) \
__AZAC_TRACE_ERROR(title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __SPX_TRACE_ERROR_IF(cond, title, fileName, lineNumber, msg, ...) \
__AZAC_TRACE_ERROR_IF(cond, title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __SPX_TRACE_VERBOSE(title, fileName, lineNumber, msg, ...) \
__AZAC_TRACE_VERBOSE(title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define __SPX_TRACE_VERBOSE_IF(cond, title, fileName, lineNumber, msg, ...) \
__AZAC_TRACE_VERBOSE_IF(cond, title, fileName, lineNumber, msg, ##__VA_ARGS__)
#define ___SPX_EXPR_AS_STRING(_String) \
___AZAC_EXPR_AS_STRING(_String)
#define __SPX_EXPR_AS_STRING(_String) \
__AZAC_EXPR_AS_STRING(_String)
#define __SPX_TRACE_HR(title, fileName, lineNumber, hr, x) \
__AZAC_TRACE_HR(title, fileName, lineNumber, hr, x)
#define __SPX_REPORT_ON_FAIL(title, fileName, lineNumber, hr) \
__AZAC_REPORT_ON_FAIL(title, fileName, lineNumber, hr)
#define __SPX_REPORT_ON_FAIL_IFNOT(title, fileName, lineNumber, hr, hrNot) \
__AZAC_REPORT_ON_FAIL_IFNOT(title, fileName, lineNumber, hr, hrNot)
#define __SPX_T_RETURN_HR(title, fileName, lineNumber, hr) \
__AZAC_T_RETURN_HR(title, fileName, lineNumber, hr)
#define __SPX_T_RETURN_HR_IF(title, fileName, lineNumber, hr, cond) \
__AZAC_T_RETURN_HR_IF(title, fileName, lineNumber, hr, cond)
#define __SPX_T_RETURN_ON_FAIL(title, fileName, lineNumber, hr) \
__AZAC_T_RETURN_ON_FAIL(title, fileName, lineNumber, hr)
#define __SPX_T_RETURN_ON_FAIL_IF_NOT(title, fileName, lineNumber, hr, hrNot) \
__AZAC_T_RETURN_ON_FAIL_IF_NOT(title, fileName, lineNumber, hr, hrNot)
#define __SPX_RETURN_HR(hr) \
__AZAC_RETURN_HR(hr)
#define __SPX_RETURN_HR_IF(hr, cond) \
__AZAC_RETURN_HR_IF(hr, cond)
#define __SPX_RETURN_ON_FAIL(hr) \
__AZAC_RETURN_ON_FAIL(hr)
#define __SPX_RETURN_ON_FAIL_IF_NOT(hr, hrNot) \
__AZAC_RETURN_ON_FAIL_IF_NOT(hr, hrNot)
#define SPX_EXITFN_CLEANUP AZAC_EXITFN_CLEANUP
#define __SPX_T_EXITFN_HR(title, fileName, lineNumber, hr) \
__AZAC_T_EXITFN_HR(title, fileName, lineNumber, hr)
#define __SPX_T_EXITFN_HR_IF(title, fileName, lineNumber, hr, cond) \
__AZAC_T_EXITFN_HR_IF(title, fileName, lineNumber, hr, cond)
#define __SPX_T_EXITFN_ON_FAIL(title, fileName, lineNumber, hr) \
__AZAC_T_EXITFN_ON_FAIL(title, fileName, lineNumber, hr)
#define __SPX_T_EXITFN_ON_FAIL_IF_NOT(title, fileName, lineNumber, hr, hrNot) \
__AZAC_T_EXITFN_ON_FAIL_IF_NOT(title, fileName, lineNumber, hr, hrNot)
#define __SPX_EXITFN_HR(hr) \
__AZAC_EXITFN_HR(hr)
#define __SPX_EXITFN_HR_IF(hr, cond) \
__AZAC_EXITFN_HR_IF(hr, cond)
#define __SPX_EXITFN_ON_FAIL(hr) \
__AZAC_EXITFN_ON_FAIL(hr)
#define __SPX_EXITFN_ON_FAIL_IF_NOT(hr, hrNot) \
__AZAC_EXITFN_ON_FAIL_IF_NOT(hr, hrNot)
#define __SPX_TRACE_ASSERT(title, fileName, lineNumber, expr) \
__AZAC_TRACE_ASSERT(title, fileName, lineNumber, expr)
#define __SPX_TRACE_ASSERT_MSG(title, fileName, lineNumber, expr, ...) \
__AZAC_TRACE_ASSERT_MSG(title, fileName, lineNumber, expr, ##__VA_ARGS__)
#define __SPX_DBG_ASSERT(title, fileName, lineNumber, expr) \
__AZAC_DBG_ASSERT(title, fileName, lineNumber, expr)
#define __SPX_DBG_ASSERT_WITH_MESSAGE(title, fileName, lineNumber, expr, ...) \
__AZAC_DBG_ASSERT_WITH_MESSAGE(title, fileName, lineNumber, expr, ##__VA_ARGS__)
#define __SPX_DBG_VERIFY(title, fileName, lineNumber, expr) \
__AZAC_DBG_VERIFY(title, fileName, lineNumber, expr)
#define __SPX_DBG_VERIFY_WITH_MESSAGE(title, fileName, lineNumber, expr, ...) \
__AZAC_DBG_VERIFY_WITH_MESSAGE(title, fileName, lineNumber, expr, ##__VA_ARGS__)
#ifdef __cplusplus
#define __SPX_TRACE_SCOPE(t1, fileName, lineNumber, t2, x, y) \
__AZAC_TRACE_SCOPE(t1, fileName, lineNumber, t2, x, y)
#ifndef __SPX_THROW_HR
#define __SPX_THROW_HR(hr) __SPX_THROW_HR_IMPL(hr)
#endif
#define __SPX_T_THROW_ON_FAIL(title, fileName, lineNumber, hr) \
__AZAC_T_THROW_ON_FAIL(title, fileName, lineNumber, hr)
#define __SPX_T_THROW_ON_FAIL_IF_NOT(title, fileName, lineNumber, hr, hrNot) \
__AZAC_T_THROW_ON_FAIL_IF_NOT(title, fileName, lineNumber, hr, hrNot)
#define __SPX_T_THROW_HR_IF(title, fileName, lineNumber, hr, cond) \
__AZAC_T_THROW_HR_IF(title, fileName, lineNumber, hr, cond)
#define __SPX_T_THROW_HR(title, fileName, lineNumber, hr) \
__AZAC_T_THROW_HR(title, fileName, lineNumber, hr)
#define __SPX_THROW_ON_FAIL(hr) \
__AZAC_THROW_ON_FAIL(hr)
#define __SPX_THROW_ON_FAIL_IF_NOT(hr, hrNot) \
__AZAC_THROW_ON_FAIL_IF_NOT(hr, hrNot)
#define __SPX_THROW_HR_IF(hr, cond) \
__AZAC_THROW_HR_IF(hr, cond)
#endif // __cplusplus
//-------------------------------------------------------
// SPX_ macro definitions
//-------------------------------------------------------
#ifdef SPX_CONFIG_TRACE_VERBOSE
#define SPX_TRACE_VERBOSE(msg, ...) __SPX_TRACE_VERBOSE("SPX_TRACE_VERBOSE: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define SPX_TRACE_VERBOSE_IF(cond, msg, ...) __SPX_TRACE_VERBOSE_IF(cond, "SPX_TRACE_VERBOSE: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define SPX_TRACE_VERBOSE(...)
#define SPX_TRACE_VERBOSE_IF(...)
#endif
#ifdef SPX_CONFIG_DBG_TRACE_VERBOSE
#define SPX_DBG_TRACE_VERBOSE(msg, ...) __SPX_TRACE_VERBOSE("SPX_DBG_TRACE_VERBOSE: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define SPX_DBG_TRACE_VERBOSE_IF(cond, msg, ...) __SPX_TRACE_VERBOSE_IF(cond, "SPX_DBG_TRACE_VERBOSE: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define SPX_DBG_TRACE_VERBOSE(...)
#define SPX_DBG_TRACE_VERBOSE_IF(...)
#endif
#ifdef SPX_CONFIG_TRACE_INFO
#define SPX_TRACE_INFO(msg, ...) __SPX_TRACE_INFO("SPX_TRACE_INFO: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define SPX_TRACE_INFO_IF(cond, msg, ...) __SPX_TRACE_INFO_IF(cond, "SPX_TRACE_INFO: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define SPX_TRACE_INFO(...)
#define SPX_TRACE_INFO_IF(...)
#endif
#ifdef SPX_CONFIG_DBG_TRACE_INFO
#define SPX_DBG_TRACE_INFO(msg, ...) __SPX_TRACE_INFO("SPX_DBG_TRACE_INFO: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define SPX_DBG_TRACE_INFO_IF(cond, msg, ...) __SPX_TRACE_INFO_IF(cond, "SPX_DBG_TRACE_INFO: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define SPX_DBG_TRACE_INFO(...)
#define SPX_DBG_TRACE_INFO_IF(...)
#endif
#ifdef SPX_CONFIG_TRACE_WARNING
#define SPX_TRACE_WARNING(msg, ...) __SPX_TRACE_WARNING("SPX_TRACE_WARNING:", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define SPX_TRACE_WARNING_IF(cond, msg, ...) __SPX_TRACE_WARNING_IF(cond, "SPX_TRACE_WARNING:", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define SPX_TRACE_WARNING(...)
#define SPX_TRACE_WARNING_IF(...)
#endif
#ifdef SPX_CONFIG_DBG_TRACE_WARNING
#define SPX_DBG_TRACE_WARNING(msg, ...) __SPX_TRACE_WARNING("SPX_DBG_TRACE_WARNING:", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define SPX_DBG_TRACE_WARNING_IF(cond, msg, ...) __SPX_TRACE_WARNING_IF(cond, "SPX_DBG_TRACE_WARNING:", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define SPX_DBG_TRACE_WARNING(...)
#define SPX_DBG_TRACE_WARNING_IF(...)
#endif
#ifdef SPX_CONFIG_TRACE_ERROR
#define SPX_TRACE_ERROR(msg, ...) __SPX_TRACE_ERROR("SPX_TRACE_ERROR: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define SPX_TRACE_ERROR_IF(cond, msg, ...) __SPX_TRACE_ERROR_IF(cond, "SPX_TRACE_ERROR: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define SPX_TRACE_ERROR(...)
#define SPX_TRACE_ERROR_IF(...)
#endif
#ifdef SPX_CONFIG_DBG_TRACE_ERROR
#define SPX_DBG_TRACE_ERROR(msg, ...) __SPX_TRACE_ERROR("SPX_DBG_TRACE_ERROR: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#define SPX_DBG_TRACE_ERROR_IF(cond, msg, ...) __SPX_TRACE_ERROR_IF(cond, "SPX_DBG_TRACE_ERROR: ", __FILE__, __LINE__, msg, ##__VA_ARGS__)
#else
#define SPX_DBG_TRACE_ERROR(...)
#define SPX_DBG_TRACE_ERROR_IF(...)
#endif
#ifdef SPX_CONFIG_TRACE_FUNCTION
#define SPX_TRACE_FUNCTION(...) __SPX_TRACE_VERBOSE("SPX_TRACE_FUNCTION: ", __FILE__, __LINE__, __FUNCTION__)
#else
#define SPX_TRACE_FUNCTION(...)
#endif
#ifdef SPX_CONFIG_DBG_TRACE_FUNCTION
#define SPX_DBG_TRACE_FUNCTION(...) __SPX_TRACE_VERBOSE("SPX_DBG_TRACE_FUNCTION: ", __FILE__, __LINE__, __FUNCTION__)
#else
#define SPX_DBG_TRACE_FUNCTION(...)
#endif
#ifdef SPX_CONFIG_TRACE_REPORT_ON_FAIL
#define SPX_REPORT_ON_FAIL(hr) __SPX_REPORT_ON_FAIL("SPX_REPORT_ON_FAIL: ", __FILE__, __LINE__, hr)
#define SPX_REPORT_ON_FAIL_IFNOT(hr, hrNot) __SPX_REPORT_ON_FAIL_IFNOT("SPX_REPORT_ON_FAIL: ", __FILE__, __LINE__, hr, hrNot)
#else
#define SPX_REPORT_ON_FAIL(hr) UNUSED(hr)
#define SPX_REPORT_ON_FAIL_IFNOT(hr, hrNot) UNUSED(hr); UNUSED(hrNot)
#endif
#ifdef SPX_CONFIG_TRACE_RETURN_ON_FAIL
#define SPX_RETURN_HR(hr) __SPX_T_RETURN_HR("SPX_RETURN_ON_FAIL: ", __FILE__, __LINE__, hr)
#define SPX_RETURN_HR_IF(hr, cond) __SPX_T_RETURN_HR_IF("SPX_RETURN_ON_FAIL: ", __FILE__, __LINE__, hr, cond)
#define SPX_RETURN_ON_FAIL(hr) __SPX_T_RETURN_ON_FAIL("SPX_RETURN_ON_FAIL: ", __FILE__, __LINE__, hr)
#define SPX_RETURN_ON_FAIL_IF_NOT(hr, hrNot) __SPX_T_RETURN_ON_FAIL_IF_NOT("SPX_RETURN_ON_FAIL: ", __FILE__, __LINE__, hr, hrNot)
#else
#define SPX_RETURN_HR(hr) __SPX_RETURN_HR(hr)
#define SPX_RETURN_HR_IF(hr, cond) __SPX_RETURN_HR_IF(hr, cond)
#define SPX_RETURN_ON_FAIL(hr) __SPX_RETURN_ON_FAIL(hr)
#define SPX_RETURN_ON_FAIL_IF_NOT(hr, hrNot) __SPX_RETURN_ON_FAIL_IF_NOT(hr, hrNot)
#endif
#define SPX_IFTRUE_RETURN_HR(cond, hr) SPX_RETURN_HR_IF(hr, cond)
#define SPX_IFFALSE_RETURN_HR(cond, hr) SPX_RETURN_HR_IF(hr, !(cond))
#define SPX_IFFAILED_RETURN_HR(hr) SPX_RETURN_ON_FAIL(hr)
#define SPX_IFFAILED_RETURN_HR_IFNOT(hr, hrNot) SPX_RETURN_ON_FAIL_IF_NOT(hr, hrNot)
#ifdef SPX_CONFIG_TRACE_EXITFN_ON_FAIL
#define SPX_EXITFN_HR(hr) __SPX_T_EXITFN_HR("SPX_EXITFN_ON_FAIL: ", __FILE__, __LINE__, hr)
#define SPX_EXITFN_HR_IF(hr, cond) __SPX_T_EXITFN_HR_IF("SPX_EXITFN_ON_FAIL: ", __FILE__, __LINE__, hr, cond)
#define SPX_EXITFN_ON_FAIL(hr) __SPX_T_EXITFN_ON_FAIL("SPX_EXITFN_ON_FAIL: ", __FILE__, __LINE__, hr)
#define SPX_EXITFN_ON_FAIL_IF_NOT(hr, hrNot) __SPX_T_EXITFN_ON_FAIL_IF_NOT("SPX_EXITFN_ON_FAIL: ", __FILE__, __LINE__, hr, hrNot)
#else
#define SPX_EXITFN_HR(hr) __SPX_EXITFN_HR(hr)
#define SPX_EXITFN_HR_IF(hr, cond) __SPX_EXITFN_HR_IF(hr, cond)
#define SPX_EXITFN_ON_FAIL(hr) __SPX_EXITFN_ON_FAIL(hr)
#define SPX_EXITFN_ON_FAIL_IF_NOT(hr, hrNot) __SPX_EXITFN_ON_FAIL_IF_NOT(hr, hrNot)
#endif
#define SPX_IFTRUE_EXITFN_WHR(cond, hr) SPX_EXITFN_HR_IF(hr, cond)
#define SPX_IFFALSE_EXITFN_WHR(cond, hr) SPX_EXITFN_HR_IF(hr, !(cond))
#define SPX_IFFAILED_EXITFN_WHR(hr) SPX_EXITFN_ON_FAIL(hr)
#define SPX_IFFAILED_EXITFN_WHR_IFNOT(hr, hrNot) SPX_EXITFN_ON_FAIL_IF_NOT(hr, hrNot)
#define SPX_IFTRUE_EXITFN_CLEANUP(cond, expr) AZAC_IFTRUE_EXITFN_CLEANUP(cond, expr)
#define SPX_IFFALSE_EXITFN_CLEANUP(cond, expr) AZAC_IFFALSE_EXITFN_CLEANUP(cond, expr)
#if defined(SPX_CONFIG_DBG_TRACE_ASSERT) && (defined(DEBUG) || defined(_DEBUG))
#define SPX_DBG_ASSERT(expr) __SPX_DBG_ASSERT("SPX_ASSERT: ", __FILE__, __LINE__, expr)
#define SPX_DBG_ASSERT_WITH_MESSAGE(expr, ...) __SPX_DBG_ASSERT_WITH_MESSAGE("SPX_ASSERT: ", __FILE__, __LINE__, expr, ##__VA_ARGS__)
#else
#define SPX_DBG_ASSERT(expr)
#define SPX_DBG_ASSERT_WITH_MESSAGE(expr, ...)
#endif
#if defined(SPX_CONFIG_DBG_TRACE_VERIFY) && (defined(DEBUG) || defined(_DEBUG))
#define SPX_DBG_VERIFY(expr) __SPX_DBG_VERIFY("SPX_VERIFY: ", __FILE__, __LINE__, expr)
#define SPX_DBG_VERIFY_WITH_MESSAGE(expr, ...) __SPX_DBG_VERIFY_WITH_MESSAGE("SPX_VERIFY: ", __FILE__, __LINE__, expr, ##__VA_ARGS__)
#else
#define SPX_DBG_VERIFY(expr) (expr)
#define SPX_DBG_VERIFY_WITH_MESSAGE(expr, ...) (expr)
#endif
#define SPX_IFTRUE(cond, expr) AZAC_IFTRUE(cond, expr)
#define SPX_IFFALSE(cond, expr) AZAC_IFFALSE(cond, expr)
#ifdef __cplusplus
#ifdef SPX_CONFIG_TRACE_SCOPE
#define SPX_TRACE_SCOPE(x, y) __SPX_TRACE_SCOPE("SPX_TRACE_SCOPE_ENTER: ", __FILE__, __LINE__, "SPX_TRACE_SCOPE_EXIT: ", x, y)
#else
#define SPX_TRACE_SCOPE(x, y)
#endif
#ifdef SPX_CONFIG_DBG_TRACE_SCOPE
#define SPX_DBG_TRACE_SCOPE(x, y) __SPX_TRACE_SCOPE("SPX_DBG_TRACE_SCOPE_ENTER: ", __FILE__, __LINE__, "SPX_DBG_TRACE_SCOPE_EXIT: ", x, y)
#else
#define SPX_DBG_TRACE_SCOPE(x, y)
#endif
#ifdef SPX_CONFIG_TRACE_THROW_ON_FAIL
#define SPX_THROW_ON_FAIL(hr) __SPX_T_THROW_ON_FAIL("SPX_THROW_ON_FAIL: ", __FILE__, __LINE__, hr)
#define SPX_THROW_ON_FAIL_IF_NOT(hr, hrNot) __SPX_T_THROW_ON_FAIL_IF_NOT("SPX_THROW_ON_FAIL: ", __FILE__, __LINE__, hr, hrNot)
#define SPX_THROW_HR_IF(hr, cond) __SPX_T_THROW_HR_IF("SPX_THROW_HR_IF: ", __FILE__, __LINE__, hr, cond)
#define SPX_THROW_HR(hr) __SPX_T_THROW_HR("SPX_THROW_HR: ", __FILE__, __LINE__, hr)
#else
#define SPX_THROW_ON_FAIL(hr) __SPX_THROW_ON_FAIL(hr)
#define SPX_THROW_ON_FAIL_IF_NOT(hr, hrNot) __SPX_THROW_ON_FAIL_IF_NOT(hr, hrNot)
#define SPX_THROW_HR_IF(hr, cond) __SPX_THROW_HR_IF(hr, cond)
#define SPX_THROW_HR(hr) __SPX_THROW_HR(hr)
#endif
#define SPX_IFFAILED_THROW_HR(hr) SPX_THROW_ON_FAIL(hr)
#define SPX_IFFAILED_THROW_HR_IFNOT(hr, hrNot) SPX_THROW_ON_FAIL_IF_NOT(hr, hrNot)
#else // __cplusplus
#define SPX_TRACE_SCOPE(x, y) static_assert(false)
#define SPX_DBG_TRACE_SCOPE(x, y) static_assert(false)
#define SPX_THROW_ON_FAIL(hr) static_assert(false)
#define SPX_THROW_ON_FAIL_IF_NOT(hr, hrNot) static_assert(false)
#define SPX_THROW_HR_IF(hr, cond) static_assert(false)
#define SPX_THROW_HR(hr) static_assert(false)
#define SPX_IFFAILED_THROW_HR(hr) static_assert(false)
#define SPX_IFFAILED_THROW_HR_IFNOT(hr, hrNot) static_assert(false)
#endif // __cplusplus

449
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/c_api/spxerror.h

@ -0,0 +1,449 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <azac_error.h> // must include after spxdebug.h or speechapi*.h (can NOT be included before)
#define SPXHR AZACHR
#define SPX_NOERROR AZAC_ERR_NONE
#define SPX_INIT_HR(hr) AZAC_INIT_HR(hr)
#define SPX_SUCCEEDED(x) AZAC_SUCCEEDED(x)
#define SPX_FAILED(x) AZAC_FAILED(x)
#define __SPX_ERRCODE_FAILED(x) __AZAC_ERRCODE_FAILED(x)
/// <summary>
/// The function is not implemented.
/// </summary>
#define SPXERR_NOT_IMPL \
AZAC_ERR_NOT_IMPL
/// <summary>
/// The object has not been properly initialized.
/// </summary>
#define SPXERR_UNINITIALIZED \
AZAC_ERR_UNINITIALIZED
/// <summary>
/// The object has already been initialized.
/// </summary>
#define SPXERR_ALREADY_INITIALIZED \
AZAC_ERR_ALREADY_INITIALIZED
/// <summary>
/// An unhandled exception was detected.
/// </summary>
#define SPXERR_UNHANDLED_EXCEPTION \
AZAC_ERR_UNHANDLED_EXCEPTION
/// <summary>
/// The object or property was not found.
/// </summary>
#define SPXERR_NOT_FOUND \
AZAC_ERR_NOT_FOUND
/// <summary>
/// One or more arguments are not valid.
/// </summary>
#define SPXERR_INVALID_ARG \
AZAC_ERR_INVALID_ARG
/// <summary>
/// The specified timeout value has elapsed.
/// </summary>
#define SPXERR_TIMEOUT \
AZAC_ERR_TIMEOUT
/// <summary>
/// The asynchronous operation is already in progress.
/// </summary>
#define SPXERR_ALREADY_IN_PROGRESS \
AZAC_ERR_ALREADY_IN_PROGRESS
/// <summary>
/// The attempt to open the file failed.
/// </summary>
#define SPXERR_FILE_OPEN_FAILED \
AZAC_ERR_FILE_OPEN_FAILED
/// <summary>
/// The end of the file was reached unexpectedly.
/// </summary>
#define SPXERR_UNEXPECTED_EOF \
AZAC_ERR_UNEXPECTED_EOF
/// <summary>
/// Invalid audio header encountered.
/// </summary>
#define SPXERR_INVALID_HEADER \
AZAC_ERR_INVALID_HEADER
/// <summary>
/// The requested operation cannot be performed while audio is pumping
/// </summary>
#define SPXERR_AUDIO_IS_PUMPING \
AZAC_ERR_AUDIO_IS_PUMPING
/// <summary>
/// Unsupported audio format.
/// </summary>
#define SPXERR_UNSUPPORTED_FORMAT \
AZAC_ERR_UNSUPPORTED_FORMAT
/// <summary>
/// Operation aborted.
/// </summary>
#define SPXERR_ABORT \
AZAC_ERR_ABORT
/// <summary>
/// Microphone is not available.
/// </summary>
#define SPXERR_MIC_NOT_AVAILABLE \
AZAC_ERR_MIC_NOT_AVAILABLE
/// <summary>
/// An invalid state was encountered.
/// </summary>
#define SPXERR_INVALID_STATE \
AZAC_ERR_INVALID_STATE
/// <summary>
/// Attempting to create a UUID failed.
/// </summary>
#define SPXERR_UUID_CREATE_FAILED \
AZAC_ERR_UUID_CREATE_FAILED
/// <summary>
/// An unexpected session state transition was encountered when setting the session audio format.
/// </summary>
/// <remarks>
/// Valid transitions are:
/// * WaitForPumpSetFormatStart --> ProcessingAudio (at the beginning of stream)
/// * StoppingPump --> WaitForAdapterCompletedSetFormatStop (at the end of stream)
/// * ProcessingAudio --> WaitForAdapterCompletedSetFormatStop (when the stream runs out of data)
/// All other state transitions are invalid.
/// </remarks>
#define SPXERR_SETFORMAT_UNEXPECTED_STATE_TRANSITION \
AZAC_ERR_SETFORMAT_UNEXPECTED_STATE_TRANSITION
/// <summary>
/// An unexpected session state was encountered in while processing audio.
/// </summary>
/// <remarks>
/// Valid states to encounter are:
/// * ProcessingAudio: We're allowed to process audio while in this state.
/// * StoppingPump: We're allowed to be called to process audio, but we'll ignore the data passed in while we're attempting to stop the pump.
/// All other states are invalid while processing audio.
/// </remarks>
#define SPXERR_PROCESS_AUDIO_INVALID_STATE \
AZAC_ERR_PROCESS_AUDIO_INVALID_STATE
/// <summary>
/// An unexpected state transition was encountered while attempting to start recognizing.
/// </summary>
/// <remarks>
/// A valid transition is:
/// * Idle --> WaitForPumpSetFormatStart
/// All other state transitions are invalid when attempting to start recognizing
/// </remarks>
#define SPXERR_START_RECOGNIZING_INVALID_STATE_TRANSITION \
AZAC_ERR_START_RECOGNIZING_INVALID_STATE_TRANSITION
/// <summary>
/// An unexpected error was encountered when trying to create an internal object.
/// </summary>
#define SPXERR_UNEXPECTED_CREATE_OBJECT_FAILURE \
AZAC_ERR_UNEXPECTED_CREATE_OBJECT_FAILURE
/// <summary>
/// An error in the audio-capturing system.
/// </summary>
#define SPXERR_MIC_ERROR \
AZAC_ERR_MIC_ERROR
/// <summary>
/// The requested operation cannot be performed; there is no audio input.
/// </summary>
#define SPXERR_NO_AUDIO_INPUT \
AZAC_ERR_NO_AUDIO_INPUT
/// <summary>
/// An unexpected error was encountered when trying to access the USP site.
/// </summary>
#define SPXERR_UNEXPECTED_USP_SITE_FAILURE \
AZAC_ERR_UNEXPECTED_USP_SITE_FAILURE
/// <summary>
/// An unexpected error was encountered when trying to access the LuAdapterSite site.
/// </summary>
#define SPXERR_UNEXPECTED_LU_SITE_FAILURE \
AZAC_ERR_UNEXPECTED_LU_SITE_FAILURE
/// <summary>
/// The buffer is too small.
/// </summary>
#define SPXERR_BUFFER_TOO_SMALL \
AZAC_ERR_BUFFER_TOO_SMALL
/// <summary>
/// A method failed to allocate memory.
/// </summary>
#define SPXERR_OUT_OF_MEMORY \
AZAC_ERR_OUT_OF_MEMORY
/// <summary>
/// An unexpected runtime error occurred.
/// </summary>
#define SPXERR_RUNTIME_ERROR \
AZAC_ERR_RUNTIME_ERROR
/// <summary>
/// The url specified is invalid.
/// </summary>
#define SPXERR_INVALID_URL \
AZAC_ERR_INVALID_URL
/// <summary>
/// The region specified is invalid or missing.
/// </summary>
#define SPXERR_INVALID_REGION \
AZAC_ERR_INVALID_REGION
/// <summary>
/// Switch between single shot and continuous recognition is not supported.
/// </summary>
#define SPXERR_SWITCH_MODE_NOT_ALLOWED \
AZAC_ERR_SWITCH_MODE_NOT_ALLOWED
/// <summary>
/// Changing connection status is not supported in the current recognition state.
/// </summary>
#define SPXERR_CHANGE_CONNECTION_STATUS_NOT_ALLOWED \
AZAC_ERR_CHANGE_CONNECTION_STATUS_NOT_ALLOWED
/// <summary>
/// Explicit connection management is not supported by the specified recognizer.
/// </summary>
#define SPXERR_EXPLICIT_CONNECTION_NOT_SUPPORTED_BY_RECOGNIZER \
AZAC_ERR_EXPLICIT_CONNECTION_NOT_SUPPORTED_BY_RECOGNIZER
/// <summary>
/// The handle is invalid.
/// </summary>
#define SPXERR_INVALID_HANDLE \
AZAC_ERR_INVALID_HANDLE
/// <summary>
/// The recognizer is invalid.
/// </summary>
#define SPXERR_INVALID_RECOGNIZER \
AZAC_ERR_INVALID_RECOGNIZER
/// <summary>
/// The value is out of range.
/// Added in version 1.3.0.
/// </summary>
#define SPXERR_OUT_OF_RANGE \
AZAC_ERR_OUT_OF_RANGE
/// <summary>
/// Extension library not found.
/// Added in version 1.3.0.
/// </summary>
#define SPXERR_EXTENSION_LIBRARY_NOT_FOUND \
AZAC_ERR_EXTENSION_LIBRARY_NOT_FOUND
/// <summary>
/// An unexpected error was encountered when trying to access the TTS engine site.
/// Added in version 1.4.0.
/// </summary>
#define SPXERR_UNEXPECTED_TTS_ENGINE_SITE_FAILURE \
AZAC_ERR_UNEXPECTED_TTS_ENGINE_SITE_FAILURE
/// <summary>
/// An unexpected error was encountered when trying to access the audio output stream.
/// Added in version 1.4.0.
/// </summary>
#define SPXERR_UNEXPECTED_AUDIO_OUTPUT_FAILURE \
AZAC_ERR_UNEXPECTED_AUDIO_OUTPUT_FAILURE
/// <summary>
/// Gstreamer internal error.
/// Added in version 1.4.0.
/// </summary>
#define SPXERR_GSTREAMER_INTERNAL_ERROR \
AZAC_ERR_GSTREAMER_INTERNAL_ERROR
/// <summary>
/// Compressed container format not supported.
/// Added in version 1.4.0.
/// </summary>
#define SPXERR_CONTAINER_FORMAT_NOT_SUPPORTED_ERROR \
AZAC_ERR_CONTAINER_FORMAT_NOT_SUPPORTED_ERROR
/// <summary>
/// Codec extension or gstreamer not found.
/// Added in version 1.4.0.
/// </summary>
#define SPXERR_GSTREAMER_NOT_FOUND_ERROR \
AZAC_ERR_GSTREAMER_NOT_FOUND_ERROR
/// <summary>
/// The language specified is missing.
/// Added in version 1.5.0.
/// </summary>
#define SPXERR_INVALID_LANGUAGE \
AZAC_ERR_INVALID_LANGUAGE
/// <summary>
/// The API is not applicable.
/// Added in version 1.5.0.
/// </summary>
#define SPXERR_UNSUPPORTED_API_ERROR \
AZAC_ERR_UNSUPPORTED_API_ERROR
/// <summary>
/// The ring buffer is unavailable.
/// Added in version 1.8.0.
/// </summary>
#define SPXERR_RINGBUFFER_DATA_UNAVAILABLE \
AZAC_ERR_RINGBUFFER_DATA_UNAVAILABLE
/// <summary>
/// An unexpected error was encountered when trying to access the Conversation site.
/// Added in version 1.5.0.
/// </summary>
#define SPXERR_UNEXPECTED_CONVERSATION_SITE_FAILURE \
AZAC_ERR_UNEXPECTED_CONVERSATION_SITE_FAILURE
/// <summary>
/// An unexpected error was encountered when trying to access the Conversation site.
/// Added in version 1.8.0.
/// </summary>
#define SPXERR_UNEXPECTED_CONVERSATION_TRANSLATOR_SITE_FAILURE \
AZAC_ERR_UNEXPECTED_CONVERSATION_TRANSLATOR_SITE_FAILURE
/// <summary>
/// An asynchronous operation was canceled before it was executed.
/// Added in version 1.8.0.
/// </summary>
#define SPXERR_CANCELED \
AZAC_ERR_CANCELED
/// <summary>
/// Codec for compression could not be initialized.
/// Added in version 1.10.0.
/// </summary>
#define SPXERR_COMPRESS_AUDIO_CODEC_INITIFAILED \
AZAC_ERR_COMPRESS_AUDIO_CODEC_INITIFAILED
/// <summary>
/// Data not available.
/// Added in version 1.10.0.
/// </summary>
#define SPXERR_DATA_NOT_AVAILABLE \
AZAC_ERR_DATA_NOT_AVAILABLE
/// <summary>
/// Invalid result reason.
/// Added in version 1.12.0
/// </summary>
#define SPXERR_INVALID_RESULT_REASON \
AZAC_ERR_INVALID_RESULT_REASON
/// <summary>
/// An unexpected error was encountered when trying to access the RNN-T site.
/// </summary>
#define SPXERR_UNEXPECTED_RNNT_SITE_FAILURE \
AZAC_ERR_UNEXPECTED_RNNT_SITE_FAILURE
/// <summary>
/// Sending of a network message failed.
/// </summary>
#define SPXERR_NETWORK_SEND_FAILED \
AZAC_ERR_NETWORK_SEND_FAILED
/// <summary>
/// Audio extension library not found.
/// Added in version 1.16.0.
/// </summary>
#define SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND \
AZAC_ERR_AUDIO_SYS_LIBRARY_NOT_FOUND
/// <summary>
/// An error in the audio-rendering system.
/// Added in version 1.20.0
/// </summary>
#define SPXERR_LOUDSPEAKER_ERROR \
AZAC_ERR_LOUDSPEAKER_ERROR
/// <summary>
/// An unexpected error was encountered when trying to access the Vision site.
/// Added in version 1.15.0.
/// </summary>
#define SPXERR_VISION_SITE_FAILURE \
AZAC_ERR_VISION_SITE_FAILURE
/// <summary>
/// Stream number provided was invalid in the current context.
/// Added in version 1.15.0.
/// </summary>
#define SPXERR_MEDIA_INVALID_STREAM \
AZAC_ERR_MEDIA_INVALID_STREAM
/// <summary>
/// Offset required is invalid in the current context.
/// Added in version 1.15.0.
/// </summary>
#define SPXERR_MEDIA_INVALID_OFFSET \
AZAC_ERR_MEDIA_INVALID_OFFSET
/// <summary>
/// No more data is available in source.
/// Added in version 1.15.0.
/// </summary>
#define SPXERR_MEDIA_NO_MORE_DATA \
AZAC_ERR_MEDIA_NO_MORE_DATA
/// <summary>
/// Source has not been started.
/// Added in version 1.15.0.
/// </summary>
#define SPXERR_MEDIA_NOT_STARTED \
AZAC_ERR_MEDIA_NOT_STARTED
/// <summary>
/// Source has already been started.
/// Added in version 1.15.0.
/// </summary>
#define SPXERR_MEDIA_ALREADY_STARTED \
AZAC_ERR_MEDIA_ALREADY_STARTED
/// <summary>
/// Media device creation failed.
/// Added in version 1.18.0.
/// </summary>
#define SPXERR_MEDIA_DEVICE_CREATION_FAILED \
AZAC_ERR_MEDIA_DEVICE_CREATION_FAILED
/// <summary>
/// No devices of the selected category are available.
/// Added in version 1.18.0.
/// </summary>
#define SPXERR_MEDIA_NO_DEVICE_AVAILABLE \
AZAC_ERR_MEDIA_NO_DEVICE_AVAILABLE
/// <summary>
/// Enabled Voice Activity Detection while using keyword recognition is not allowed.
/// </summary>
#define SPXERR_VAD_COULD_NOT_USE_WITH_KEYWORD_RECOGNIZER \
AZAC_ERR_VAD_COULD_NOT_USE_WITH_KEYWORD_RECOGNIZER
/// <summary>
/// The specified RecoEngineAdapter could not be created.
/// </summary>
#define SPXERR_COULD_NOT_CREATE_ENGINE_ADAPTER \
AZAC_ERR_COULD_NOT_CREATE_ENGINE_ADAPTER

9
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/CMakeLists.txt

@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.19)
project(cxx_headers)
set(SRC_DIR "${PROJECT_SOURCE_DIR}")
add_library(${PROJECT_NAME} INTERFACE ${SPEECH_CXX_API_HEADERS})
target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR})
target_link_libraries(${PROJECT_NAME} INTERFACE c_headers)
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER api)

82
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/azac_api_cxx_common.h

@ -0,0 +1,82 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/azai/license202106 for the full license information.
//
#pragma once
// TODO: TFS#3671215 - Vision: C/C++ azac_api* files are in shared include directory, speech and vision share
#include <azac_api_c_common.h>
#include <azac_api_c_error.h>
#include <azac_debug.h>
#include <azac_error.h>
#include <functional>
#include <stdexcept>
#include <string>
#define AZAC_DISABLE_COPY_AND_MOVE(T) \
/** \brief Disable copy constructor */ \
T(const T&) = delete; \
/** \brief Disable copy assignment */ \
T& operator=(const T&) = delete; \
/** \brief Disable move constructor */ \
T(T&&) = delete; \
/** \brief Disable move assignment */ \
T& operator=(T&&) = delete
#define AZAC_DISABLE_DEFAULT_CTORS(T) \
/** \brief Disable default constructor */ \
T() = delete; \
AZAC_DISABLE_COPY_AND_MOVE(T)
#if defined(__GNUG__) && defined(__linux__) && !defined(ANDROID) && !defined(__ANDROID__)
#include <cxxabi.h>
#define SHOULD_HANDLE_FORCED_UNWIND 1
#endif
/*! \cond INTERNAL */
namespace Azure {
namespace AI {
namespace Core {
namespace _detail {
template <class T>
class ProtectedAccess : public T
{
public:
static AZAC_HANDLE HandleFromPtr(T* ptr) {
if (ptr == nullptr)
{
return nullptr;
}
auto access = static_cast<ProtectedAccess*>(ptr);
return (AZAC_HANDLE)(*access);
}
static AZAC_HANDLE HandleFromConstPtr(const T* ptr) {
if (ptr == nullptr)
{
return nullptr;
}
auto access = static_cast<const ProtectedAccess*>(ptr);
return (AZAC_HANDLE)(*access);
}
template<typename... Args>
static std::shared_ptr<T> FromHandle(AZAC_HANDLE handle, Args... extras) {
return T::FromHandle(handle, extras...);
}
template<typename... Args>
static std::shared_ptr<T> Create(Args&&... args) {
return T::Create(std::forward<Args&&>(args)...);
}
};
} } } } // Azure::AI::Core::Details
/*! \endcond */

117
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx.h

@ -0,0 +1,117 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx.h: Master include header for public C++ API declarations
//
#pragma once
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_smart_handle.h>
#include <speechapi_cxx_properties.h>
#include <speechapi_cxx_audio_stream_format.h>
#include <speechapi_cxx_audio_stream.h>
#include <speechapi_cxx_speech_config.h>
#include <speechapi_cxx_embedded_speech_config.h>
#include <speechapi_cxx_hybrid_speech_config.h>
#include <speechapi_cxx_audio_config.h>
#include <speechapi_cxx_audio_processing_options.h>
#include <speechapi_cxx_eventargs.h>
#include <speechapi_cxx_eventsignal.h>
#include <speechapi_cxx_session_eventargs.h>
#include <speechapi_cxx_recognition_result.h>
#include <speechapi_cxx_recognition_eventargs.h>
#include <speechapi_cxx_recognition_async_recognizer.h>
#include <speechapi_cxx_recognition_base_async_recognizer.h>
#include <speechapi_cxx_recognizer.h>
#include <speechapi_cxx_speech_recognition_result.h>
#include <speechapi_cxx_speech_recognition_eventargs.h>
#include <speechapi_cxx_speech_recognizer.h>
#include <speechapi_cxx_speech_recognition_model.h>
#include <speechapi_cxx_conversational_language_understanding_model.h>
#include <speechapi_cxx_intent_recognition_result.h>
#include <speechapi_cxx_intent_recognition_eventargs.h>
#include <speechapi_cxx_intent_recognizer.h>
#include <speechapi_cxx_intent_trigger.h>
#include <speechapi_cxx_language_understanding_model.h>
#include <speechapi_cxx_pattern_matching_model.h>
#include <speechapi_cxx_pattern_matching_intent.h>
#include <speechapi_cxx_translation_result.h>
#include <speechapi_cxx_translation_eventargs.h>
#include <speechapi_cxx_speech_translation_config.h>
#include <speechapi_cxx_translation_recognizer.h>
#include <speechapi_cxx_auto_detect_source_lang_config.h>
#include <speechapi_cxx_source_lang_config.h>
#include <speechapi_cxx_speech_translation_model.h>
#include <speechapi_cxx_pronunciation_assessment_config.h>
#include <speechapi_cxx_pronunciation_assessment_result.h>
#include <speechapi_cxx_grammar.h>
#include <speechapi_cxx_grammar_phrase.h>
#include <speechapi_cxx_phrase_list_grammar.h>
#include <speechapi_cxx_grammar_list.h>
#include <speechapi_cxx_class_language_model.h>
#include <speechapi_cxx_session.h>
#include <speechapi_cxx_dialog_service_connector.h>
#include <speechapi_cxx_connection.h>
#include <speechapi_cxx_connection_eventargs.h>
#include <speechapi_cxx_audio_data_stream.h>
#include <speechapi_cxx_speech_synthesis_request.h>
#include <speechapi_cxx_speech_synthesis_result.h>
#include <speechapi_cxx_speech_synthesis_eventargs.h>
#include <speechapi_cxx_speech_synthesis_word_boundary_eventargs.h>
#include <speechapi_cxx_speech_synthesis_viseme_eventargs.h>
#include <speechapi_cxx_speech_synthesis_bookmark_eventargs.h>
#include <speechapi_cxx_speech_synthesizer.h>
#include <speechapi_cxx_synthesis_voices_result.h>
#include <speechapi_cxx_voice_info.h>
#include <speechapi_cxx_keyword_recognition_result.h>
#include <speechapi_cxx_keyword_recognition_eventargs.h>
#include <speechapi_cxx_keyword_recognizer.h>
#include <speechapi_cxx_conversation.h>
#include <speechapi_cxx_conversation_transcriber.h>
#include <speechapi_cxx_conversation_transcription_eventargs.h>
#include <speechapi_cxx_conversation_transcription_result.h>
#include <speechapi_cxx_meeting.h>
#include <speechapi_cxx_meeting_transcriber.h>
#include <speechapi_cxx_meeting_transcription_eventargs.h>
#include <speechapi_cxx_meeting_transcription_result.h>
#include <speechapi_cxx_user.h>
#include <speechapi_cxx_participant.h>
#include <speechapi_cxx_conversation_translator.h>
#include <speechapi_cxx_conversation_translator_events.h>
#include <speechapi_cxx_auto_detect_source_lang_result.h>
#include <speechapi_cxx_source_language_recognizer.h>
#include <speechapi_cxx_speaker_recognizer.h>
#include <speechapi_cxx_speaker_verification_model.h>
#include <speechapi_cxx_speaker_identification_model.h>
#include <speechapi_cxx_voice_profile_client.h>
#include <speechapi_cxx_voice_profile.h>
#include <speechapi_cxx_voice_profile_result.h>
#include <speechapi_cxx_voice_profile_enrollment_result.h>
#include <speechapi_cxx_voice_profile_phrase_result.h>
#include <speechapi_cxx_speaker_recognition_result.h>
#include <speechapi_cxx_file_logger.h>
#include <speechapi_cxx_event_logger.h>
#include <speechapi_cxx_memory_logger.h>

338
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_config.h

@ -0,0 +1,338 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_audio_config.h: Public API declarations for AudioConfig C++ class
//
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_smart_handle.h>
#include <speechapi_cxx_audio_stream.h>
#include <speechapi_cxx_audio_processing_options.h>
#include <speechapi_c_audio_config.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Audio {
/// <summary>
/// Represents audio input or output configuration. Audio input can be from a microphone, file,
/// or input stream. Audio output can be to a speaker, audio file output in WAV format, or output
/// stream.
/// </summary>
class AudioConfig
{
public:
/// <summary>
/// Internal operator used to get underlying handle value.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXAUDIOCONFIGHANDLE() const { return m_haudioConfig.get(); }
/// <summary>
/// Creates an AudioConfig object representing the default microphone on the system.
/// </summary>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromDefaultMicrophoneInput()
{
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_input_from_default_microphone(&haudioConfig));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing the default microphone on the system.
/// </summary>
/// <param name="audioProcessingOptions">Audio processing options.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromDefaultMicrophoneInput(std::shared_ptr<AudioProcessingOptions> audioProcessingOptions)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, audioProcessingOptions == nullptr);
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_input_from_default_microphone(&haudioConfig));
SPX_THROW_ON_FAIL(audio_config_set_audio_processing_options(haudioConfig, static_cast<SPXAUDIOPROCESSINGOPTIONSHANDLE>(*audioProcessingOptions.get())));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing a specific microphone on the system.
/// Added in version 1.3.0.
/// </summary>
/// <param name="deviceName">Specifies the device name. Please refer to <a href="https://aka.ms/csspeech/microphone-selection">this page</a> on how to retrieve platform-specific microphone names.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromMicrophoneInput(const SPXSTRING& deviceName)
{
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_input_from_a_microphone(&haudioConfig, Utils::ToUTF8(deviceName).c_str()));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing a specific microphone on the system.
/// </summary>
/// <param name="deviceName">Specifies the device name. Please refer to <a href="https://aka.ms/csspeech/microphone-selection">this page</a> on how to retrieve platform-specific microphone names.</param>
/// <param name="audioProcessingOptions">Audio processing options.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromMicrophoneInput(const SPXSTRING& deviceName, std::shared_ptr<AudioProcessingOptions> audioProcessingOptions)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, audioProcessingOptions == nullptr);
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_input_from_a_microphone(&haudioConfig, Utils::ToUTF8(deviceName).c_str()));
SPX_THROW_ON_FAIL(audio_config_set_audio_processing_options(haudioConfig, static_cast<SPXAUDIOPROCESSINGOPTIONSHANDLE>(*audioProcessingOptions.get())));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing the specified file.
/// </summary>
/// <param name="fileName">Specifies the audio input file.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromWavFileInput(const SPXSTRING& fileName)
{
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_input_from_wav_file_name(&haudioConfig, Utils::ToUTF8(fileName).c_str()));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing the specified file.
/// </summary>
/// <param name="fileName">Specifies the audio input file.</param>
/// <param name="audioProcessingOptions">Audio processing options.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromWavFileInput(const SPXSTRING& fileName, std::shared_ptr<AudioProcessingOptions> audioProcessingOptions)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, audioProcessingOptions == nullptr);
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_input_from_wav_file_name(&haudioConfig, Utils::ToUTF8(fileName).c_str()));
SPX_THROW_ON_FAIL(audio_config_set_audio_processing_options(haudioConfig, static_cast<SPXAUDIOPROCESSINGOPTIONSHANDLE>(*audioProcessingOptions.get())));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing the specified stream.
/// </summary>
/// <param name="stream">Specifies the custom audio input stream.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromStreamInput(std::shared_ptr<AudioInputStream> stream)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, stream == nullptr);
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_input_from_stream(&haudioConfig, GetStreamHandle(stream)));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing the specified stream.
/// </summary>
/// <param name="stream">Specifies the custom audio input stream.</param>
/// <param name="audioProcessingOptions">Audio processing options.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromStreamInput(std::shared_ptr<AudioInputStream> stream, std::shared_ptr<AudioProcessingOptions> audioProcessingOptions)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, stream == nullptr);
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, audioProcessingOptions == nullptr);
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_input_from_stream(&haudioConfig, GetStreamHandle(stream)));
SPX_THROW_ON_FAIL(audio_config_set_audio_processing_options(haudioConfig, static_cast<SPXAUDIOPROCESSINGOPTIONSHANDLE>(*audioProcessingOptions.get())));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing the default audio output device (speaker) on the system.
/// Added in version 1.4.0
/// </summary>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromDefaultSpeakerOutput()
{
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_output_from_default_speaker(&haudioConfig));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing a specific speaker on the system.
/// Added in version 1.14.0.
/// </summary>
/// <param name="deviceName">Specifies the device name. Please refer to <a href="https://aka.ms/csspeech/microphone-selection">this page</a> on how to retrieve platform-specific audio device names.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromSpeakerOutput(const SPXSTRING& deviceName)
{
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_output_from_a_speaker(&haudioConfig, Utils::ToUTF8(deviceName).c_str()));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing the specified file for audio output.
/// Added in version 1.4.0
/// </summary>
/// <param name="fileName">Specifies the audio output file. The parent directory must already exist.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromWavFileOutput(const SPXSTRING& fileName)
{
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_output_from_wav_file_name(&haudioConfig, Utils::ToUTF8(fileName).c_str()));
auto config = new AudioConfig(haudioConfig);
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Creates an AudioConfig object representing the specified output stream.
/// Added in version 1.4.0
/// </summary>
/// <param name="stream">Specifies the custom audio output stream.</param>
/// <returns>A shared pointer to the AudioConfig object</returns>
static std::shared_ptr<AudioConfig> FromStreamOutput(std::shared_ptr<AudioOutputStream> stream)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, stream == nullptr);
SPXAUDIOCONFIGHANDLE haudioConfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_create_audio_output_from_stream(&haudioConfig, GetOutputStreamHandle(stream)));
auto config = new AudioConfig(haudioConfig);
config->m_outputStream = stream;
return std::shared_ptr<AudioConfig>(config);
}
/// <summary>
/// Sets a property value by name.
/// </summary>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
void SetProperty(const SPXSTRING& name, const SPXSTRING& value)
{
property_bag_set_string(m_propertybag, -1, Utils::ToUTF8(name).c_str(), Utils::ToUTF8(value).c_str());
}
/// <summary>
/// Sets a property value by ID.
/// </summary>
/// <param name="id">The property id.</param>
/// <param name="value">The property value.</param>
void SetProperty(PropertyId id, const SPXSTRING& value)
{
property_bag_set_string(m_propertybag, static_cast<int>(id), nullptr, Utils::ToUTF8(value).c_str());
}
/// <summary>
/// Gets a property value by name.
/// </summary>
/// <param name="name">The parameter name.</param>
/// <returns>The property value.</returns>
SPXSTRING GetProperty(const SPXSTRING& name) const
{
const char* value = property_bag_get_string(m_propertybag, -1, Utils::ToUTF8(name).c_str(), "");
return Utils::ToSPXString(Utils::CopyAndFreePropertyString(value));
}
/// <summary>
/// Gets a property value by ID.
/// </summary>
/// <param name="id">The parameter id.</param>
/// <returns>The property value.</returns>
SPXSTRING GetProperty(PropertyId id) const
{
const char* value = property_bag_get_string(m_propertybag, static_cast<int>(id), nullptr, "");
return Utils::ToSPXString(Utils::CopyAndFreePropertyString(value));
}
/// <summary>
/// Gets an instance of AudioProcessingOptions class which contains the parameters for audio processing used by Speech SDK.
/// </summary>
/// <returns>A shared pointer to the AudioProcessingOptions object.</returns>
std::shared_ptr<AudioProcessingOptions> GetAudioProcessingOptions() const
{
SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_config_get_audio_processing_options(m_haudioConfig, &hoptions));
return std::make_shared<AudioProcessingOptions>(hoptions);
}
/// <summary>
/// Destructs the object.
/// </summary>
virtual ~AudioConfig()
{
property_bag_release(m_propertybag);
}
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit AudioConfig(SPXAUDIOCONFIGHANDLE haudioConfig)
: m_haudioConfig(haudioConfig)
{
SPX_THROW_ON_FAIL(audio_config_get_property_bag(m_haudioConfig, &m_propertybag));
}
/// <summary>
/// Internal helper method to get the audio stream format handle.
/// </summary>
static SPXAUDIOSTREAMHANDLE GetStreamHandle(std::shared_ptr<AudioInputStream> stream) { return (SPXAUDIOSTREAMHANDLE)(*stream.get()); }
/// <summary>
/// Internal helper method to get the audio output stream format handle.
/// </summary>
static SPXAUDIOSTREAMHANDLE GetOutputStreamHandle(std::shared_ptr<AudioOutputStream> stream) { return (SPXAUDIOSTREAMHANDLE)(*stream.get()); }
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(AudioConfig);
/// <summary>
/// Internal member variable that holds the smart handle.
/// </summary>
SmartHandle<SPXAUDIOCONFIGHANDLE, &audio_config_release> m_haudioConfig;
/// <summary>
/// Internal member variable that holds the properties of the audio config
/// </summary>
SPXPROPERTYBAGHANDLE m_propertybag;
std::shared_ptr<AudioInputStream> m_stream;
std::shared_ptr<AudioOutputStream> m_outputStream;
};
} } } } // Microsoft::CognitiveServices::Speech::Audio

239
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_data_stream.h

@ -0,0 +1,239 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_audio_data_stream.h: Public API declarations for AudioDataStream C++ class
//
#pragma once
#include <memory>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_smart_handle.h>
#include <speechapi_cxx_properties.h>
#include <speechapi_cxx_utils.h>
#include <speechapi_c_audio_stream.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
class SpeechSynthesisResult;
class KeywordRecognitionResult;
/// <summary>
/// Represents audio data stream used for operating audio data as a stream.
/// Added in version 1.4.0
/// </summary>
class AudioDataStream : public std::enable_shared_from_this<AudioDataStream>
{
private:
/// <summary>
/// Internal member variable that holds the smart handle.
/// </summary>
SmartHandle<SPXAUDIOSTREAMHANDLE, &audio_data_stream_release> m_haudioStream;
/*! \cond PRIVATE */
class PrivatePropertyCollection : public PropertyCollection
{
public:
PrivatePropertyCollection(SPXAUDIOSTREAMHANDLE hstream) :
PropertyCollection(
[=]() {
SPXPROPERTYBAGHANDLE hpropbag = SPXHANDLE_INVALID;
audio_data_stream_get_property_bag(hstream, &hpropbag);
return hpropbag;
}())
{
}
};
/// <summary>
/// Internal member variable that holds the properties associating to the audio data stream.
/// </summary>
PrivatePropertyCollection m_properties;
/*! \endcond */
public:
/// <summary>
/// Destroy the instance.
/// </summary>
~AudioDataStream()
{
DetachInput();
}
/// <summary>
/// Creates a memory backed AudioDataStream for the specified audio input file.
/// Added in version 1.14.0
/// </summary>
/// <param name="fileName">Specifies the audio input file.</param>
/// <returns>A shared pointer to AudioDataStream</returns>
static std::shared_ptr<AudioDataStream> FromWavFileInput(const SPXSTRING& fileName)
{
SPXAUDIOSTREAMHANDLE hstream = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_data_stream_create_from_file(&hstream, Utils::ToUTF8(fileName).c_str()));
auto stream = new AudioDataStream(hstream);
return std::shared_ptr<AudioDataStream>(stream);
}
/// <summary>
/// Creates a memory backed AudioDataStream from given speech synthesis result.
/// </summary>
/// <param name="result">The speech synthesis result.</param>
/// <returns>A shared pointer to AudioDataStream</returns>
static std::shared_ptr<AudioDataStream> FromResult(std::shared_ptr<SpeechSynthesisResult> result);
/// <summary>
/// Obtains the memory backed AudioDataStream associated with a given KeywordRecognition result.
/// </summary>
/// <param name="result">The keyword recognition result.</param>
/// <returns>An audio stream with the input to the KeywordRecognizer starting from right before the Keyword.</returns>
static std::shared_ptr<AudioDataStream> FromResult(std::shared_ptr<KeywordRecognitionResult> result);
/// <summary>
/// Get current status of the audio data stream.
/// </summary>
/// <returns>Current status</returns>
StreamStatus GetStatus()
{
Stream_Status status = StreamStatus_Unknown;
SPX_THROW_ON_FAIL(audio_data_stream_get_status(m_haudioStream, &status));
return (StreamStatus)status;
}
/// <summary>
/// Check whether the stream has enough data to be read.
/// </summary>
/// <param name="bytesRequested">The requested data size in bytes.</param>
/// <returns>A bool indicating whether the stream has enough data to be read.</returns>
bool CanReadData(uint32_t bytesRequested)
{
return audio_data_stream_can_read_data(m_haudioStream, bytesRequested);
}
/// <summary>
/// Check whether the stream has enough data to be read, starting from the specified position.
/// </summary>
/// <param name="pos">The position counting from start of the stream.</param>
/// <param name="bytesRequested">The requested data size in bytes.</param>
/// <returns>A bool indicating whether the stream has enough data to be read.</returns>
bool CanReadData(uint32_t pos, uint32_t bytesRequested)
{
return audio_data_stream_can_read_data_from_position(m_haudioStream, bytesRequested, pos);
}
/// <summary>
/// Reads a chunk of the audio data and fill it to given buffer
/// </summary>
/// <param name="buffer">A buffer to receive read data.</param>
/// <param name="bufferSize">Size of the buffer.</param>
/// <returns>Size of data filled to the buffer, 0 means end of stream</returns>
uint32_t ReadData(uint8_t* buffer, uint32_t bufferSize)
{
uint32_t filledSize = 0;
SPX_THROW_ON_FAIL(audio_data_stream_read(m_haudioStream, buffer, bufferSize, &filledSize));
return filledSize;
}
/// <summary>
/// Reads a chunk of the audio data and fill it to given buffer, starting from the specified position.
/// </summary>
/// <param name="pos">The position counting from start of the stream.</param>
/// <param name="buffer">A buffer to receive read data.</param>
/// <param name="bufferSize">Size of the buffer.</param>
/// <returns>Size of data filled to the buffer, 0 means end of stream</returns>
uint32_t ReadData(uint32_t pos, uint8_t* buffer, uint32_t bufferSize)
{
uint32_t filledSize = 0;
SPX_THROW_ON_FAIL(audio_data_stream_read_from_position(m_haudioStream, buffer, bufferSize, pos, &filledSize));
return filledSize;
}
/// <summary>
/// Save the audio data to a file, synchronously.
/// </summary>
/// <param name="fileName">The file name with full path.</param>
void SaveToWavFile(const SPXSTRING& fileName)
{
SPX_THROW_ON_FAIL(audio_data_stream_save_to_wave_file(m_haudioStream, Utils::ToUTF8(fileName).c_str()));
}
/// <summary>
/// Save the audio data to a file, asynchronously.
/// </summary>
/// <param name="fileName">The file name with full path.</param>
/// <returns>An asynchronous operation representing the saving.</returns>
std::future<void> SaveToWavFileAsync(const SPXSTRING& fileName)
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this, fileName]() -> void {
SPX_THROW_ON_FAIL(audio_data_stream_save_to_wave_file(m_haudioStream, Utils::ToUTF8(fileName).c_str()));
});
return future;
}
/// <summary>
/// Get current position of the audio data stream.
/// </summary>
/// <returns>Current position</returns>
uint32_t GetPosition()
{
uint32_t position = 0;
SPX_THROW_ON_FAIL(audio_data_stream_get_position(m_haudioStream, &position));
return position;
}
/// <summary>
/// Set current position of the audio data stream.
/// </summary>
/// <param name="pos">Position to be set.</param>
void SetPosition(uint32_t pos)
{
SPX_THROW_ON_FAIL(audio_data_stream_set_position(m_haudioStream, pos));
}
/// <summary>
/// Stops any more data from getting to the stream.
/// </summary>
void DetachInput()
{
SPX_THROW_ON_FAIL(audio_data_stream_detach_input(m_haudioStream));
}
/// <summary>
/// Explicit conversion operator.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXAUDIOSTREAMHANDLE() { return m_haudioStream; }
/// <summary>
/// Collection of additional SpeechSynthesisResult properties.
/// </summary>
const PropertyCollection& Properties;
private:
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit AudioDataStream(SPXAUDIOSTREAMHANDLE haudioStream) :
m_haudioStream(haudioStream),
m_properties(haudioStream),
Properties(m_properties)
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
}
};
} } } // Microsoft::CognitiveServices::Speech

358
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_processing_options.h

@ -0,0 +1,358 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_audio_processing_options.h: Public API declarations for AudioProcessingOptions and related C++ classes
//
#pragma once
#include <vector>
#include <memory>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_smart_handle.h>
#include <speechapi_c_audio_processing_options.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Audio {
/// <summary>
/// Types of preset microphone array geometries.
/// See [Microphone Array Recommendations](/azure/cognitive-services/speech-service/speech-devices-sdk-microphone) for more details.
/// </summary>
enum class PresetMicrophoneArrayGeometry
{
/// <summary>
/// Indicates that no geometry specified. Speech SDK will determine the microphone array geometry.
/// </summary>
Uninitialized,
/// <summary>
/// Indicates a microphone array with one microphone in the center and six microphones evenly spaced
/// in a circle with radius approximately equal to 42.5 mm.
/// </summary>
Circular7,
/// <summary>
/// Indicates a microphone array with one microphone in the center and three microphones evenly spaced
/// in a circle with radius approximately equal to 42.5 mm.
/// </summary>
Circular4,
/// <summary>
/// Indicates a microphone array with four linearly placed microphones with 40 mm spacing between them.
/// </summary>
Linear4,
/// <summary>
/// Indicates a microphone array with two linearly placed microphones with 40 mm spacing between them.
/// </summary>
Linear2,
/// <summary>
/// Indicates a microphone array with a single microphone.
/// </summary>
Mono,
/// <summary>
/// Indicates a microphone array with custom geometry.
/// </summary>
Custom
};
/// <summary>
/// Types of microphone arrays.
/// </summary>
enum class MicrophoneArrayType
{
/// <summary>
/// Indicates that the microphone array has microphones in a straight line.
/// </summary>
Linear,
/// <summary>
/// Indicates that the microphone array has microphones in a plane.
/// </summary>
Planar
};
/// <summary>
/// Defines speaker reference channel position in input audio.
/// </summary>
enum class SpeakerReferenceChannel
{
/// <summary>
/// Indicates that the input audio does not have a speaker reference channel.
/// </summary>
None,
/// <summary>
/// Indicates that the last channel in the input audio corresponds to the speaker
/// reference for echo cancellation.
/// </summary>
LastChannel
};
typedef AudioProcessingOptions_MicrophoneCoordinates MicrophoneCoordinates;
/// <summary>
/// Represents the geometry of a microphone array.
/// </summary>
struct MicrophoneArrayGeometry
{
/// <summary>
/// Type of microphone array.
/// </summary>
MicrophoneArrayType microphoneArrayType;
/// <summary>
/// Start angle for beamforming in degrees.
/// </summary>
uint16_t beamformingStartAngle;
/// <summary>
/// End angle for beamforming in degrees.
/// </summary>
uint16_t beamformingEndAngle;
/// <summary>
/// Coordinates of microphones in the microphone array.
/// </summary>
std::vector<MicrophoneCoordinates> microphoneCoordinates;
/// <summary>
/// Creates a new instance of MicrophoneArrayGeometry.
/// Beamforming start angle is set to zero.
/// Beamforming end angle is set to 180 degrees if microphoneArrayType is Linear, otherwise it is set to 360 degrees.
/// </summary>
/// <param name="microphoneArrayType">Type of microphone array.</param>
/// <param name="microphoneCoordinates">Coordinates of microphones in the microphone array.</param>
MicrophoneArrayGeometry(MicrophoneArrayType microphoneArrayType, const std::vector<MicrophoneCoordinates>& microphoneCoordinates)
{
this->microphoneArrayType = microphoneArrayType;
this->beamformingStartAngle = 0;
this->beamformingEndAngle = (microphoneArrayType == MicrophoneArrayType::Linear) ? 180 : 360;
this->microphoneCoordinates.resize(microphoneCoordinates.size());
for (size_t i = 0; i < microphoneCoordinates.size(); i++)
{
this->microphoneCoordinates[i] = microphoneCoordinates[i];
}
}
/// <summary>
/// Creates a new instance of MicrophoneArrayGeometry.
/// </summary>
/// <param name="microphoneArrayType">Type of microphone array.</param>
/// <param name="beamformingStartAngle">Start angle for beamforming in degrees.</param>
/// <param name="beamformingEndAngle">End angle for beamforming in degrees.</param>
/// <param name="microphoneCoordinates">Coordinates of microphones in the microphone array.</param>
MicrophoneArrayGeometry(MicrophoneArrayType microphoneArrayType, uint16_t beamformingStartAngle, uint16_t beamformingEndAngle, const std::vector<MicrophoneCoordinates>& microphoneCoordinates)
{
this->microphoneArrayType = microphoneArrayType;
this->beamformingStartAngle = beamformingStartAngle;
this->beamformingEndAngle = beamformingEndAngle;
this->microphoneCoordinates.resize(microphoneCoordinates.size());
for (size_t i = 0; i < microphoneCoordinates.size(); i++)
{
this->microphoneCoordinates[i] = microphoneCoordinates[i];
}
}
};
/// <summary>
/// Represents audio processing options used with audio config class.
/// </summary>
class AudioProcessingOptions
{
public:
/// <summary>
/// Creates a new instance using the provided handle.
/// </summary>
/// <param name="hoptions">A handle to audio processing options.</param>
explicit AudioProcessingOptions(SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions)
: m_hoptions(hoptions)
{
SPX_THROW_ON_FAIL(audio_processing_options_get_property_bag(m_hoptions, &m_propertybag));
}
/// <summary>
/// Destructs an instance of the AudioProcessingOptions class.
/// </summary>
~AudioProcessingOptions() = default;
/// <summary>
/// Internal operator used to get underlying handle value.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXAUDIOPROCESSINGOPTIONSHANDLE() const { return m_hoptions.get(); }
/// <summary>
/// Creates a new instance of the AudioProcessingOptions class.
/// </summary>
/// <param name="audioProcessingFlags">Specifies flags to control the audio processing performed by Speech SDK. It is bitwise OR of AUDIO_INPUT_PROCESSING_XXX constants.</param>
/// <returns>The newly created AudioProcessingOptions wrapped inside a std::shared_ptr.</returns>
/// <remarks>
/// This function should only be used when the audio input is from a microphone array.
/// On Windows, this function will try to query the microphone array geometry from the audio driver. Audio data is also read from speaker reference channel.
/// On Linux, it assumes that the microphone is a single channel microphone.
/// </remarks>
static std::shared_ptr<AudioProcessingOptions> Create(int audioProcessingFlags)
{
SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_processing_options_create(&hoptions, audioProcessingFlags));
auto options = new AudioProcessingOptions(hoptions);
return std::shared_ptr<AudioProcessingOptions>(options);
}
/// <summary>
/// Creates a new instance of the AudioProcessingOptions class with preset microphone array geometry.
/// </summary>
/// <param name="audioProcessingFlags">Specifies flags to control the audio processing performed by Speech SDK. It is bitwise OR of AUDIO_INPUT_PROCESSING_XXX constants.</param>
/// <param name="microphoneArrayGeometry">Specifies the type of microphone array geometry.</param>
/// <param name="speakerReferenceChannel">Specifies the speaker reference channel position in the input audio.</param>
/// <returns>The newly created AudioProcessingOptions wrapped inside a std::shared_ptr.</returns>
static std::shared_ptr<AudioProcessingOptions> Create(int audioProcessingFlags, PresetMicrophoneArrayGeometry microphoneArrayGeometry, SpeakerReferenceChannel speakerReferenceChannel = SpeakerReferenceChannel::None)
{
SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_processing_options_create_from_preset_microphone_array_geometry(&hoptions, audioProcessingFlags, (AudioProcessingOptions_PresetMicrophoneArrayGeometry)microphoneArrayGeometry, (AudioProcessingOptions_SpeakerReferenceChannel)speakerReferenceChannel));
auto options = new AudioProcessingOptions(hoptions);
return std::shared_ptr<AudioProcessingOptions>(options);
}
/// <summary>
/// Creates a new instance of the AudioProcessingOptions class with microphone array geometry.
/// </summary>
/// <param name="audioProcessingFlags">Specifies flags to control the audio processing performed by Speech SDK. It is bitwise OR of AUDIO_INPUT_PROCESSING_XXX constants.</param>
/// <param name="microphoneArrayGeometry">Specifies the microphone array geometry.</param>
/// <param name="speakerReferenceChannel">Specifies the speaker reference channel position in the input audio.</param>
/// <returns>The newly created AudioProcessingOptions wrapped inside a std::shared_ptr.</returns>
static std::shared_ptr<AudioProcessingOptions> Create(int audioProcessingFlags, MicrophoneArrayGeometry microphoneArrayGeometry, SpeakerReferenceChannel speakerReferenceChannel = SpeakerReferenceChannel::None)
{
AudioProcessingOptions_MicrophoneArrayGeometry geometry
{
(AudioProcessingOptions_MicrophoneArrayType)microphoneArrayGeometry.microphoneArrayType,
microphoneArrayGeometry.beamformingStartAngle,
microphoneArrayGeometry.beamformingEndAngle,
(uint16_t)microphoneArrayGeometry.microphoneCoordinates.size(),
microphoneArrayGeometry.microphoneCoordinates.data()
};
SPXAUDIOPROCESSINGOPTIONSHANDLE hoptions = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_processing_options_create_from_microphone_array_geometry(&hoptions, audioProcessingFlags, &geometry, (AudioProcessingOptions_SpeakerReferenceChannel)speakerReferenceChannel));
auto options = new AudioProcessingOptions(hoptions);
return std::shared_ptr<AudioProcessingOptions>(options);
}
/// <summary>
/// Returns the type of audio processing performed by Speech SDK.
/// </summary>
/// <returns>Bitwise OR of AUDIO_INPUT_PROCESSING_XXX constant flags indicating the input audio processing performed by Speech SDK.</returns>
int GetAudioProcessingFlags() const
{
int audioProcessingFlags;
SPX_THROW_ON_FAIL(audio_processing_options_get_audio_processing_flags(m_hoptions, &audioProcessingFlags));
return audioProcessingFlags;
}
/// <summary>
/// Returns the microphone array geometry of the microphone used for audio input.
/// </summary>
/// <returns>A value of type PresetMicrophoneArrayGeometry enum.</returns>
PresetMicrophoneArrayGeometry GetPresetMicrophoneArrayGeometry() const
{
PresetMicrophoneArrayGeometry microphoneArrayGeometry = PresetMicrophoneArrayGeometry::Uninitialized;
SPX_THROW_ON_FAIL(audio_processing_options_get_preset_microphone_array_geometry(m_hoptions, (AudioProcessingOptions_PresetMicrophoneArrayGeometry*)&microphoneArrayGeometry));
return microphoneArrayGeometry;
}
/// <summary>
/// Returns the microphone array type of the microphone used for audio input.
/// </summary>
/// <returns>A value of type MicrophoneArrayType enum.</returns>
MicrophoneArrayType GetMicrophoneArrayType() const
{
MicrophoneArrayType microphoneArrayType = MicrophoneArrayType::Linear;
SPX_THROW_ON_FAIL(audio_processing_options_get_microphone_array_type(m_hoptions, (AudioProcessingOptions_MicrophoneArrayType*)&microphoneArrayType));
return microphoneArrayType;
}
/// <summary>
/// Returns the start angle used for beamforming.
/// </summary>
/// <returns>Beamforming start angle.</returns>
uint16_t GetBeamformingStartAngle() const
{
uint16_t startAngle;
SPX_THROW_ON_FAIL(audio_processing_options_get_beamforming_start_angle(m_hoptions, &startAngle));
return startAngle;
}
/// <summary>
/// Returns the end angle used for beamforming.
/// </summary>
/// <returns>Beamforming end angle.</returns>
uint16_t GetBeamformingEndAngle() const
{
uint16_t endAngle;
SPX_THROW_ON_FAIL(audio_processing_options_get_beamforming_end_angle(m_hoptions, &endAngle));
return endAngle;
}
/// <summary>
/// Returns the coordinates of microphones in the microphone array used for audio input.
/// </summary>
/// <returns>A std::vector of MicrophoneCoordinates elements.</returns>
std::vector<MicrophoneCoordinates> GetMicrophoneCoordinates() const
{
uint16_t microphoneCount;
SPX_THROW_ON_FAIL(audio_processing_options_get_microphone_count(m_hoptions, &microphoneCount));
std::vector<MicrophoneCoordinates> microphoneCoordinates(microphoneCount);
SPX_THROW_ON_FAIL(audio_processing_options_get_microphone_coordinates(m_hoptions, microphoneCoordinates.data(), microphoneCount));
return microphoneCoordinates;
}
/// <summary>
/// Returns the speaker reference channel position in the audio input.
/// </summary>
/// <returns>A value of type SpeakerReferenceChannel enum.</returns>
SpeakerReferenceChannel GetSpeakerReferenceChannel() const
{
SpeakerReferenceChannel speakerReferenceChannel = SpeakerReferenceChannel::None;
SPX_THROW_ON_FAIL(audio_processing_options_get_speaker_reference_channel(m_hoptions, (AudioProcessingOptions_SpeakerReferenceChannel*)&speakerReferenceChannel));
return speakerReferenceChannel;
}
/// <summary>
/// Sets a property value by name.
/// </summary>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
void SetProperty(const SPXSTRING& name, const SPXSTRING& value)
{
property_bag_set_string(m_propertybag, -1, Utils::ToUTF8(name).c_str(), Utils::ToUTF8(value).c_str());
}
/// <summary>
/// Gets a property value by name.
/// </summary>
/// <param name="name">The parameter name.</param>
/// <returns>The property value.</returns>
SPXSTRING GetProperty(const SPXSTRING& name) const
{
const char* value = property_bag_get_string(m_propertybag, -1, Utils::ToUTF8(name).c_str(), "");
return Utils::ToSPXString(Utils::CopyAndFreePropertyString(value));
}
private:
DISABLE_COPY_AND_MOVE(AudioProcessingOptions);
/// <summary>
/// Internal member variable that holds the smart handle.
/// </summary>
SmartHandle<SPXAUDIOPROCESSINGOPTIONSHANDLE, &audio_processing_options_release> m_hoptions;
/// <summary>
/// Internal member variable that holds the properties of the audio processing options.
/// </summary>
SmartHandle<SPXPROPERTYBAGHANDLE, &property_bag_release> m_propertybag;
};
} } } } // Microsoft::CognitiveServices::Speech::Audio

995
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_stream.h

@ -0,0 +1,995 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_audio_stream.h: Public API declarations for AudioInputStream / AudioOutputStream and related C++ classes
//
#pragma once
#include <functional>
#include <future>
#include <memory>
#include <vector>
#include <string>
#include <cstring>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_smart_handle.h>
#include <speechapi_cxx_audio_stream_format.h>
#include <speechapi_cxx_enums.h>
#include <speechapi_c_audio_stream.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Dialog {
class ActivityReceivedEventArgs;
}
namespace Audio {
class PullAudioInputStreamCallback;
class PushAudioInputStream;
class PullAudioInputStream;
class PushAudioOutputStreamCallback;
class PushAudioOutputStream;
class PullAudioOutputStream;
/// <summary>
/// Represents audio input stream used for custom audio input configurations.
/// </summary>
class AudioInputStream
{
public:
using ReadCallbackFunction_Type = ::std::function<int(uint8_t*, uint32_t)>;
using CloseCallbackFunction_Type = ::std::function<void()>;
/// Added in version 1.5.0.
using GetPropertyCallbackFunction_Type = std::function<SPXSTRING(PropertyId)>;
/// <summary>
/// Internal operator used to get underlying handle value.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXAUDIOSTREAMHANDLE() const { return m_haudioStream.get(); }
/// <summary>
/// Creates a memory backed PushAudioInputStream using the default format (16 kHz, 16 bit, mono PCM).
/// </summary>
/// <returns>A shared pointer to PushAudioInputStream</returns>
static std::shared_ptr<PushAudioInputStream> CreatePushStream();
/// <summary>
/// Creates a memory backed PushAudioInputStream with the specified audio format.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <returns>A shared pointer to PushAudioInputStream</returns>
static std::shared_ptr<PushAudioInputStream> CreatePushStream(std::shared_ptr<AudioStreamFormat> format);
/// <summary>
/// Creates a PullAudioInputStream that delegates to the specified callback functions for Read() and Close() methods, using the default format (16 kHz, 16 bit, mono PCM).
/// </summary>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback = nullptr);
/// <summary>
/// Creates a PullAudioInputStream that delegates to the specified callback functions for Read(), Close() and GetProperty() methods
/// Added in version 1.5.0.
/// </summary>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <param name="getPropertyCallback">GetProperty callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback, CUSTOM_AUDIO_PULL_STREAM_GET_PROPERTY_CALLBACK getPropertyCallback);
/// Creates a PullAudioInputStream that delegates to the specified callback functions for Read() and Close() methods, using the default format (16 kHz, 16 bit, mono PCM).
/// </summary>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback = nullptr);
/// <summary>
/// Creates a PullAudioInputStream that delegates to the specified callback functions for Read(), Close() and GetProperty() methods.
/// Added in version 1.5.0.
/// </summary>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <param name="getPropertyCallback">Get property callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback, GetPropertyCallbackFunction_Type getPropertyCallback);
/// <summary>
/// Creates a PullAudioInputStream that delegates to the specified callback interface for the Read() and Close() methods, using the default format (16 kHz, 16 bit, mono PCM).
/// </summary>
/// <param name="callback">Shared pointer to PullAudioInputStreamCallback instance.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(std::shared_ptr<PullAudioInputStreamCallback> callback);
/// <summary>
/// Creates a PullAudioInputStream that delegates to the specified callback functions for Read() and Close() methods.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(std::shared_ptr<AudioStreamFormat> format, void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback = nullptr);
/// <summary>
/// Creates a PullAudioInputStream that delegates to the specified callback functions for Read(), Close() and GetProperty() methods.
/// Added in version 1.5.0.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <param name="getPropertyCallback">Get property callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(std::shared_ptr<AudioStreamFormat> format, void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback, CUSTOM_AUDIO_PULL_STREAM_GET_PROPERTY_CALLBACK getPropertyCallback);
/// Creates a PullAudioInputStream that delegates to the specified callback functions for Read() and Close() methods.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(std::shared_ptr<AudioStreamFormat> format, ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback = nullptr);
/// <summary>
/// Creates a PullAudioInputStream that delegates to the specified callback functions for Read() and Close() methods.
/// Added in version 1.5.0.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <param name="getPropertyCallback">Get property callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(std::shared_ptr<AudioStreamFormat> format, ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback, GetPropertyCallbackFunction_Type getPropertyCallback);
/// <summary>
/// Creates a PullAudioInputStream that delegates to the specified callback interface for the Read() and Close() methods, using the specified format.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="callback">Shared pointer to PullAudioInputStreamCallback instance.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> CreatePullStream(std::shared_ptr<AudioStreamFormat> format, std::shared_ptr<PullAudioInputStreamCallback> callback);
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit AudioInputStream(SPXAUDIOSTREAMHANDLE haudioStream) : m_haudioStream(haudioStream) { }
/// <summary>
/// Destructor, does nothing.
/// </summary>
virtual ~AudioInputStream() {}
/// <summary>
/// Internal helper method to get the default format if the specified format is nullptr.
/// </summary>
static std::shared_ptr<AudioStreamFormat> UseDefaultFormatIfNull(std::shared_ptr<AudioStreamFormat> format) { return format != nullptr ? format : AudioStreamFormat::GetDefaultInputFormat(); }
/// <summary>
/// Internal helper method to get the audio stream format handle.
/// </summary>
static SPXAUDIOSTREAMFORMATHANDLE GetFormatHandle(std::shared_ptr<AudioStreamFormat> format) { return (SPXAUDIOSTREAMFORMATHANDLE)(*format.get()); }
/// <summary>
/// Internal member variable that holds the smart handle.
/// </summary>
SmartHandle<SPXAUDIOSTREAMHANDLE, &audio_stream_release> m_haudioStream;
protected:
static constexpr size_t m_maxPropertyLen = 1024;
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(AudioInputStream);
};
/// <summary>
/// Represents memory backed push audio input stream used for custom audio input configurations.
/// </summary>
class PushAudioInputStream : public AudioInputStream
{
public:
/// <summary>
/// Destructor; closes the underlying stream if not already closed.
/// </summary>
virtual ~PushAudioInputStream()
{
if (audio_stream_is_handle_valid(m_haudioStream))
{
CloseStream();
}
}
/// <summary>
/// Creates a memory backed PushAudioInputStream using the default format (16 kHz, 16 bit, mono PCM).
/// </summary>
/// <returns>A shared pointer to PushAudioInputStream</returns>
static std::shared_ptr<PushAudioInputStream> Create()
{
return Create(nullptr);
}
/// <summary>
/// Creates a memory backed PushAudioInputStream with the specified audio format.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <returns>A shared pointer to PushAudioInputStream</returns>
static std::shared_ptr<PushAudioInputStream> Create(std::shared_ptr<AudioStreamFormat> format)
{
format = UseDefaultFormatIfNull(format);
SPXAUDIOSTREAMHANDLE haudioStream = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_stream_create_push_audio_input_stream(&haudioStream, GetFormatHandle(format)));
auto stream = new PushAudioInputStream(haudioStream);
return std::shared_ptr<PushAudioInputStream>(stream);
}
/// <summary>
/// Writes the audio data specified by making an internal copy of the data.
/// Note: The dataBuffer should not contain any audio header.
/// </summary>
/// <param name="dataBuffer">The pointer to the audio buffer of which this function will make a copy.</param>
/// <param name="size">The size of the buffer.</param>
void Write(uint8_t* dataBuffer, uint32_t size)
{
SPX_THROW_ON_FAIL(push_audio_input_stream_write(m_haudioStream, dataBuffer, size));
}
/// <summary>
/// Set value of a property. The properties of the audio data should be set before writing the audio data.
/// Added in version 1.5.0.
/// </summary>
/// <param name="id">The id of property. See <see cref="PropertyId"/></param>
/// <param name="value">value to set</param>
void SetProperty(PropertyId id, const SPXSTRING& value)
{
SPX_THROW_ON_FAIL(push_audio_input_stream_set_property_by_id(m_haudioStream, static_cast<int>(id), Utils::ToUTF8(value).c_str()));
}
/// <summary>
/// Set value of a property. The properties of the audio data should be set before writing the audio data.
/// Added in version 1.5.0.
/// </summary>
/// <param name="propertyName">The name of property.</param>
/// <param name="value">value to set</param>
void SetProperty(const SPXSTRING& propertyName, const SPXSTRING& value)
{
SPX_THROW_ON_FAIL(push_audio_input_stream_set_property_by_name(m_haudioStream, Utils::ToUTF8(propertyName.c_str()), Utils::ToUTF8(value.c_str())));
}
/// <summary>
/// Closes the stream.
/// </summary>
void Close() { SPX_THROW_ON_FAIL(CloseStream()); }
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit PushAudioInputStream(SPXAUDIOSTREAMHANDLE haudioStream) : AudioInputStream(haudioStream) { }
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(PushAudioInputStream);
SPXHR CloseStream() { return push_audio_input_stream_close(m_haudioStream); }
};
/// <summary>
/// An interface that defines callback methods for an audio input stream.
/// </summary>
/// <remarks>
/// Derive from this class and implement its function to provide your own
/// data as an audio input stream.
/// <remarks>
class PullAudioInputStreamCallback
{
public:
/// <summary>
/// Destructor, does nothing.
/// </summary>
virtual ~PullAudioInputStreamCallback() {}
/// <summary>
/// This function is called to synchronously get data from the audio stream.
/// Note: The dataBuffer returned by Read() should not contain any audio header.
/// </summary>
/// <param name="dataBuffer">The pointer to the buffer to which to copy the audio data.</param>
/// <param name="size">The size of the buffer.</param>
/// <returns>The number of bytes copied into the buffer, or zero to indicate end of stream</returns>
virtual int Read(uint8_t* dataBuffer, uint32_t size) = 0;
/// <summary>
/// This function is called to synchronously to get meta information associated to stream data, such as TimeStamp or UserId .
/// Added in version 1.5.0.
/// </summary>
/// <param name="id">The id of the property.</param>
/// <returns>The value of the property.</returns>
virtual SPXSTRING GetProperty(PropertyId id)
{
if (PropertyId::DataBuffer_TimeStamp == id)
{
return "";
}
else if (PropertyId::DataBuffer_UserId == id)
{
return "";
}
else
{
return "";
}
}
/// <summary>
/// This function is called to close the audio stream.
/// </summary>
/// <returns></returns>
virtual void Close() = 0;
protected:
/*! \cond PROTECTED */
/// <summary>
/// Constructor, does nothing.
/// </summary>
PullAudioInputStreamCallback() {};
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(PullAudioInputStreamCallback);
};
/// <summary>
/// Pull audio input stream class.
/// </summary>
class PullAudioInputStream : public AudioInputStream
{
public:
/// <summary>
/// Creates a PullAudioInputStream utilizing the specified Read() and Close() "C" callback functions pointers
/// Note: The dataBuffer returned by Read() should not contain any audio header.
/// </summary>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback = nullptr)
{
return Create(nullptr, pvContext, readCallback, closeCallback);
}
/// <summary>
/// Creates a PullAudioInputStream utilizing the specified Read(), Close() and GetProperty() "C" callback functions pointers
/// Note: The dataBuffer returned by Read() should not contain any audio header.
/// Added in version 1.5.0.
/// </summary>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <param name="getPropertyCallback">Get property callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback, CUSTOM_AUDIO_PULL_STREAM_GET_PROPERTY_CALLBACK getPropertyCallback)
{
return Create(nullptr, pvContext, readCallback, closeCallback, getPropertyCallback);
}
/// Creates a PullAudioInputStream utilizing the specified Read() and Close() callback functions.
/// Note: The dataBuffer returned by Read() should not contain any audio header.
/// </summary>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback = nullptr)
{
return Create(nullptr, readCallback, closeCallback);
}
/// <summary>
/// Creates a PullAudioInputStream utilizing the specified Read(), Close() and GetProperty() callback functions.
/// Note: The dataBuffer returned by Read() should not contain any audio header.
/// Added in version 1.5.0.
/// </summary>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <param name="getPropertyCallback">Get property callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback, GetPropertyCallbackFunction_Type getPropertyCallback)
{
return Create(nullptr, readCallback, closeCallback, getPropertyCallback);
}
/// <summary>
/// Creates a PullAudioInputStream utilizing the specified Close() callback function.
/// </summary>
/// <param name="callback">Shared pointer to PullAudioInputStreamCallback instance.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(std::shared_ptr<PullAudioInputStreamCallback> callback)
{
return Create(nullptr, callback);
}
/// <summary>
/// Creates a PullAudioInputStream utilizing the specified Read() and Close() "C" callback functions pointers
/// Note: The dataBuffer returned by Read() should not contain any audio header.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(std::shared_ptr<AudioStreamFormat> format, void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback = nullptr)
{
return Create(format,
[=](uint8_t* buffer, uint32_t size) -> int { return readCallback(pvContext, buffer, size); },
[=]() { if (closeCallback != nullptr) { closeCallback(pvContext); } });
}
/// <summary>
/// Creates a PullAudioInputStream utilizing the specified Read(), Close() and GetProperty() "C" callback functions pointers
/// Note: The dataBuffer returned by Read() should not contain any audio header.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <param name="getPropertyCallback">Get property callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(std::shared_ptr<AudioStreamFormat> format, void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback, CUSTOM_AUDIO_PULL_STREAM_GET_PROPERTY_CALLBACK getPropertyCallback)
{
return Create(format,
[=](uint8_t* buffer, uint32_t size) -> int { return readCallback(pvContext, buffer, size); },
[=]() { if (closeCallback != nullptr) { closeCallback(pvContext); } },
[=](PropertyId id) -> SPXSTRING
{
uint8_t result[m_maxPropertyLen];
getPropertyCallback(pvContext, static_cast<int>(id), result, m_maxPropertyLen);
return reinterpret_cast<char*>(result);
});
}
/// <summary>
/// Creates a PullAudioInputStream utilizing the specified Read() and Close() callback functions.
/// Note: The dataBuffer returned by Read() should not contain any audio header.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(std::shared_ptr<AudioStreamFormat> format, ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback = nullptr)
{
auto wrapper = std::make_shared<FunctionCallbackWrapper>(readCallback, closeCallback);
return Create(format, wrapper);
}
/// <summary>
/// Creates a PullAudioInputStream utilizing the specified Read(), Close() and GetProperty() callback functions.
/// Note: The dataBuffer returned by Read() should not contain any audio header.
/// Added in version 1.5.0.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="readCallback">Read callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <param name="getPropertyCallback">Get property callback.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(std::shared_ptr<AudioStreamFormat> format, ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback, GetPropertyCallbackFunction_Type getPropertyCallback)
{
auto wrapper = std::make_shared<FunctionCallbackWrapper>(readCallback, closeCallback, getPropertyCallback);
return Create(format, wrapper);
}
/// <summary>
/// Creates a PullAudioInputStream utilizing the specified Read() and Close() callback functions.
/// </summary>
/// <param name="format">Audio stream format.</param>
/// <param name="callback">Shared pointer to PullAudioInputStreamCallback instance.</param>
/// <returns>A shared pointer to PullAudioInputStream</returns>
static std::shared_ptr<PullAudioInputStream> Create(std::shared_ptr<AudioStreamFormat> format, std::shared_ptr<PullAudioInputStreamCallback> callback)
{
format = UseDefaultFormatIfNull(format);
SPXAUDIOSTREAMHANDLE haudioStream = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_stream_create_pull_audio_input_stream(&haudioStream, GetFormatHandle(format)));
auto stream = new PullAudioInputStream(haudioStream);
SPX_THROW_ON_FAIL(pull_audio_input_stream_set_callbacks(haudioStream, stream, ReadCallbackWrapper, CloseCallbackWrapper));
SPX_THROW_ON_FAIL(pull_audio_input_stream_set_getproperty_callback(haudioStream, stream, GetPropertyCallbackWrapper));
stream->m_callback = callback;
return std::shared_ptr<PullAudioInputStream>(stream);
}
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit PullAudioInputStream(SPXAUDIOSTREAMHANDLE haudioStream) : AudioInputStream(haudioStream) { }
class FunctionCallbackWrapper : public PullAudioInputStreamCallback
{
public:
FunctionCallbackWrapper(ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback, GetPropertyCallbackFunction_Type getPropertyCallback = nullptr) :
m_readCallback(readCallback),
m_closeCallback(closeCallback),
m_getPropertyCallback(getPropertyCallback)
{
};
/// Note: The dataBuffer returned by Read() should not contain any audio header.
int Read(uint8_t* dataBuffer, uint32_t size) override { return m_readCallback(dataBuffer, size); }
void Close() override { if (m_closeCallback != nullptr) m_closeCallback(); };
SPXSTRING GetProperty(PropertyId id) override
{
if (m_getPropertyCallback != nullptr)
{
return m_getPropertyCallback(id);
}
else
{
return "";
}
}
private:
DISABLE_COPY_AND_MOVE(FunctionCallbackWrapper);
ReadCallbackFunction_Type m_readCallback;
CloseCallbackFunction_Type m_closeCallback;
GetPropertyCallbackFunction_Type m_getPropertyCallback;
};
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(PullAudioInputStream);
static int ReadCallbackWrapper(void* pvContext, uint8_t* dataBuffer, uint32_t size)
{
PullAudioInputStream* ptr = (PullAudioInputStream*)pvContext;
return ptr->m_callback->Read(dataBuffer, size);
}
static void CloseCallbackWrapper(void* pvContext)
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
PullAudioInputStream* ptr = (PullAudioInputStream*)pvContext;
ptr->m_callback->Close();
}
static void GetPropertyCallbackWrapper(void *pvContext, int id, uint8_t* result, uint32_t size)
{
PullAudioInputStream* ptr = (PullAudioInputStream*)pvContext;
auto value = ptr->m_callback->GetProperty(static_cast<PropertyId>(id));
auto valueSize = value.size() + 1;
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, valueSize > size);
std::memcpy(result, value.c_str(), valueSize);
}
std::shared_ptr<PullAudioInputStreamCallback> m_callback;
};
inline std::shared_ptr<PushAudioInputStream> AudioInputStream::CreatePushStream()
{
return PushAudioInputStream::Create();
}
inline std::shared_ptr<PushAudioInputStream> AudioInputStream::CreatePushStream(std::shared_ptr<AudioStreamFormat> format)
{
return PushAudioInputStream::Create(format);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback)
{
return PullAudioInputStream::Create(pvContext, readCallback, closeCallback);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback, CUSTOM_AUDIO_PULL_STREAM_GET_PROPERTY_CALLBACK getPropertyCallback)
{
return PullAudioInputStream::Create(pvContext, readCallback, closeCallback, getPropertyCallback);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback)
{
return PullAudioInputStream::Create(readCallback, closeCallback);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback, GetPropertyCallbackFunction_Type getPropertyCallback)
{
return PullAudioInputStream::Create(readCallback, closeCallback, getPropertyCallback);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(std::shared_ptr<PullAudioInputStreamCallback> callback)
{
return PullAudioInputStream::Create(callback);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(std::shared_ptr<AudioStreamFormat> format, void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback)
{
return PullAudioInputStream::Create(format, pvContext, readCallback, closeCallback);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(std::shared_ptr<AudioStreamFormat> format, void* pvContext, CUSTOM_AUDIO_PULL_STREAM_READ_CALLBACK readCallback, CUSTOM_AUDIO_PULL_STREAM_CLOSE_CALLBACK closeCallback, CUSTOM_AUDIO_PULL_STREAM_GET_PROPERTY_CALLBACK getPropertyCallback)
{
return PullAudioInputStream::Create(format, pvContext, readCallback, closeCallback, getPropertyCallback);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(std::shared_ptr<AudioStreamFormat> format, ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback)
{
return PullAudioInputStream::Create(format, readCallback, closeCallback);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(std::shared_ptr<AudioStreamFormat> format, ReadCallbackFunction_Type readCallback, CloseCallbackFunction_Type closeCallback, GetPropertyCallbackFunction_Type getPropertyCallback)
{
return PullAudioInputStream::Create(format, readCallback, closeCallback, getPropertyCallback);
}
inline std::shared_ptr<PullAudioInputStream> AudioInputStream::CreatePullStream(std::shared_ptr<AudioStreamFormat> format, std::shared_ptr<PullAudioInputStreamCallback> callback)
{
return PullAudioInputStream::Create(format, callback);
}
/// <summary>
/// Represents audio output stream used for custom audio output configurations.
/// Updated in version 1.7.0
/// </summary>
class AudioOutputStream
{
public:
using WriteCallbackFunction_Type = ::std::function<int(uint8_t*, uint32_t)>;
using CloseCallbackFunction_Type = ::std::function<void()>;
/// <summary>
/// Internal operator used to get underlying handle value.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXAUDIOSTREAMHANDLE() const { return m_haudioStream.get(); }
/// <summary>
/// Creates a memory backed PullAudioOutputStream.
/// </summary>
/// <returns>A shared pointer to PullAudioOutputStream</returns>
static std::shared_ptr<PullAudioOutputStream> CreatePullStream();
/// <summary>
/// Creates a PushAudioOutputStream that delegates to the specified callback functions for Write() and Close() methods.
/// </summary>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="writeCallback">Write callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PushAudioOutputStream</returns>
static std::shared_ptr<PushAudioOutputStream> CreatePushStream(void* pvContext, CUSTOM_AUDIO_PUSH_STREAM_WRITE_CALLBACK writeCallback, CUSTOM_AUDIO_PUSH_STREAM_CLOSE_CALLBACK closeCallback = nullptr);
/// <summary>
/// Creates a PushAudioOutputStream that delegates to the specified callback functions for Write() and Close() methods.
/// </summary>
/// <param name="writeCallback">Write callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PushAudioOutputStream</returns>
static std::shared_ptr<PushAudioOutputStream> CreatePushStream(WriteCallbackFunction_Type writeCallback, CloseCallbackFunction_Type closeCallback = nullptr);
/// <summary>
/// Creates a PushAudioOutputStream that delegates to the specified callback interface for Write() and Close() methods.
/// </summary>
/// <param name="callback">Shared pointer to PushAudioOutputStreamCallback instance.</param>
/// <returns>A shared pointer to PushAudioOutputStream</returns>
static std::shared_ptr<PushAudioOutputStream> CreatePushStream(std::shared_ptr<PushAudioOutputStreamCallback> callback);
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit AudioOutputStream(SPXAUDIOSTREAMHANDLE haudioStream) : m_haudioStream(haudioStream) { }
/// <summary>
/// Destructor, does nothing.
/// </summary>
virtual ~AudioOutputStream() {}
/// <summary>
/// Internal member variable that holds the smart handle.
/// </summary>
SmartHandle<SPXAUDIOSTREAMHANDLE, &audio_stream_release> m_haudioStream;
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(AudioOutputStream);
};
/// <summary>
/// Represents memory backed pull audio output stream used for custom audio output.
/// Updated in version 1.7.0
/// </summary>
class PullAudioOutputStream : public AudioOutputStream
{
public:
friend class Dialog::ActivityReceivedEventArgs;
/// <summary>
/// Creates a memory backed PullAudioOutputStream.
/// </summary>
/// <returns>A shared pointer to PullAudioOutputStream</returns>
static std::shared_ptr<PullAudioOutputStream> Create()
{
SPXAUDIOSTREAMHANDLE haudioStream = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_stream_create_pull_audio_output_stream(&haudioStream));
auto stream = new PullAudioOutputStream(haudioStream);
return std::shared_ptr<PullAudioOutputStream>(stream);
}
/// <summary>
/// Reads a chunk of the audio data and fill it to given buffer
/// </summary>
/// <param name="buffer">A buffer to receive read data.</param>
/// <param name="bufferSize">Size of the buffer.</param>
/// <returns>Size of data filled to the buffer, 0 means end of stream</returns>
inline uint32_t Read(uint8_t* buffer, uint32_t bufferSize)
{
uint32_t filledSize = 0;
SPX_THROW_ON_FAIL(pull_audio_output_stream_read(m_haudioStream, buffer, bufferSize, &filledSize));
return filledSize;
}
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit PullAudioOutputStream(SPXAUDIOSTREAMHANDLE haudioStream) : AudioOutputStream(haudioStream) { }
/*! \endcond */
private:
template <class T>
static std::shared_ptr<T> SpxAllocSharedBuffer(size_t sizeInBytes)
{
auto ptr = reinterpret_cast<T*>(new uint8_t[sizeInBytes]);
auto deleter = [](T* p) { delete[] reinterpret_cast<uint8_t*>(p); };
std::shared_ptr<T> buffer(ptr, deleter);
return buffer;
}
private:
DISABLE_COPY_AND_MOVE(PullAudioOutputStream);
std::vector<uint8_t> m_audioData;
};
/// <summary>
/// An interface that defines callback methods for an audio output stream.
/// Updated in version 1.7.0
/// </summary>
/// <remarks>
/// Derive from this class and implement its function to provide your own
/// data as an audio output stream.
/// <remarks>
class PushAudioOutputStreamCallback
{
public:
/// <summary>
/// Destructor, does nothing.
/// </summary>
virtual ~PushAudioOutputStreamCallback() {}
/// <summary>
/// This function is called to synchronously put data to the audio stream.
/// </summary>
/// <param name="dataBuffer">The pointer to the buffer from which to consume the audio data.</param>
/// <param name="size">The size of the buffer.</param>
/// <returns>The number of bytes consumed from the buffer</returns>
virtual int Write(uint8_t* dataBuffer, uint32_t size) = 0;
/// <summary>
/// This function is called to close the audio stream.
/// </summary>
/// <returns></returns>
virtual void Close() = 0;
protected:
/*! \cond PROTECTED */
/// <summary>
/// Constructor, does nothing.
/// </summary>
PushAudioOutputStreamCallback() {};
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(PushAudioOutputStreamCallback);
};
/// <summary>
/// Push audio output stream class.
/// Added in version 1.4.0
/// </summary>
class PushAudioOutputStream : public AudioOutputStream
{
public:
/// <summary>
/// Creates a PushAudioOutputStream utilizing the specified Write() and Close() "C" callback functions pointers
/// </summary>
/// <param name="pvContext">Context pointer to use when invoking the callbacks.</param>
/// <param name="writeCallback">Write callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PushAudioOutputStream</returns>
static std::shared_ptr<PushAudioOutputStream> Create(void* pvContext, CUSTOM_AUDIO_PUSH_STREAM_WRITE_CALLBACK writeCallback, CUSTOM_AUDIO_PUSH_STREAM_CLOSE_CALLBACK closeCallback = nullptr)
{
return Create(
[=](uint8_t* buffer, uint32_t size) -> int { return writeCallback(pvContext, buffer, size); },
[=]() { if (closeCallback != nullptr) { closeCallback(pvContext); } });
}
/// <summary>
/// Creates a PushAudioOutputStream utilizing the specified Write() and Close() callback functions.
/// </summary>
/// <param name="writeCallback">Write callback.</param>
/// <param name="closeCallback">Close callback.</param>
/// <returns>A shared pointer to PushAudioOutputStream</returns>
static std::shared_ptr<PushAudioOutputStream> Create(WriteCallbackFunction_Type writeCallback, CloseCallbackFunction_Type closeCallback = nullptr)
{
auto wrapper = std::make_shared<FunctionCallbackWrapper>(writeCallback, closeCallback);
return Create(wrapper);
}
/// <summary>
/// Creates a PushAudioOutputStream utilizing the specified callback interface with Write() and Close() callback function.
/// </summary>
/// <param name="callback">Shared pointer to PushAudioOutputStreamCallback instance.</param>
/// <returns>A shared pointer to PushAudioOutputStream</returns>
static std::shared_ptr<PushAudioOutputStream> Create(std::shared_ptr<PushAudioOutputStreamCallback> callback)
{
SPXAUDIOSTREAMHANDLE haudioStream = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_stream_create_push_audio_output_stream(&haudioStream));
auto stream = new PushAudioOutputStream(haudioStream);
SPX_THROW_ON_FAIL(push_audio_output_stream_set_callbacks(haudioStream, stream, WriteCallbackWrapper, CloseCallbackWrapper));
stream->m_callback = callback;
return std::shared_ptr<PushAudioOutputStream>(stream);
}
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit PushAudioOutputStream(SPXAUDIOSTREAMHANDLE haudioStream) : AudioOutputStream(haudioStream) { }
class FunctionCallbackWrapper : public PushAudioOutputStreamCallback
{
public:
FunctionCallbackWrapper(WriteCallbackFunction_Type writeCallback, CloseCallbackFunction_Type closeCallback) :
m_writeCallback(writeCallback),
m_closeCallback(closeCallback)
{
};
int Write(uint8_t* dataBuffer, uint32_t size) override { return m_writeCallback(dataBuffer, size); }
void Close() override { if (m_closeCallback != nullptr) m_closeCallback(); };
private:
DISABLE_COPY_AND_MOVE(FunctionCallbackWrapper);
WriteCallbackFunction_Type m_writeCallback;
CloseCallbackFunction_Type m_closeCallback;
};
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(PushAudioOutputStream);
static int WriteCallbackWrapper(void* pvContext, uint8_t* dataBuffer, uint32_t size)
{
PushAudioOutputStream* ptr = (PushAudioOutputStream*)pvContext;
return ptr->m_callback->Write(dataBuffer, size);
}
static void CloseCallbackWrapper(void* pvContext)
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
PushAudioOutputStream* ptr = (PushAudioOutputStream*)pvContext;
ptr->m_callback->Close();
}
std::shared_ptr<PushAudioOutputStreamCallback> m_callback;
};
inline std::shared_ptr<PullAudioOutputStream> AudioOutputStream::CreatePullStream()
{
return PullAudioOutputStream::Create();
}
inline std::shared_ptr<PushAudioOutputStream> AudioOutputStream::CreatePushStream(void* pvContext, CUSTOM_AUDIO_PUSH_STREAM_WRITE_CALLBACK writeCallback, CUSTOM_AUDIO_PUSH_STREAM_CLOSE_CALLBACK closeCallback)
{
return PushAudioOutputStream::Create(pvContext, writeCallback, closeCallback);
}
inline std::shared_ptr<PushAudioOutputStream> AudioOutputStream::CreatePushStream(WriteCallbackFunction_Type writeCallback, CloseCallbackFunction_Type closeCallback)
{
return PushAudioOutputStream::Create(writeCallback, closeCallback);
}
inline std::shared_ptr<PushAudioOutputStream> AudioOutputStream::CreatePushStream(std::shared_ptr<PushAudioOutputStreamCallback> callback)
{
return PushAudioOutputStream::Create(callback);
}
} } } } // Microsoft::CognitiveServices::Speech::Audio

215
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_audio_stream_format.h

@ -0,0 +1,215 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_audio_stream_format.h: Public API declarations for AudioStreamFormat and related C++ classes
//
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_smart_handle.h>
#include <speechapi_c_audio_stream_format.h>
#include <speechapi_cxx_enums.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Audio {
/// <summary>
/// Defines supported audio stream container format.
/// Changed in version 1.4.0.
/// </summary>
enum class AudioStreamContainerFormat
{
/// <summary>
/// Stream ContainerFormat definition for OGG OPUS.
/// </summary>
OGG_OPUS = 0x101,
/// <summary>
/// Stream ContainerFormat definition for MP3.
/// </summary>
MP3 = 0x102,
/// <summary>
/// Stream ContainerFormat definition for FLAC. Added in version 1.7.0.
/// </summary>
FLAC = 0x103,
/// <summary>
/// Stream ContainerFormat definition for ALAW. Added in version 1.7.0.
/// </summary>
ALAW = 0x104,
/// <summary>
/// Stream ContainerFormat definition for MULAW. Added in version 1.7.0.
/// </summary>
MULAW = 0x105,
/// <summary>
/// Stream ContainerFormat definition for AMRNB. Currently not supported.
/// </summary>
AMRNB = 0x106,
/// <summary>
/// Stream ContainerFormat definition for AMRWB. Currently not supported.
/// </summary>
AMRWB = 0x107,
/// <summary>
/// Stream ContainerFormat definition for any other or unknown format.
/// </summary>
ANY = 0x108
};
/// <summary>
/// Represents the format specified inside WAV container.
/// </summary>
enum class AudioStreamWaveFormat
{
/// <summary>
/// AudioStreamWaveFormat definition for PCM (pulse-code modulated) data in integer format.
/// </summary>
PCM = 0x0001,
/// <summary>
/// AudioStreamWaveFormat definition A-law-encoded format.
/// </summary>
ALAW = 0x0006,
/// <summary>
/// AudioStreamWaveFormat definition for Mu-law-encoded format.
/// </summary>
MULAW = 0x0007,
/// <summary>
/// AudioStreamWaveFormat definition for G.722-encoded format.
/// </summary>
G722 = 0x028F
};
/// <summary>
/// Class to represent the audio stream format used for custom audio input configurations.
/// Updated in version 1.5.0.
/// </summary>
class AudioStreamFormat
{
public:
/// <summary>
/// Destructor, does nothing.
/// </summary>
virtual ~AudioStreamFormat() {}
/// <summary>
/// Internal operator used to get underlying handle value.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXAUDIOSTREAMFORMATHANDLE() const { return m_hformat.get(); }
/// <summary>
/// Creates an audio stream format object representing the default audio stream format (16 kHz, 16 bit, mono PCM).
/// </summary>
/// <returns>A shared pointer to AudioStreamFormat</returns>
static std::shared_ptr<AudioStreamFormat> GetDefaultInputFormat()
{
SPXAUDIOSTREAMFORMATHANDLE hformat = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_stream_format_create_from_default_input(&hformat));
auto format = new AudioStreamFormat(hformat);
return std::shared_ptr<AudioStreamFormat>(format);
}
/// <summary>
/// Creates an audio stream format object with the specified PCM waveformat characteristics.
/// </summary>
/// <param name="samplesPerSecond">Samples per second.</param>
/// <param name="bitsPerSample">Bits per sample.</param>
/// <param name="channels">Number of channels in the waveform-audio data.</param>
/// <param name="waveFormat">The format specified inside the WAV container.</param>
/// <returns>A shared pointer to AudioStreamFormat</returns>
static std::shared_ptr<AudioStreamFormat> GetWaveFormat(uint32_t samplesPerSecond, uint8_t bitsPerSample, uint8_t channels, AudioStreamWaveFormat waveFormat)
{
SPXAUDIOSTREAMFORMATHANDLE hformat = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_stream_format_create_from_waveformat(&hformat, samplesPerSecond, bitsPerSample, channels, (Audio_Stream_Wave_Format)waveFormat));
auto format = new AudioStreamFormat(hformat);
return std::shared_ptr<AudioStreamFormat>(format);
}
/// <summary>
/// Creates an audio stream format object with the specified PCM waveformat characteristics.
/// </summary>
/// <param name="samplesPerSecond">Samples per second.</param>
/// <param name="bitsPerSample">Bits per sample.</param>
/// <param name="channels">Number of channels in the waveform-audio data.</param>
/// <returns>A shared pointer to AudioStreamFormat</returns>
static std::shared_ptr<AudioStreamFormat> GetWaveFormatPCM(uint32_t samplesPerSecond, uint8_t bitsPerSample = 16, uint8_t channels = 1)
{
SPXAUDIOSTREAMFORMATHANDLE hformat = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_stream_format_create_from_waveformat(&hformat, samplesPerSecond, bitsPerSample, channels, Audio_Stream_Wave_Format::StreamWaveFormat_PCM));
auto format = new AudioStreamFormat(hformat);
return std::shared_ptr<AudioStreamFormat>(format);
}
/// <summary>
/// Creates an audio stream format object representing the default audio stream format (16 kHz, 16 bit, mono PCM).
/// Added in version 1.4.0
/// </summary>
/// <returns>A shared pointer to AudioStreamFormat</returns>
static std::shared_ptr<AudioStreamFormat> GetDefaultOutputFormat()
{
SPXAUDIOSTREAMFORMATHANDLE hformat = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_stream_format_create_from_default_output(&hformat));
auto format = new AudioStreamFormat(hformat);
return std::shared_ptr<AudioStreamFormat>(format);
}
/// <summary>
/// Creates an audio stream format object with the specified compressed audio container format, to be used as input format.
/// Support added in 1.4.0.
/// </summary>
/// <remarks>
/// Formats are defined in AudioStreamContainerFormat enum.
/// </remarks>
/// <param name="compressedFormat">Compressed format type.</param>
/// <returns>A shared pointer to AudioStreamFormat.</returns>
static std::shared_ptr<AudioStreamFormat> GetCompressedFormat(AudioStreamContainerFormat compressedFormat)
{
SPXAUDIOSTREAMFORMATHANDLE hformat = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(audio_stream_format_create_from_compressed_format(&hformat, (Audio_Stream_Container_Format)compressedFormat));
auto format = new AudioStreamFormat(hformat);
return std::shared_ptr<AudioStreamFormat>(format);
}
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit AudioStreamFormat(SPXAUDIOSTREAMFORMATHANDLE hformat) : m_hformat(hformat) { }
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(AudioStreamFormat);
/// <summary>
/// Internal member variable that holds the smart handle.
/// </summary>
SmartHandle<SPXAUDIOSTREAMFORMATHANDLE, &audio_stream_format_release> m_hformat;
};
} } } } // Microsoft::CognitiveServices::Speech::Audio

141
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_auto_detect_source_lang_config.h

@ -0,0 +1,141 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <string>
#include <sstream>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_properties.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_utils.h>
#include <speechapi_c_auto_detect_source_lang_config.h>
#include <speechapi_cxx_source_lang_config.h>
#include <stdarg.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Class that defines auto detection source configuration
/// Updated in 1.13.0
/// </summary>
class AutoDetectSourceLanguageConfig
{
public:
/// <summary>
/// Internal operator used to get underlying handle value.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXAUTODETECTSOURCELANGCONFIGHANDLE() const { return m_hconfig; }
/// <summary>
/// Creates an instance of the AutoDetectSourceLanguageConfig with open range as source languages
/// Note: only <see cref="SpeechSynthesizer"/>, embedded speech translation and multilingual <see cref="TranslationRecognizer"/> support source language auto detection from open range,
/// for <see cref="Recognizer"/>, please use AutoDetectSourceLanguageConfig with specific source languages.
/// Added in 1.13.0
/// </summary>
/// <returns>A shared pointer to the new AutoDetectSourceLanguageConfig instance.</returns>
static std::shared_ptr<AutoDetectSourceLanguageConfig> FromOpenRange()
{
SPXAUTODETECTSOURCELANGCONFIGHANDLE hconfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(create_auto_detect_source_lang_config_from_open_range(&hconfig));
auto ptr = new AutoDetectSourceLanguageConfig(hconfig);
return std::shared_ptr<AutoDetectSourceLanguageConfig>(ptr);
}
/// <summary>
/// Creates an instance of the AutoDetectSourceLanguageConfig with source languages
/// </summary>
/// <param name="languages">The list of source languages.</param>
/// <returns>A shared pointer to the new AutoDetectSourceLanguageConfig instance.</returns>
static std::shared_ptr<AutoDetectSourceLanguageConfig> FromLanguages(const std::vector<SPXSTRING>& languages)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, languages.empty());
SPXAUTODETECTSOURCELANGCONFIGHANDLE hconfig = SPXHANDLE_INVALID;
std::string languagesStr;
bool isFirst = true;
for (const SPXSTRING& language : languages)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, language.empty());
if (!isFirst)
{
languagesStr += ",";
}
isFirst = false;
languagesStr += Utils::ToUTF8(language);
}
SPX_THROW_ON_FAIL(create_auto_detect_source_lang_config_from_languages(&hconfig, languagesStr.c_str()));
auto ptr = new AutoDetectSourceLanguageConfig(hconfig);
return std::shared_ptr<AutoDetectSourceLanguageConfig>(ptr);
}
/// <summary>
/// Creates an instance of the AutoDetectSourceLanguageConfig with a list of source language config
/// </summary>
/// <param name="configList">The list of source languages config</param>
/// <returns>A shared pointer to the new AutoDetectSourceLanguageConfig instance.</returns>
static std::shared_ptr<AutoDetectSourceLanguageConfig> FromSourceLanguageConfigs(std::vector<std::shared_ptr<Microsoft::CognitiveServices::Speech::SourceLanguageConfig>> configList)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, configList.empty());
SPXAUTODETECTSOURCELANGCONFIGHANDLE hconfig = SPXHANDLE_INVALID;
bool isFirst = true;
for (const auto& config : configList)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, config == nullptr);
if (isFirst)
{
SPX_THROW_ON_FAIL(create_auto_detect_source_lang_config_from_source_lang_config(&hconfig, Utils::HandleOrInvalid<SPXSOURCELANGCONFIGHANDLE, SourceLanguageConfig>(config)));
isFirst = false;
}
else
{
SPX_THROW_ON_FAIL(add_source_lang_config_to_auto_detect_source_lang_config(hconfig, Utils::HandleOrInvalid<SPXSOURCELANGCONFIGHANDLE, SourceLanguageConfig>(config)));
}
}
auto ptr = new AutoDetectSourceLanguageConfig(hconfig);
return std::shared_ptr<AutoDetectSourceLanguageConfig>(ptr);
}
/// <summary>
/// Destructs the object.
/// </summary>
virtual ~AutoDetectSourceLanguageConfig()
{
auto_detect_source_lang_config_release(m_hconfig);
property_bag_release(m_propertybag);
}
private:
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
explicit AutoDetectSourceLanguageConfig(SPXAUTODETECTSOURCELANGCONFIGHANDLE hconfig)
:m_hconfig(hconfig)
{
SPX_THROW_ON_FAIL(auto_detect_source_lang_config_get_property_bag(hconfig, &m_propertybag));
}
/// <summary>
/// Internal member variable that holds the config
/// </summary>
SPXAUTODETECTSOURCELANGCONFIGHANDLE m_hconfig;
/// <summary>
/// Internal member variable that holds the properties of the speech config
/// </summary>
SPXPROPERTYBAGHANDLE m_propertybag;
DISABLE_COPY_AND_MOVE(AutoDetectSourceLanguageConfig);
};
}}}

85
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_auto_detect_source_lang_result.h

@ -0,0 +1,85 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <string>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_c.h>
#include <speechapi_cxx_speech_recognition_result.h>
#include <speechapi_cxx_conversation_transcription_result.h>
#include <speechapi_cxx_translation_result.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Contains auto detected source language result
/// Added in 1.8.0
/// </summary>
class AutoDetectSourceLanguageResult
{
public:
/// <summary>
/// Creates an instance of AutoDetectSourceLanguageResult object for the speech recognition result.
/// </summary>
/// <param name="result">The speech recognition result.</param>
/// <returns>A shared pointer to AutoDetectSourceLanguageResult.</returns>
static std::shared_ptr<AutoDetectSourceLanguageResult> FromResult(std::shared_ptr<SpeechRecognitionResult> result)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, result == nullptr);
auto ptr = new AutoDetectSourceLanguageResult(result);
return std::shared_ptr<AutoDetectSourceLanguageResult>(ptr);
}
/// <summary>
/// Creates an instance of AutoDetectSourceLanguageResult object for the speech translation result.
/// </summary>
/// <param name="result">The speech translation result.</param>
/// <returns>A shared pointer to AutoDetectSourceLanguageResult.</returns>
static std::shared_ptr<AutoDetectSourceLanguageResult> FromResult(std::shared_ptr<Translation::TranslationRecognitionResult> result)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, result == nullptr);
auto ptr = new AutoDetectSourceLanguageResult(result);
return std::shared_ptr<AutoDetectSourceLanguageResult>(ptr);
}
/// <summary>
/// Creates an instance of AutoDetectSourceLanguageResult object for the convesation transcription result.
/// </summary>
/// <param name="result">The conversation transcription result.</param>
/// <returns>A shared pointer to AutoDetectSourceLanguageResult.</returns>
static std::shared_ptr<AutoDetectSourceLanguageResult> FromResult(std::shared_ptr<Microsoft::CognitiveServices::Speech::Transcription::ConversationTranscriptionResult> result)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, result == nullptr);
auto ptr = new AutoDetectSourceLanguageResult(result);
return std::shared_ptr<AutoDetectSourceLanguageResult>(ptr);
}
/// <summary>
/// The language value
/// If this is empty, it means the system fails to detect the source language automatically
/// </summary>
const SPXSTRING Language;
protected:
/*! \cond PROTECTED */
// Using RecognitionResult pointer, so this can cover all classes that inherit from RecognitionResult
AutoDetectSourceLanguageResult(std::shared_ptr<RecognitionResult> result) :
Language(result->Properties.GetProperty(PropertyId::SpeechServiceConnection_AutoDetectSourceLanguageResult))
{
}
/*! \endcond */
private:
DISABLE_DEFAULT_CTORS(AutoDetectSourceLanguageResult);
};
} } } // Microsoft::CognitiveServices::Speech

70
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_class_language_model.h

@ -0,0 +1,70 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_class_language_model.h: Public API declarations for ClassLanguageModel C++ class
//
#pragma once
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_smart_handle.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_grammar.h>
#include <speechapi_c.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Represents a list of grammars for dynamic grammar scenarios.
/// Added in version 1.7.0.
/// </summary>
/// <remarks>
/// ClassLanguageModels are only usable in specific scenarios and are not generally available.
/// </remarks>
class ClassLanguageModel : public Grammar
{
public:
/// <summary>
/// Creates a class language model from a storage ID.
/// </summary>
/// <param name="storageId)">The persisted storage ID of the language model.</param>
/// <returns>The grammar list associated with the recognizer.</returns>
/// <remarks>
/// Creating a ClassLanguageModel from a storage ID is only usable in specific scenarios and is not generally available.
/// </remarks>
static std::shared_ptr<ClassLanguageModel> FromStorageId(const SPXSTRING& storageId)
{
SPXGRAMMARHANDLE hgrammar = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(class_language_model_from_storage_id(&hgrammar, Utils::ToUTF8(storageId.c_str())));
return std::make_shared<ClassLanguageModel>(hgrammar);
}
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
/// <param name="hgrammar">Class Language Model handle.</param>
explicit ClassLanguageModel(SPXGRAMMARHANDLE hgrammar = SPXHANDLE_INVALID) : Grammar(hgrammar) { }
/// <summary>
/// Assigns a grammar to a class in the language mode.
/// </summary>
/// <param name="className">Name of the class to assign the grammar to.</param>
/// <param name="grammar">Grammar to assign.</param>
template <class T>
void AssignClass(const SPXSTRING& className, std::shared_ptr<T> grammar)
{
SPX_THROW_ON_FAIL(class_language_model_assign_class(m_hgrammar.get(), Utils::ToUTF8(className.c_str()), (SPXPHRASEHANDLE)(*grammar.get())));
}
private:
DISABLE_COPY_AND_MOVE(ClassLanguageModel);
};
} } } // Microsoft::CognitiveServices::Speech

16
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_common.h

@ -0,0 +1,16 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_common.h: Public API declarations for global C++ APIs/namespaces
//
#pragma once
#include <speechapi_c_common.h>
#include <speechapi_c_error.h>
#include <spxerror.h>
#include <azac_api_cxx_common.h> // must include after spxdebug.h or speechapi*.h (can NOT be included before)
#define DISABLE_COPY_AND_MOVE(T) AZAC_DISABLE_COPY_AND_MOVE(T)
#define DISABLE_DEFAULT_CTORS(T) AZAC_DISABLE_DEFAULT_CTORS(T)

346
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_connection.h

@ -0,0 +1,346 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_recognizer.h>
#include <speechapi_cxx_eventsignal.h>
#include <speechapi_cxx_connection_eventargs.h>
#include <speechapi_cxx_connection_message_eventargs.h>
#include <speechapi_c.h>
#include <speechapi_cxx_conversation_translator.h>
#include <speechapi_cxx_speech_synthesizer.h>
#include <speechapi_cxx_dialog_service_connector.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Connection is a proxy class for managing connection to the speech service of the specified Recognizer.
/// By default, a Recognizer autonomously manages connection to service when needed.
/// The Connection class provides additional methods for users to explicitly open or close a connection and
/// to subscribe to connection status changes.
/// The use of Connection is optional. It is intended for scenarios where fine tuning of application
/// behavior based on connection status is needed. Users can optionally call Open() to manually
/// initiate a service connection before starting recognition on the Recognizer associated with this Connection.
/// After starting a recognition, calling Open() or Close() might fail. This will not impact
/// the Recognizer or the ongoing recognition. Connection might drop for various reasons, the Recognizer will
/// always try to reinstitute the connection as required to guarantee ongoing operations. In all these cases
/// Connected/Disconnected events will indicate the change of the connection status.
/// Updated in version 1.17.0.
/// </summary>
class Connection : public std::enable_shared_from_this<Connection>
{
public:
/// <summary>
/// Gets the Connection instance from the specified recognizer.
/// </summary>
/// <param name="recognizer">The recognizer associated with the connection.</param>
/// <returns>The Connection instance of the recognizer.</returns>
static std::shared_ptr<Connection> FromRecognizer(std::shared_ptr<Recognizer> recognizer)
{
SPX_INIT_HR(hr);
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, recognizer == nullptr);
SPXCONNECTIONHANDLE handle = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(hr = ::connection_from_recognizer(recognizer->m_hreco, &handle));
return std::make_shared<Connection>(handle);
}
/// <summary>
/// Gets the Connection instance from the specified conversation translator.
/// </summary>
/// <param name="convTrans">The conversation translator associated with the connection.</param>
/// <returns>The Connection instance of the conversation translator.</returns>
static std::shared_ptr<Connection> FromConversationTranslator(std::shared_ptr<Transcription::ConversationTranslator> convTrans)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, convTrans == nullptr);
SPXCONNECTIONHANDLE handle = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(::connection_from_conversation_translator(convTrans->m_handle, &handle));
return std::make_shared<Connection>(handle);
}
/// <summary>
/// Gets the Connection instance from the specified dialog service connector, used for observing and managing
/// connection and disconnection from the speech service.
/// </summary>
/// <param name="dialogServiceConnector">The dialog service connector associated with the connection.</param>
/// <returns>The Connection instance of the dialog service connector.</returns>
static std::shared_ptr<Connection> FromDialogServiceConnector(std::shared_ptr<Dialog::DialogServiceConnector> dialogServiceConnector)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, dialogServiceConnector == nullptr);
SPXCONNECTIONHANDLE handle = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(::connection_from_dialog_service_connector(dialogServiceConnector->m_handle, &handle));
return std::make_shared<Connection>(handle);
}
/// <summary>
/// Gets the Connection instance from the specified speech synthesizer.
/// Added in version 1.17.0
/// </summary>
/// <param name="synthesizer">The speech synthesizer associated with the connection.</param>
/// <returns>The Connection instance of the speech synthesizer.</returns>
static std::shared_ptr<Connection> FromSpeechSynthesizer(std::shared_ptr<SpeechSynthesizer> synthesizer)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, synthesizer == nullptr);
SPXCONNECTIONHANDLE handle = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(::connection_from_speech_synthesizer(synthesizer->m_hsynth, &handle));
return std::make_shared<Connection>(handle);
}
/// <summary>
/// Starts to set up connection to the service.
/// Users can optionally call Open() to manually set up a connection in advance before starting recognition/synthesis on the
/// Recognizer/Synthesizer associated with this Connection. After starting recognition, calling Open() might fail, depending on
/// the process state of the Recognizer/Synthesizer. But the failure does not affect the state of the associated Recognizer/Synthesizer.
/// Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to
/// be notified when the connection is established.
/// </summary>
/// <param name="forContinuousRecognition">Indicates whether the connection is used for continuous recognition or single-shot recognition. It takes no effect if the connection is from SpeechSynthsizer.</param>
void Open(bool forContinuousRecognition)
{
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_connectionHandle == SPXHANDLE_INVALID);
SPX_THROW_ON_FAIL(::connection_open(m_connectionHandle, forContinuousRecognition));
}
/// <summary>
/// Closes the connection the service.
/// Users can optionally call Close() to manually shutdown the connection of the associated Recognizer/Synthesizer. The call
/// might fail, depending on the process state of the Recognizer/Synthesizer. But the failure does not affect the state of the
/// associated Recognizer/Synthesizer.
/// </summary>
void Close()
{
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_connectionHandle == SPXHANDLE_INVALID);
SPX_THROW_ON_FAIL(::connection_close(m_connectionHandle));
}
/// <summary>
/// Appends a parameter in a message to service.
/// Added in version 1.7.0.
/// </summary>
/// <param name="path">the message path.</param>
/// <param name="propertyName">Name of the property.</param>
/// <param name="propertyValue">Value of the property. This is a json string.</param>
/// <returns>void.</returns>
void SetMessageProperty(const SPXSTRING& path, const SPXSTRING& propertyName, const SPXSTRING& propertyValue)
{
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_connectionHandle == SPXHANDLE_INVALID);
SPX_THROW_ON_FAIL(::connection_set_message_property(m_connectionHandle, Utils::ToUTF8(path).c_str(), Utils::ToUTF8(propertyName).c_str(), Utils::ToUTF8(propertyValue).c_str()));
}
/// <summary>
/// Send a message to the speech service.
/// Added in version 1.7.0.
/// </summary>
/// <param name="path">The path of the message.</param>
/// <param name="payload">The payload of the message. This is a json string.</param>
/// <returns>An empty future.</returns>
std::future<void> SendMessageAsync(const SPXSTRING& path, const SPXSTRING& payload)
{
auto keep_alive = this->shared_from_this();
auto future = std::async(std::launch::async, [keep_alive, this, path, payload]() -> void {
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_connectionHandle == SPXHANDLE_INVALID);
SPX_THROW_ON_FAIL(::connection_send_message(m_connectionHandle, Utils::ToUTF8(path.c_str()), Utils::ToUTF8(payload.c_str())));
});
return future;
}
/// <summary>
/// Send a binary message to the speech service.
/// This method doesn't work for the connection of SpeechSynthesizer.
/// Added in version 1.10.0.
/// </summary>
/// <param name="path">The path of the message.</param>
/// <param name="payload">The binary payload of the message.</param>
/// <param name="size">The size of the binary payload.</param>
/// <returns>An empty future.</returns>
std::future<void> SendMessageAsync(const SPXSTRING& path, uint8_t* payload, uint32_t size)
{
auto keep_alive = this->shared_from_this();
auto future = std::async(std::launch::async, [keep_alive, this, path, payload, size]() -> void {
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_connectionHandle == SPXHANDLE_INVALID);
SPX_THROW_ON_FAIL(::connection_send_message_data(m_connectionHandle, Utils::ToUTF8(path.c_str()), payload, size));
});
return future;
}
/// <summary>
/// The Connected event to indicate that the recognizer is connected to service.
/// </summary>
EventSignal<const ConnectionEventArgs&> Connected;
/// <summary>
/// The Disconnected event to indicate that the recognizer is disconnected from service.
/// </summary>
EventSignal<const ConnectionEventArgs&> Disconnected;
/// <summary>
/// The MessageReceived event to indicate that the underlying protocol received a message from the service.
/// Added in version 1.10.0.
/// </summary>
EventSignal<const ConnectionMessageEventArgs&> MessageReceived;
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
/// <param name="handle">The connection handle.</param>
explicit Connection(SPXCONNECTIONHANDLE handle) :
Connected(GetConnectionEventConnectionsChangedCallback(), GetConnectionEventConnectionsChangedCallback()),
Disconnected(GetConnectionEventConnectionsChangedCallback(), GetConnectionEventConnectionsChangedCallback()),
MessageReceived(GetConnectionMessageEventConnectionsChangedCallback(), GetConnectionMessageEventConnectionsChangedCallback()),
m_connectionHandle(handle)
{
SPX_DBG_TRACE_FUNCTION();
}
/// <summary>
/// Destructor.
/// </summary>
~Connection()
{
SPX_DBG_TRACE_FUNCTION();
try
{
Disconnected.DisconnectAll();
Connected.DisconnectAll();
}
catch (const std::exception& ex)
{
SPX_TRACE_ERROR("Exception caught in ~Connection(): %s", ex.what());
(void)ex;
}
catch (...)
{
SPX_TRACE_ERROR("Unknown exception happened during ~Connection().");
}
if (m_connectionHandle != SPXHANDLE_INVALID)
{
::connection_handle_release(m_connectionHandle);
m_connectionHandle = SPXHANDLE_INVALID;
}
}
private:
DISABLE_COPY_AND_MOVE(Connection);
SPXCONNECTIONHANDLE m_connectionHandle;
static void FireConnectionEvent(bool firingConnectedEvent, SPXEVENTHANDLE event, void* context)
{
std::exception_ptr p;
try
{
std::unique_ptr<ConnectionEventArgs> connectionEvent{ new ConnectionEventArgs(event) };
auto connection = static_cast<Connection*>(context);
auto keepAlive = connection->shared_from_this();
if (firingConnectedEvent)
{
connection->Connected.Signal(*connectionEvent.get());
}
else
{
connection->Disconnected.Signal(*connectionEvent.get());
}
}
#ifdef SHOULD_HANDLE_FORCED_UNWIND
// Currently Python forcibly kills the thread by throwing __forced_unwind,
// taking care we propagate this exception further.
catch (abi::__forced_unwind&)
{
SPX_TRACE_ERROR("__forced_unwind exception caught in FireConnectionEvent.");
throw;
}
#endif
catch (...)
{
if (recognizer_event_handle_is_valid(event)) {
recognizer_event_handle_release(event);
}
SPX_TRACE_ERROR("Caught exception in FireConnectionEvent(%s). Will rethrow later.", firingConnectedEvent ? "Connected" : "Disconnected");
throw;
}
// ConnectionEventArgs doesn't hold hevent, and thus can't release it properly ... release it here
SPX_DBG_ASSERT(recognizer_event_handle_is_valid(event));
recognizer_event_handle_release(event);
}
static void FireEvent_Connected(SPXEVENTHANDLE event, void* context)
{
FireConnectionEvent(true, event, context);
}
static void FireEvent_Disconnected(SPXEVENTHANDLE event, void* context)
{
FireConnectionEvent(false, event, context);
}
static void FireEvent_MessageReceived(SPXEVENTHANDLE event, void* context)
{
std::unique_ptr<ConnectionMessageEventArgs> connectionEvent { new ConnectionMessageEventArgs(event) };
auto connection = static_cast<Connection*>(context);
auto keepAlive = connection->shared_from_this();
connection->MessageReceived.Signal(*connectionEvent.get());
}
void ConnectionEventConnectionsChanged(const EventSignal<const ConnectionEventArgs&>& connectionEvent)
{
if (m_connectionHandle != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_connectionHandle=0x%8p", __FUNCTION__, (void*)m_connectionHandle);
SPX_DBG_TRACE_VERBOSE_IF(!::connection_handle_is_valid(m_connectionHandle), "%s: m_connectionHandle is INVALID!!!", __FUNCTION__);
if (&connectionEvent == &Connected)
{
SPX_THROW_ON_FAIL(connection_connected_set_callback(m_connectionHandle, Connected.IsConnected() ? FireEvent_Connected : nullptr, this));
}
else if (&connectionEvent == &Disconnected)
{
SPX_THROW_ON_FAIL(connection_disconnected_set_callback(m_connectionHandle, Disconnected.IsConnected() ? FireEvent_Disconnected : nullptr, this));
}
}
}
void ConnectionMessageEventConnectionsChanged(const EventSignal<const ConnectionMessageEventArgs&>& connectionEvent)
{
if (m_connectionHandle != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_connectionHandle=0x%8p", __FUNCTION__, (void*)m_connectionHandle);
SPX_DBG_TRACE_VERBOSE_IF(!::connection_handle_is_valid(m_connectionHandle), "%s: m_connectionHandle is INVALID!!!", __FUNCTION__);
if (&connectionEvent == &MessageReceived)
{
SPX_THROW_ON_FAIL(connection_message_received_set_callback(m_connectionHandle, MessageReceived.IsConnected() ? FireEvent_MessageReceived : nullptr, this));
}
}
}
inline std::function<void(const EventSignal<const ConnectionEventArgs&>&)> GetConnectionEventConnectionsChangedCallback()
{
return [=, this](const EventSignal<const ConnectionEventArgs&>& connectionEvent) { this->ConnectionEventConnectionsChanged(connectionEvent); };
}
inline std::function<void(const EventSignal<const ConnectionMessageEventArgs&>&)> GetConnectionMessageEventConnectionsChangedCallback()
{
return [=, this](const EventSignal<const ConnectionMessageEventArgs&>& connectionEvent) { this->ConnectionMessageEventConnectionsChanged(connectionEvent); };
}
};
} } } // Microsoft::CognitiveServices::Speech

68
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_connection_eventargs.h

@ -0,0 +1,68 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <string>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_session_eventargs.h>
#include <speechapi_cxx_properties.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Provides data for the ConnectionEvent.
/// Added in version 1.2.0.
/// </summary>
class ConnectionEventArgs : public SessionEventArgs
{
protected:
/*! \cond PRIVATE */
class PrivatePropertyCollection : public PropertyCollection
{
public:
PrivatePropertyCollection(SPXEVENTHANDLE hevent) :
PropertyCollection([=]()
{
SPXPROPERTYBAGHANDLE hpropbag = SPXHANDLE_INVALID;
recognizer_connection_event_get_property_bag(hevent, &hpropbag);
return hpropbag;
}())
{}
};
PrivatePropertyCollection m_properties;
/*! \endcond */
public:
/// <summary>
/// Constructor.
/// </summary>
/// <param name="hevent">Event handle.</param>
explicit ConnectionEventArgs(SPXEVENTHANDLE hevent) :
SessionEventArgs(hevent),
m_properties(hevent),
Properties(m_properties)
{
};
/// <inheritdoc/>
virtual ~ConnectionEventArgs() {}
/// <summary>
/// Collection of additional properties.
/// </summary>
const PropertyCollection& Properties;
private:
DISABLE_COPY_AND_MOVE(ConnectionEventArgs);
};
} } } // Microsoft::CognitiveServices::Speech

152
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_connection_message.h

@ -0,0 +1,152 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_connection_message.h: Public API declarations for ConnectionMessage C++ class
//
#pragma once
#include <string>
#include <vector>
#include <speechapi_c_connection.h>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_properties.h>
#include <speechapi_cxx_session_eventargs.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// ConnectionMessage represents implementation specific messages sent to and received from
/// the speech service. These messages are provided for debugging purposes and should not
/// be used for production use cases with the Azure Cognitive Services Speech Service.
/// Messages sent to and received from the Speech Service are subject to change without
/// notice. This includes message contents, headers, payloads, ordering, etc.
/// Added in version 1.10.0.
/// </summary>
class ConnectionMessage
{
private:
/*! \cond PRIVATE */
class PrivatePropertyCollection : public PropertyCollection
{
public:
PrivatePropertyCollection(SPXCONNECTIONMESSAGEHANDLE hcm) :
PropertyCollection(
[=]() {
SPXPROPERTYBAGHANDLE hpropbag = SPXHANDLE_INVALID;
::connection_message_get_property_bag(hcm, &hpropbag);
return hpropbag;
}())
{
}
};
SPXCONNECTIONMESSAGEHANDLE m_hcm;
PrivatePropertyCollection m_properties;
/*! \endcond */
public:
/// <summary>
/// Constructor.
/// </summary>
/// <param name="hcm">Event handle.</param>
explicit ConnectionMessage(SPXCONNECTIONMESSAGEHANDLE hcm) :
m_hcm(hcm),
m_properties(hcm),
Properties(m_properties)
{
};
/// <summary>
/// Destructor.
/// </summary>
virtual ~ConnectionMessage()
{
SPX_DBG_TRACE_VERBOSE("%s (this=0x%p, handle=0x%p)", __FUNCTION__, (void*)this, (void*)m_hcm);
SPX_THROW_ON_FAIL(::connection_message_handle_release(m_hcm));
}
/// <summary>
/// Gets the message path.
/// </summary>
/// <returns>An std::string containing the message path.</returns>
std::string GetPath() const
{
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_hcm == SPXHANDLE_INVALID);
return m_properties.GetProperty("connection.message.path");
}
/// <summary>
/// Checks to see if the ConnectionMessage is a text message.
/// See also IsBinaryMessage().
/// </summary>
/// <returns>A bool indicated if the message payload is text.</returns>
bool IsTextMessage() const
{
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_hcm == SPXHANDLE_INVALID);
return m_properties.GetProperty("connection.message.type") == "text";
}
/// <summary>
/// Checks to see if the ConnectionMessage is a binary message.
/// See also GetBinaryMessage().
/// </summary>
/// <returns>A bool indicated if the message payload is binary.</returns>
bool IsBinaryMessage() const
{
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_hcm == SPXHANDLE_INVALID);
return m_properties.GetProperty("connection.message.type") == "binary";
}
/// <summary>
/// Gets the text message payload. Typically the text message content-type is
/// application/json. To determine other content-types use
/// Properties.GetProperty("Content-Type").
/// </summary>
/// <returns>An std::string containing the text message.</returns>
std::string GetTextMessage() const
{
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_hcm == SPXHANDLE_INVALID);
return m_properties.GetProperty("connection.message.text.message");
}
/// <summary>
/// Gets the binary message payload.
/// </summary>
/// <returns>An std::vector<uint8_t> containing the binary message.</returns>
std::vector<uint8_t> GetBinaryMessage() const
{
SPX_THROW_HR_IF(SPXERR_INVALID_HANDLE, m_hcm == SPXHANDLE_INVALID);
auto size = ::connection_message_get_data_size(m_hcm);
std::vector<uint8_t> message(size);
SPX_THROW_ON_FAIL(::connection_message_get_data(m_hcm, message.data(), size));
return message;
}
/// <summary>
/// A collection of properties and their values defined for this <see cref="ConnectionMessage"/>.
/// Message headers can be accessed via this collection (e.g. "Content-Type").
/// </summary>
PropertyCollection& Properties;
private:
/*! \cond PRIVATE */
DISABLE_COPY_AND_MOVE(ConnectionMessage);
/*! \endcond */
};
} } } // Microsoft::CognitiveServices::Speech

79
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_connection_message_eventargs.h

@ -0,0 +1,79 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_connection_message_eventargs.h: Public API declarations for ConnectionMessageEventArgs C++ base class
//
#pragma once
#include <string>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_properties.h>
#include <speechapi_cxx_eventargs.h>
#include <speechapi_cxx_connection_message.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Provides data for the ConnectionMessageEvent
/// </summary>
class ConnectionMessageEventArgs : public EventArgs
{
private:
/*! \cond PRIVATE */
SPXEVENTHANDLE m_hevent;
std::shared_ptr<ConnectionMessage> m_message;
/*! \endcond */
public:
/// <summary>
/// Constructor. Creates a new instance using the provided handle.
/// </summary>
/// <param name="hevent">Event handle.</param>
explicit ConnectionMessageEventArgs(SPXEVENTHANDLE hevent) :
m_hevent(hevent),
m_message(std::make_shared<ConnectionMessage>(MessageHandleFromEventHandle(hevent)))
{
};
/// <summary>
/// Destructor.
/// </summary>
virtual ~ConnectionMessageEventArgs()
{
SPX_THROW_ON_FAIL(::connection_message_received_event_handle_release(m_hevent));
}
/// <summary>
/// Gets the <see cref="ConnectionMessage"/> associated with this <see cref="ConnectionMessageEventArgs"/>.
/// </summary>
/// <returns>An `std::shared<ConnectionMessage>` containing the message.</returns>
std::shared_ptr<ConnectionMessage> GetMessage() const { return m_message; }
private:
/*! \cond PRIVATE */
DISABLE_COPY_AND_MOVE(ConnectionMessageEventArgs);
SPXCONNECTIONMESSAGEHANDLE MessageHandleFromEventHandle(SPXEVENTHANDLE hevent)
{
SPXCONNECTIONMESSAGEHANDLE hcm = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(::connection_message_received_event_get_message(hevent, &hcm));
return hcm;
}
/*! \endcond */
};
} } } // Microsoft::CognitiveServices::Speech

340
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation.h

@ -0,0 +1,340 @@
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_conversation.h: Public API declarations for Conversation C++ class
//
#pragma once
#include <exception>
#include <future>
#include <memory>
#include <string>
#include <cstring>
#include <speechapi_c.h>
#include <speechapi_cxx_speech_config.h>
#include <speechapi_cxx_utils.h>
#include <speechapi_cxx_properties.h>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_properties.h>
#include <speechapi_cxx_user.h>
#include <speechapi_cxx_participant.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Transcription {
/// <summary>
/// Class for conversation.
/// Added in version 1.8.0
/// </summary>
class Conversation : public std::enable_shared_from_this<Conversation>
{
public:
static constexpr size_t MAX_CONVERSATION_ID_LEN = 1024;
/// <summary>
/// Create a conversation using a speech config and an optional conversation id.
/// </summary>
/// <param name="speechConfig">A shared smart pointer of a speech config object.</param>
/// <param name="conversationId">Conversation Id.</param>
/// <returns>A shared smart pointer of the created conversation object.</returns>
static std::future<std::shared_ptr<Conversation>> CreateConversationAsync(std::shared_ptr<SpeechConfig> speechConfig, const SPXSTRING& conversationId = SPXSTRING())
{
auto future = std::async(std::launch::async, [conversationId, speechConfig]() -> std::shared_ptr<Conversation> {
SPXCONVERSATIONHANDLE hconversation;
SPX_THROW_ON_FAIL(conversation_create_from_config(&hconversation, (SPXSPEECHCONFIGHANDLE)(*speechConfig), Utils::ToUTF8(conversationId).c_str()));
return std::make_shared<Conversation>(hconversation);
});
return future;
}
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
/// <param name="hconversation">Recognizer handle.</param>
explicit Conversation(SPXCONVERSATIONHANDLE hconversation) :
m_hconversation(hconversation),
m_properties(hconversation),
Properties(m_properties)
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
}
/// <summary>
/// Destructor.
/// </summary>
~Conversation()
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
::conversation_release_handle(m_hconversation);
m_hconversation = SPXHANDLE_INVALID;
}
/// <summary>
/// Internal operator used to get underlying handle value.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXCONVERSATIONHANDLE () const { return m_hconversation; }
/// <summary>
/// Get the conversation id.
/// </summary>
/// <returns>Conversation id.</returns>
SPXSTRING GetConversationId()
{
char id[MAX_CONVERSATION_ID_LEN + 1];
std::memset(id, 0, MAX_CONVERSATION_ID_LEN);
SPX_THROW_ON_FAIL(conversation_get_conversation_id(m_hconversation, id, MAX_CONVERSATION_ID_LEN));
return id;
}
/// <summary>
/// Add a participant to a conversation using the user's id.
///
/// Note: The returned participant can be used to remove. If the client changes the participant's attributes,
/// the changed attributes are passed on to the service only when the participant is added again.
/// </summary>
/// <param name="userId">A user id.</param>
/// <returns>a shared smart pointer of the participant.</returns>
std::future<std::shared_ptr<Participant>> AddParticipantAsync(const SPXSTRING& userId)
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this, userId]() -> std::shared_ptr<Participant> {
const auto participant = Participant::From(userId);
SPX_THROW_ON_FAIL(conversation_update_participant(m_hconversation, true, (SPXPARTICIPANTHANDLE)(*participant)));
return participant;
});
return future;
}
/// <summary>
/// Add a participant to a conversation using the User object.
/// </summary>
/// <param name="user">A shared smart pointer to a User object.</param>
/// <returns>The passed in User object.</returns>
std::future<std::shared_ptr<User>> AddParticipantAsync(const std::shared_ptr<User>& user)
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this, user]() -> std::shared_ptr<User> {
SPX_THROW_ON_FAIL(conversation_update_participant_by_user(m_hconversation, true, (SPXUSERHANDLE)(*user)));
return user;
});
return future;
}
/// <summary>
/// Add a participant to a conversation using the participant object
/// </summary>
/// <param name="participant">A shared smart pointer to a participant object.</param>
/// <returns>The passed in participant object.</returns>
std::future<std::shared_ptr<Participant>> AddParticipantAsync(const std::shared_ptr<Participant>& participant)
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this, participant]() -> std::shared_ptr<Participant> {
SPX_THROW_ON_FAIL(conversation_update_participant(m_hconversation, true, (SPXPARTICIPANTHANDLE)(*participant)));
return participant;
});
return future;
}
/// <summary>
/// Remove a participant from a conversation using the participant object
/// </summary>
/// <param name="participant">A shared smart pointer of a participant object.</param>
/// <returns>An empty future.</returns>
std::future<void> RemoveParticipantAsync(const std::shared_ptr<Participant>& participant)
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this, participant]() -> void {
SPX_THROW_ON_FAIL(conversation_update_participant(m_hconversation, false, (SPXPARTICIPANTHANDLE)(*participant)));
});
return future;
}
/// <summary>
/// Remove a participant from a conversation using the User object
/// </summary>
/// <param name="user">A smart pointer of a User.</param>
/// <returns>An empty future.</returns>
std::future<void> RemoveParticipantAsync(const std::shared_ptr<User>& user)
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this, user]() -> void {
SPX_THROW_ON_FAIL(conversation_update_participant_by_user(m_hconversation, false, SPXUSERHANDLE(*user)));
});
return future;
}
/// <summary>
/// Remove a participant from a conversation using a user id string.
/// </summary>
/// <param name="userId">A user id.</param>
/// <returns>An empty future.</returns>
std::future<void> RemoveParticipantAsync(const SPXSTRING& userId)
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this, userId]() -> void {
SPX_THROW_ON_FAIL(conversation_update_participant_by_user_id(m_hconversation, false, Utils::ToUTF8(userId.c_str())));
});
return future;
}
/// <summary>
/// Ends the current conversation.
/// </summary>
/// <returns>An empty future.</returns>
std::future<void> EndConversationAsync()
{
return RunAsync(::conversation_end_conversation);
}
/// <summary>
/// Sets the authorization token that will be used for connecting the server.
/// </summary>
/// <param name="token">The authorization token.</param>
void SetAuthorizationToken(const SPXSTRING& token)
{
Properties.SetProperty(PropertyId::SpeechServiceAuthorization_Token, token);
}
/// <summary>
/// Gets the authorization token.
/// </summary>
/// <returns>Authorization token</returns>
SPXSTRING GetAuthorizationToken()
{
return Properties.GetProperty(PropertyId::SpeechServiceAuthorization_Token, SPXSTRING());
}
/// <summary>
/// Start the conversation.
/// </summary>
/// <returns>An empty future.</returns>
std::future<void> StartConversationAsync()
{
return RunAsync(::conversation_start_conversation);
}
/// <summary>
/// Deletes the conversation. Any participants that are still part of the converation
/// will be ejected after this call.
/// </summary>
/// <returns>An empty future.</returns>
std::future<void> DeleteConversationAsync()
{
return RunAsync(::conversation_delete_conversation);
}
/// <summary>
/// Locks the conversation. After this no new participants will be able to join.
/// </summary>
/// <returns>An empty future.</returns>
std::future<void> LockConversationAsync()
{
return RunAsync(::conversation_lock_conversation);
}
/// <summary>
/// Unlocks the conversation.
/// </summary>
/// <returns>An empty future.</returns>
std::future<void> UnlockConversationAsync()
{
return RunAsync(::conversation_unlock_conversation);
}
/// <summary>
/// Mutes all participants except for the host. This prevents others from generating
/// transcriptions, or sending text messages.
/// </summary>
/// <returns>An empty future.</returns>
std::future<void> MuteAllParticipantsAsync()
{
return RunAsync(::conversation_mute_all_participants);
}
/// <summary>
/// Allows other participants to generate transcriptions, or send text messages.
/// </summary>
/// <returns>An empty future.</returns>
std::future<void> UnmuteAllParticipantsAsync()
{
return RunAsync(::conversation_unmute_all_participants);
}
/// <summary>
/// Mutes a particular participant. This will prevent them generating new transcriptions,
/// or sending text messages.
/// </summary>
/// <param name="participantId">The identifier for the participant.</param>
/// <returns>An empty future.</returns>
std::future<void> MuteParticipantAsync(const SPXSTRING& participantId)
{
return RunAsync([participantId = Utils::ToUTF8(participantId)](auto handle)
{
return ::conversation_mute_participant(handle, participantId.c_str());
});
}
/// <summary>
/// Unmutes a particular participant.
/// </summary>
/// <param name="participantId">The identifier for the participant.</param>
/// <returns>An empty future.</returns>
std::future<void> UnmuteParticipantAsync(const SPXSTRING& participantId)
{
return RunAsync([participantId = Utils::ToUTF8(participantId)](auto handle)
{
return ::conversation_unmute_participant(handle, participantId.c_str());
});
}
private:
/*! \cond PRIVATE */
SPXCONVERSATIONHANDLE m_hconversation;
class PrivatePropertyCollection : public PropertyCollection
{
public:
PrivatePropertyCollection(SPXCONVERSATIONHANDLE hconv) :
PropertyCollection(
[=]() {
SPXPROPERTYBAGHANDLE hpropbag = SPXHANDLE_INVALID;
conversation_get_property_bag(hconv, &hpropbag);
return hpropbag;
}())
{
}
};
PrivatePropertyCollection m_properties;
inline std::future<void> RunAsync(std::function<SPXHR(SPXCONVERSATIONHANDLE)> func)
{
auto keepalive = this->shared_from_this();
return std::async(std::launch::async, [keepalive, this, func]()
{
SPX_THROW_ON_FAIL(func(m_hconversation));
});
}
/*! \endcond */
public:
/// <summary>
/// A collection of properties and their values defined for this <see cref="Conversation"/>.
/// </summary>
PropertyCollection& Properties;
};
}}}}

509
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_transcriber.h

@ -0,0 +1,509 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_conversation_transcriber.h: Public API declarations for ConversationTranscriber C++ class
//
#pragma once
#include <exception>
#include <future>
#include <memory>
#include <string>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_c.h>
#include <speechapi_cxx_recognizer.h>
#include <speechapi_cxx_conversation_transcription_eventargs.h>
#include <speechapi_cxx_conversation_transcription_result.h>
#include <speechapi_cxx_properties.h>
#include <speechapi_cxx_speech_config.h>
#include <speechapi_cxx_audio_stream.h>
#include <speechapi_cxx_auto_detect_source_lang_config.h>
#include <speechapi_cxx_source_lang_config.h>
#include <speechapi_cxx_audio_config.h>
#include <speechapi_cxx_utils.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Transcription {
class Session;
/// <summary>
/// Class for ConversationTranscribers.
/// </summary>
class ConversationTranscriber final : public Recognizer
{
public:
/// <summary>
/// Create a conversation transcriber from a speech config
/// </summary>
/// <param name="speechconfig">Speech configuration.</param>
/// <returns>A smart pointer wrapped conversation transcriber pointer.</returns>
static std::shared_ptr<ConversationTranscriber> FromConfig(std::shared_ptr<SpeechConfig> speechconfig, std::nullptr_t)
{
SPXRECOHANDLE hreco;
SPX_THROW_ON_FAIL(::recognizer_create_conversation_transcriber_from_config(
&hreco,
Utils::HandleOrInvalid<SPXSPEECHCONFIGHANDLE, SpeechConfig>(speechconfig),
Utils::HandleOrInvalid<SPXAUDIOCONFIGHANDLE, Audio::AudioConfig>(nullptr)));
return std::make_shared<ConversationTranscriber>(hreco);
}
/// <summary>
/// Create a conversation transcriber from a speech config and audio config.
/// </summary>
/// <param name="speechconfig">Speech configuration.</param>
/// <param name="audioInput">Audio configuration.</param>
/// <returns>A smart pointer wrapped conversation transcriber pointer.</returns>
static std::shared_ptr<ConversationTranscriber> FromConfig(std::shared_ptr<SpeechConfig> speechconfig, std::shared_ptr<Audio::AudioConfig> audioInput = nullptr)
{
SPXRECOHANDLE hreco;
SPX_THROW_ON_FAIL(::recognizer_create_conversation_transcriber_from_config(
&hreco,
Utils::HandleOrInvalid<SPXAUDIOCONFIGHANDLE,SpeechConfig>(speechconfig),
Utils::HandleOrInvalid<SPXAUDIOCONFIGHANDLE, Audio::AudioConfig>(audioInput)));
return std::make_shared<ConversationTranscriber>(hreco);
}
/// <summary>
/// Create a conversation transcriber from a speech config, auto detection source language config and audio config
/// </summary>
/// <param name="speechconfig">Speech configuration.</param>
/// <param name="autoDetectSourceLangConfig">Auto detection source language config.</param>
/// <param name="audioInput">Audio configuration.</param>
/// <returns>A smart pointer wrapped conversation trasncriber pointer.</returns>
static std::shared_ptr<ConversationTranscriber> FromConfig(
std::shared_ptr<SpeechConfig> speechconfig,
std::shared_ptr<AutoDetectSourceLanguageConfig> autoDetectSourceLangConfig,
std::shared_ptr<Audio::AudioConfig> audioInput = nullptr)
{
SPXRECOHANDLE hreco;
SPX_THROW_ON_FAIL(::recognizer_create_conversation_transcriber_from_auto_detect_source_lang_config(
&hreco,
Utils::HandleOrInvalid<SPXSPEECHCONFIGHANDLE, SpeechConfig>(speechconfig),
Utils::HandleOrInvalid<SPXAUTODETECTSOURCELANGCONFIGHANDLE, AutoDetectSourceLanguageConfig>(autoDetectSourceLangConfig),
Utils::HandleOrInvalid<SPXAUDIOCONFIGHANDLE, Audio::AudioConfig>(audioInput)));
return std::make_shared<ConversationTranscriber>(hreco);
}
/// <summary>
/// Create a conversation transcriber from a speech config, source language config and audio config
/// </summary>
/// <param name="speechconfig">Speech configuration.</param>
/// <param name="sourceLanguageConfig">Source language config.</param>
/// <param name="audioInput">Audio configuration.</param>
/// <returns>A smart pointer wrapped conversation transcriber pointer.</returns>
static std::shared_ptr<ConversationTranscriber> FromConfig(
std::shared_ptr<SpeechConfig> speechconfig,
std::shared_ptr<SourceLanguageConfig> sourceLanguageConfig,
std::shared_ptr<Audio::AudioConfig> audioInput = nullptr)
{
SPXRECOHANDLE hreco;
SPX_THROW_ON_FAIL(::recognizer_create_conversation_transcriber_from_source_lang_config(
&hreco,
Utils::HandleOrInvalid<SPXSPEECHCONFIGHANDLE, SpeechConfig>(speechconfig),
Utils::HandleOrInvalid<SPXSOURCELANGCONFIGHANDLE, SourceLanguageConfig>(sourceLanguageConfig),
Utils::HandleOrInvalid<SPXAUDIOCONFIGHANDLE, Audio::AudioConfig>(audioInput)));
return std::make_shared<ConversationTranscriber>(hreco);
}
/// <summary>
/// Create a conversation transcriber from a speech config, source language and audio config
/// </summary>
/// <param name="speechconfig">Speech configuration.</param>
/// <param name="sourceLanguage">Source language.</param>
/// <param name="audioInput">Audio configuration.</param>
/// <returns>A smart pointer wrapped conversation transcriber pointer.</returns>
static std::shared_ptr<ConversationTranscriber> FromConfig(
std::shared_ptr<SpeechConfig> speechconfig,
const SPXSTRING& sourceLanguage,
std::shared_ptr<Audio::AudioConfig> audioInput = nullptr)
{
return FromConfig(speechconfig, SourceLanguageConfig::FromLanguage(sourceLanguage), audioInput);
}
/// <summary>
/// Asynchronously starts a conversation transcribing.
/// </summary>
/// <returns>An empty future.</returns>
std::future<void> StartTranscribingAsync()
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this]() -> void {
SPX_INIT_HR(hr);
SPX_THROW_ON_FAIL(hr = recognizer_async_handle_release(m_hasyncStartContinuous)); // close any unfinished previous attempt
SPX_EXITFN_ON_FAIL(hr = recognizer_start_continuous_recognition_async(m_hreco, &m_hasyncStartContinuous));
SPX_EXITFN_ON_FAIL(hr = recognizer_start_continuous_recognition_async_wait_for(m_hasyncStartContinuous, UINT32_MAX));
SPX_EXITFN_CLEANUP:
auto releaseHr = recognizer_async_handle_release(m_hasyncStartContinuous);
SPX_REPORT_ON_FAIL(releaseHr);
m_hasyncStartContinuous = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(hr);
});
return future;
}
/// <summary>
/// Asynchronously stops a conversation transcribing.
/// </summary>
/// <returns>An empty future.</returns>
std::future<void> StopTranscribingAsync()
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this]() -> void {
SPX_INIT_HR(hr);
SPX_THROW_ON_FAIL(hr = recognizer_async_handle_release(m_hasyncStopContinuous)); // close any unfinished previous attempt
SPX_EXITFN_ON_FAIL(hr = recognizer_stop_continuous_recognition_async(m_hreco, &m_hasyncStopContinuous));
SPX_EXITFN_ON_FAIL(hr = recognizer_stop_continuous_recognition_async_wait_for(m_hasyncStopContinuous, UINT32_MAX));
SPX_EXITFN_CLEANUP:
auto releaseHr = recognizer_async_handle_release(m_hasyncStopContinuous);
SPX_REPORT_ON_FAIL(releaseHr);
m_hasyncStopContinuous = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(hr);
});
return future;
}
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
/// <param name="hreco">Recognizer handle.</param>
explicit ConversationTranscriber(SPXRECOHANDLE hreco) throw() :
Recognizer(hreco),
SessionStarted(GetSessionEventConnectionsChangedCallback()),
SessionStopped(GetSessionEventConnectionsChangedCallback()),
SpeechStartDetected(GetRecognitionEventConnectionsChangedCallback()),
SpeechEndDetected(GetRecognitionEventConnectionsChangedCallback()),
Transcribing(GetRecoEventConnectionsChangedCallback()),
Transcribed(GetRecoEventConnectionsChangedCallback()),
Canceled(GetRecoCanceledEventConnectionsChangedCallback()),
m_hasyncStartContinuous(SPXHANDLE_INVALID),
m_hasyncStopContinuous(SPXHANDLE_INVALID),
m_properties(hreco),
Properties(m_properties)
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
}
/// <summary>
/// Destructor.
/// </summary>
~ConversationTranscriber()
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
TermRecognizer();
}
/// <summary>
/// Signal for events indicating the start of a recognition session (operation).
/// </summary>
EventSignal<const SessionEventArgs&> SessionStarted;
/// <summary>
/// Signal for events indicating the end of a recognition session (operation).
/// </summary>
EventSignal<const SessionEventArgs&> SessionStopped;
/// <summary>
/// Signal for events indicating the start of speech.
/// </summary>
EventSignal<const RecognitionEventArgs&> SpeechStartDetected;
/// <summary>
/// Signal for events indicating the end of speech.
/// </summary>
EventSignal<const RecognitionEventArgs&> SpeechEndDetected;
/// <summary>
/// Signal for events containing intermediate recognition results.
/// </summary>
EventSignal<const ConversationTranscriptionEventArgs&> Transcribing;
/// <summary>
/// Signal for events containing final recognition results.
/// (indicating a successful recognition attempt).
/// </summary>
EventSignal<const ConversationTranscriptionEventArgs&> Transcribed;
/// <summary>
/// Signal for events containing canceled recognition results
/// (indicating a recognition attempt that was canceled as a result or a direct cancellation request
/// or, alternatively, a transport or protocol failure).
/// </summary>
EventSignal<const ConversationTranscriptionCanceledEventArgs&> Canceled;
/// <summary>
/// Sets the authorization token that will be used for connecting the server.
/// </summary>
/// <param name="token">The authorization token.</param>
void SetAuthorizationToken(const SPXSTRING& token)
{
Properties.SetProperty(PropertyId::SpeechServiceAuthorization_Token, token);
}
/// <summary>
/// Gets the authorization token.
/// </summary>
/// <returns>Authorization token</returns>
SPXSTRING GetAuthorizationToken()
{
return Properties.GetProperty(PropertyId::SpeechServiceAuthorization_Token, SPXSTRING());
}
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
/// <param name="hreco">Recognizer handle.</param>
virtual void TermRecognizer() override
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
// Disconnect the event signals in reverse construction order
Canceled.DisconnectAll();
Transcribed.DisconnectAll();
Transcribing.DisconnectAll();
SpeechEndDetected.DisconnectAll();
SpeechStartDetected.DisconnectAll();
SessionStopped.DisconnectAll();
SessionStarted.DisconnectAll();
// Close the async handles we have open for Recognize, StartContinuous, and StopContinuous
for (auto handle : { &m_hasyncStartContinuous, &m_hasyncStopContinuous })
{
if (*handle != SPXHANDLE_INVALID && ::recognizer_async_handle_is_valid(*handle))
{
::recognizer_async_handle_release(*handle);
*handle = SPXHANDLE_INVALID;
}
}
// Ask the base to term
Recognizer::TermRecognizer();
}
void RecoEventConnectionsChanged(const EventSignal<const ConversationTranscriptionEventArgs&>& recoEvent)
{
if (m_hreco != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_hreco=0x%8p", __FUNCTION__, (void*)m_hreco);
SPX_DBG_TRACE_VERBOSE_IF(!::recognizer_handle_is_valid(m_hreco), "%s: m_hreco is INVALID!!!", __FUNCTION__);
if (&recoEvent == &Transcribing)
{
recognizer_recognizing_set_callback(m_hreco, Transcribing.IsConnected() ? FireEvent_Transcribing : nullptr, this);
}
else if (&recoEvent == &Transcribed)
{
recognizer_recognized_set_callback(m_hreco, Transcribed.IsConnected() ? FireEvent_Transcribed : nullptr, this);
}
}
}
static void FireEvent_Transcribing(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext)
{
UNUSED(hreco);
std::unique_ptr<ConversationTranscriptionEventArgs> recoEvent{ new ConversationTranscriptionEventArgs(hevent) };
auto pThis = static_cast<ConversationTranscriber*>(pvContext);
auto keepAlive = pThis->shared_from_this();
pThis->Transcribing.Signal(*recoEvent.get());
}
static void FireEvent_Transcribed(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext)
{
UNUSED(hreco);
std::unique_ptr<ConversationTranscriptionEventArgs> recoEvent{ new ConversationTranscriptionEventArgs(hevent) };
auto pThis = static_cast<ConversationTranscriber*>(pvContext);
auto keepAlive = pThis->shared_from_this();
pThis->Transcribed.Signal(*recoEvent.get());
}
void RecoCanceledEventConnectionsChanged(const EventSignal<const ConversationTranscriptionCanceledEventArgs&>& recoEvent)
{
if (m_hreco != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_hreco=0x%8p", __FUNCTION__, (void*)m_hreco);
SPX_DBG_TRACE_VERBOSE_IF(!::recognizer_handle_is_valid(m_hreco), "%s: m_hreco is INVALID!!!", __FUNCTION__);
if (&recoEvent == &Canceled)
{
recognizer_canceled_set_callback(m_hreco, Canceled.IsConnected() ? FireEvent_Canceled : nullptr, this);
}
}
}
static void FireEvent_Canceled(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext)
{
UNUSED(hreco);
auto ptr = new ConversationTranscriptionCanceledEventArgs(hevent);
std::shared_ptr<ConversationTranscriptionCanceledEventArgs> recoEvent(ptr);
auto pThis = static_cast<ConversationTranscriber*>(pvContext);
auto keepAlive = pThis->shared_from_this();
pThis->Canceled.Signal(*ptr);
}
void SessionEventConnectionsChanged(const EventSignal<const SessionEventArgs&>& sessionEvent)
{
if (m_hreco != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_hreco=0x%8p", __FUNCTION__, (void*)m_hreco);
SPX_DBG_TRACE_VERBOSE_IF(!::recognizer_handle_is_valid(m_hreco), "%s: m_hreco is INVALID!!!", __FUNCTION__);
if (&sessionEvent == &SessionStarted)
{
recognizer_session_started_set_callback(m_hreco, SessionStarted.IsConnected() ? FireEvent_SessionStarted : nullptr, this);
}
else if (&sessionEvent == &SessionStopped)
{
recognizer_session_stopped_set_callback(m_hreco, SessionStopped.IsConnected() ? FireEvent_SessionStopped : nullptr, this);
}
}
}
static void FireEvent_SessionStarted(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext)
{
UNUSED(hreco);
std::unique_ptr<SessionEventArgs> sessionEvent{ new SessionEventArgs(hevent) };
auto pThis = static_cast<ConversationTranscriber*>(pvContext);
auto keepAlive = pThis->shared_from_this();
pThis->SessionStarted.Signal(*sessionEvent.get());
// SessionEventArgs doesn't hold hevent, and thus can't release it properly ... release it here
SPX_DBG_ASSERT(recognizer_event_handle_is_valid(hevent));
recognizer_event_handle_release(hevent);
}
static void FireEvent_SessionStopped(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext)
{
UNUSED(hreco);
std::unique_ptr<SessionEventArgs> sessionEvent{ new SessionEventArgs(hevent) };
auto pThis = static_cast<ConversationTranscriber*>(pvContext);
auto keepAlive = pThis->shared_from_this();
pThis->SessionStopped.Signal(*sessionEvent.get());
// SessionEventArgs doesn't hold hevent, and thus can't release it properly ... release it here
SPX_DBG_ASSERT(recognizer_event_handle_is_valid(hevent));
recognizer_event_handle_release(hevent);
}
void RecognitionEventConnectionsChanged(const EventSignal<const RecognitionEventArgs&>& recognitionEvent)
{
if (m_hreco != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_hreco=0x%8p", __FUNCTION__, (void*)m_hreco);
SPX_DBG_TRACE_VERBOSE_IF(!::recognizer_handle_is_valid(m_hreco), "%s: m_hreco is INVALID!!!", __FUNCTION__);
if (&recognitionEvent == &SpeechStartDetected)
{
recognizer_speech_start_detected_set_callback(m_hreco, SpeechStartDetected.IsConnected() ? FireEvent_SpeechStartDetected : nullptr, this);
}
else if (&recognitionEvent == &SpeechEndDetected)
{
recognizer_speech_end_detected_set_callback(m_hreco, SpeechEndDetected.IsConnected() ? FireEvent_SpeechEndDetected : nullptr, this);
}
}
}
static void FireEvent_SpeechStartDetected(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext)
{
UNUSED(hreco);
std::unique_ptr<RecognitionEventArgs> recoEvent{ new RecognitionEventArgs(hevent) };
auto pThis = static_cast<ConversationTranscriber*>(pvContext);
auto keepAlive = pThis->shared_from_this();
pThis->SpeechStartDetected.Signal(*recoEvent.get());
// RecognitionEventArgs doesn't hold hevent, and thus can't release it properly ... release it here
SPX_DBG_ASSERT(recognizer_event_handle_is_valid(hevent));
recognizer_event_handle_release(hevent);
}
static void FireEvent_SpeechEndDetected(SPXRECOHANDLE hreco, SPXEVENTHANDLE hevent, void* pvContext)
{
UNUSED(hreco);
std::unique_ptr<RecognitionEventArgs> recoEvent{ new RecognitionEventArgs(hevent) };
auto pThis = static_cast<ConversationTranscriber*>(pvContext);
auto keepAlive = pThis->shared_from_this();
pThis->SpeechEndDetected.Signal(*recoEvent.get());
// RecognitionEventArgs doesn't hold hevent, and thus can't release it properly ... release it here
SPX_DBG_ASSERT(recognizer_event_handle_is_valid(hevent));
recognizer_event_handle_release(hevent);
}
/*! \endcond */
private:
SPXASYNCHANDLE m_hasyncStartContinuous;
SPXASYNCHANDLE m_hasyncStopContinuous;
DISABLE_DEFAULT_CTORS(ConversationTranscriber);
friend class Microsoft::CognitiveServices::Speech::Session;
class PrivatePropertyCollection : public PropertyCollection
{
public:
PrivatePropertyCollection(SPXRECOHANDLE hreco) :
PropertyCollection(
[=]() {
SPXPROPERTYBAGHANDLE hpropbag = SPXHANDLE_INVALID;
recognizer_get_property_bag(hreco, &hpropbag);
return hpropbag;
}())
{
}
};
PrivatePropertyCollection m_properties;
inline std::function<void(const EventSignal<const SessionEventArgs&>&)> GetSessionEventConnectionsChangedCallback()
{
return [=, this](const EventSignal<const SessionEventArgs&>& sessionEvent) { this->SessionEventConnectionsChanged(sessionEvent); };
}
inline std::function<void(const EventSignal<const ConversationTranscriptionEventArgs&>&)> GetRecoEventConnectionsChangedCallback()
{
return [=, this](const EventSignal<const ConversationTranscriptionEventArgs&>& recoEvent) { this->RecoEventConnectionsChanged(recoEvent); };
}
inline std::function<void(const EventSignal<const ConversationTranscriptionCanceledEventArgs&>&)> GetRecoCanceledEventConnectionsChangedCallback()
{
return [=, this](const EventSignal<const ConversationTranscriptionCanceledEventArgs&>& recoEvent) { this->RecoCanceledEventConnectionsChanged(recoEvent); };
}
inline std::function<void(const EventSignal<const RecognitionEventArgs&>&)> GetRecognitionEventConnectionsChangedCallback()
{
return [=, this](const EventSignal<const RecognitionEventArgs&>& recoEvent) { this->RecognitionEventConnectionsChanged(recoEvent); };
}
public:
/// <summary>
/// A collection of properties and their values defined for this <see cref="ConversationTranscriber"/>.
/// </summary>
PropertyCollection& Properties;
};
} } } } // Microsoft::CognitiveServices::Speech::Transcription

165
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_transcription_eventargs.h

@ -0,0 +1,165 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_conversation_transcription_eventargs.h: Public API declarations for ConversationTranscriptionEventArgs C++ class
//
#pragma once
#include <string>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_recognition_eventargs.h>
#include <speechapi_cxx_conversation_transcription_result.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Transcription {
/// <summary>
/// Class for conversation transcriber event arguments.
/// </summary>
class ConversationTranscriptionEventArgs : public RecognitionEventArgs
{
private:
SPXEVENTHANDLE m_hevent;
std::shared_ptr<ConversationTranscriptionResult> m_result;
public:
/// <summary>
/// Constructor.
/// </summary>
/// <param name="hevent">Event handle</param>
explicit ConversationTranscriptionEventArgs(SPXEVENTHANDLE hevent) :
RecognitionEventArgs(hevent),
m_hevent(hevent),
m_result(std::make_shared<ConversationTranscriptionResult>(ResultHandleFromEventHandle(hevent))),
Result(m_result)
{
SPX_DBG_TRACE_VERBOSE("%s (this=0x%p, handle=0x%p)", __FUNCTION__, (void*)this, (void*)m_hevent);
};
/// <inheritdoc/>
virtual ~ConversationTranscriptionEventArgs()
{
SPX_DBG_TRACE_VERBOSE("%s (this=0x%p, handle=0x%p)", __FUNCTION__, (void*)this, (void*)m_hevent);
SPX_THROW_ON_FAIL(recognizer_event_handle_release(m_hevent));
};
#if defined(BINDING_OBJECTIVE_C)
private:
#endif
/// <summary>
/// Conversation transcriber result.
/// </summary>
std::shared_ptr<ConversationTranscriptionResult> Result;
#if defined(BINDING_OBJECTIVE_C)
public:
#else
protected:
#endif
/*! \cond PROTECTED */
/// <summary>
/// Conversation transcriber result.
/// </summary>
std::shared_ptr<ConversationTranscriptionResult> GetResult() const { return m_result; }
/*! \endcond */
private:
DISABLE_DEFAULT_CTORS(ConversationTranscriptionEventArgs);
SPXRESULTHANDLE ResultHandleFromEventHandle(SPXEVENTHANDLE hevent)
{
SPXRESULTHANDLE hresult = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(recognizer_recognition_event_get_result(hevent, &hresult));
return hresult;
}
};
/// <summary>
/// Class for conversation transcriber canceled event arguments.
/// </summary>
class ConversationTranscriptionCanceledEventArgs : public ConversationTranscriptionEventArgs
{
private:
std::shared_ptr<CancellationDetails> m_cancellation;
CancellationReason m_cancellationReason;
CancellationErrorCode m_errorCode;
public:
/// <summary>
/// Constructor.
/// </summary>
/// <param name="hevent">Event handle</param>
explicit ConversationTranscriptionCanceledEventArgs(SPXEVENTHANDLE hevent) :
ConversationTranscriptionEventArgs(hevent),
m_cancellation(CancellationDetails::FromResult(GetResult())),
m_cancellationReason(m_cancellation->Reason),
m_errorCode(m_cancellation->ErrorCode),
Reason(m_cancellationReason),
ErrorCode(m_errorCode),
ErrorDetails(m_cancellation->ErrorDetails)
{
SPX_DBG_TRACE_VERBOSE("%s (this=0x%p)", __FUNCTION__, (void*)this);
};
/// <inheritdoc/>
virtual ~ConversationTranscriptionCanceledEventArgs()
{
SPX_DBG_TRACE_VERBOSE("%s (this=0x%p)", __FUNCTION__, (void*)this);
};
#if defined(BINDING_OBJECTIVE_C)
private:
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif
/// <summary>
/// The reason the result was canceled.
/// </summary>
const CancellationReason& Reason;
/// <summary>
/// The error code in case of an unsuccessful recognition (<see cref="Reason"/> is set to Error).
/// If Reason is not Error, ErrorCode is set to NoError.
/// </summary>
const CancellationErrorCode& ErrorCode;
#ifdef __clang__
#pragma clang diagnostic pop
#endif
/// <summary>
/// The error message in case of an unsuccessful recognition (<see cref="Reason"/> is set to Error).
/// </summary>
const SPXSTRING ErrorDetails;
#if defined(BINDING_OBJECTIVE_C)
public:
#else
private:
#endif
/// <summary>
/// CancellationDetails.
/// </summary>
std::shared_ptr<CancellationDetails> GetCancellationDetails() const { return m_cancellation; }
private:
DISABLE_DEFAULT_CTORS(ConversationTranscriptionCanceledEventArgs);
};
} } } } // Microsoft::CognitiveServices::Speech::Transcription

72
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_transcription_result.h

@ -0,0 +1,72 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_conversation_transcription_result.h: Public API declarations for ConversationTranscription C++ class
//
#pragma once
#include <string>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_recognition_result.h>
#include <speechapi_c.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Transcription {
/// <summary>
/// Represents the result of a conversation transcriber.
/// </summary>
class ConversationTranscriptionResult final : public RecognitionResult
{
public:
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
/// <param name="hresult">Result handle.</param>
explicit ConversationTranscriptionResult(SPXRESULTHANDLE hresult) :
RecognitionResult(hresult),
SpeakerId(m_speakerId)
{
PopulateSpeakerFields(hresult, &m_speakerId);
SPX_DBG_TRACE_VERBOSE("%s (this=0x%p, handle=0x%p) -- resultid=%s; reason=0x%x; text=%s, speakerid=%s, utteranceid=%s", __FUNCTION__, (void*)this, (void*)Handle, Utils::ToUTF8(ResultId).c_str(), Reason, Utils::ToUTF8(Text).c_str(), Utils::ToUTF8(SpeakerId).c_str());
}
/// <summary>
/// Destructor.
/// </summary>
~ConversationTranscriptionResult()
{
SPX_DBG_TRACE_VERBOSE("%s (this=0x%p, handle=0x%p)", __FUNCTION__, (void*)this, (void*)Handle);
}
/// <summary>
/// Unique Speaker id.
/// </summary>
const SPXSTRING& SpeakerId;
private:
DISABLE_DEFAULT_CTORS(ConversationTranscriptionResult);
void PopulateSpeakerFields(SPXRESULTHANDLE hresult, SPXSTRING* pspeakerId)
{
SPX_INIT_HR(hr);
const size_t maxCharCount = 1024;
char sz[maxCharCount + 1] = {};
if (pspeakerId != nullptr && recognizer_result_handle_is_valid(hresult))
{
SPX_THROW_ON_FAIL(hr = conversation_transcription_result_get_speaker_id(hresult, sz, maxCharCount));
*pspeakerId = Utils::ToSPXString(sz);
}
}
SPXSTRING m_speakerId;
};
} } } } // Microsoft::CognitiveServices::Speech::Transcription

448
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_translator.h

@ -0,0 +1,448 @@
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_conversation_translator.h: Public API declarations for ConversationTranslator C++ class
//
#pragma once
#include <exception>
#include <future>
#include <memory>
#include <string>
#include <cstring>
#include <speechapi_c_conversation_translator.h>
#include <speechapi_cxx_eventsignal.h>
#include <speechapi_cxx_audio_config.h>
#include <speechapi_cxx_conversation.h>
#include <speechapi_cxx_conversation_translator_events.h>
#include <speechapi_cxx_conversation_transcription_eventargs.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
// Forward decl: facilitates friend use of Connection::FromConversationTranslator
class Connection;
namespace Transcription {
/// <summary>
/// A conversation translator that enables a connected experience where participants can use their
/// own devices to see everyone else's recognitions and IMs in their own languages. Participants
/// can also speak and send IMs to others.
/// Added in 1.9.0
/// </summary>
class ConversationTranslator : public std::enable_shared_from_this<ConversationTranslator>
{
private:
/*! \cond PRIVATE */
class PrivatePropertyCollection : public PropertyCollection
{
public:
PrivatePropertyCollection(SPXCONVERSATIONHANDLE hconvtrans) :
PropertyCollection([hconvtrans]()
{
SPXPROPERTYBAGHANDLE hpropbag = SPXHANDLE_INVALID;
conversation_translator_get_property_bag(hconvtrans, &hpropbag);
return hpropbag;
}())
{}
};
SPXCONVERSATIONTRANSLATORHANDLE m_handle;
PrivatePropertyCollection m_properties;
/*! \endcond */
public:
/// <summary>
/// Creates a conversation translator from an audio config
/// </summary>
/// <param name="audioConfig">Audio configuration.</param>
/// <returns>Smart pointer to conversation translator instance.</returns>
static std::shared_ptr<ConversationTranslator> FromConfig(std::shared_ptr<Audio::AudioConfig> audioConfig = nullptr)
{
SPXCONVERSATIONTRANSLATORHANDLE handle;
SPX_THROW_ON_FAIL(::conversation_translator_create_from_config(
&handle,
Utils::HandleOrInvalid<SPXAUDIOCONFIGHANDLE, Audio::AudioConfig>(audioConfig)
));
return std::shared_ptr<ConversationTranslator>(new ConversationTranslator(handle));
}
/// <summary>
/// Destructor
/// </summary>
virtual ~ConversationTranslator()
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
// disconnect callbacks in reverse order
TextMessageReceived.DisconnectAll();
Transcribed.DisconnectAll();
Transcribing.DisconnectAll();
ConversationExpiration.DisconnectAll();
ParticipantsChanged.DisconnectAll();
Canceled.DisconnectAll();
SessionStopped.DisconnectAll();
SessionStarted.DisconnectAll();
::conversation_translator_handle_release(m_handle);
m_handle = SPXHANDLE_INVALID;
}
/// <summary>
/// Signal for events indicating the start of a transcription session (operation).
/// </summary>
EventSignal<const SessionEventArgs&> SessionStarted;
/// <summary>
/// Signal for events indicating the end of a transcription session (operation).
/// </summary>
EventSignal<const SessionEventArgs&> SessionStopped;
/// <summary>
/// Signal for events containing canceled recognition results
/// (indicating a recognition attempt that was canceled as a result or a direct cancellation request
/// or, alternatively, a transport or protocol failure).
/// </summary>
EventSignal<const ConversationTranslationCanceledEventArgs&> Canceled;
/// <summary>
/// Signal for events indicating the conversation participants have changed.
/// </summary>
EventSignal<const ConversationParticipantsChangedEventArgs&> ParticipantsChanged;
/// <summary>
/// Signal for event indicating how many minutes are left until a conversation expires.
/// </summary>
EventSignal<const ConversationExpirationEventArgs&> ConversationExpiration;
/// <summary>
/// Signal for events containing intermediate translated conversation transcription results.
/// </summary>
EventSignal<const ConversationTranslationEventArgs&> Transcribing;
/// <summary>
/// Signal for events containing final translated conversation transcription results.
/// (indicating a successful recognition attempt).
/// </summary>
EventSignal<const ConversationTranslationEventArgs&> Transcribed;
/// <summary>
/// Raised when a text message is received from the conversation.
/// </summary>
EventSignal<const ConversationTranslationEventArgs&> TextMessageReceived;
/// <summary>
/// Joins a conversation. After you call this, you will start receiving events.
/// </summary>
/// <param name="conversation">The conversation instance to use. This instance can be used by the
/// host to manage the conversation.</param>
/// <param name="nickname">The display name to use for the current participant in the conversation.</param>
/// <returns>An asynchronous operation.</returns>
std::future<void> JoinConversationAsync(std::shared_ptr<Conversation> conversation, const SPXSTRING& nickname)
{
return RunAsync([conversation, nickname](auto handle)
{
return ::conversation_translator_join(
handle,
Utils::HandleOrInvalid<SPXCONVERSATIONHANDLE>(conversation),
Utils::ToUTF8(nickname).c_str());
});
}
/// <summary>
/// Joins a conversation. After you call this, you will start receiving events.
/// </summary>
/// <param name="conversationId">The identifier of the conversation you want to join.</param>
/// <param name="nickname">The display name of the current participant in the conversation.</param>
/// <param name="language">The language the participant is using.</param>
/// <returns>An asynchronous operation.</returns>
std::future<void> JoinConversationAsync(const SPXSTRING& conversationId, const SPXSTRING& nickname, const SPXSTRING& language)
{
return RunAsync([conversationId, nickname, language](auto handle)
{
return ::conversation_translator_join_with_id(
handle,
Utils::ToUTF8(conversationId).c_str(),
Utils::ToUTF8(nickname).c_str(),
Utils::ToUTF8(language).c_str());
});
}
/// <summary>
/// Starts sending audio to the conversation service for speech recognition.
/// </summary>
/// <returns>An asynchronous operation.</returns>
std::future<void> StartTranscribingAsync()
{
return RunAsync(::conversation_translator_start_transcribing);
}
/// <summary>
/// Stops sending audio to the conversation service.
/// </summary>
/// <returns>An asynchronous operation.</returns>
std::future<void> StopTranscribingAsync()
{
return RunAsync(::conversation_translator_stop_transcribing);
}
/// <summary>
/// Sends an instant message to all participants in the conversation. This instant message
/// will be translated into each participant's text language.
/// </summary>
/// <param name="message">The message to send.</param>
/// <returns>An asynchronous operation.</returns>
std::future<void> SendTextMessageAsync(const SPXSTRING& message)
{
return RunAsync([message](auto handle)
{
return ::conversation_translator_send_text_message(
handle,
Utils::ToUTF8(message).c_str());
});
}
/// <summary>
/// Leaves the current conversation. After this is called, you will no longer receive any events.
/// </summary>
/// <returns>An asynchronous operation.</returns>
std::future<void> LeaveConversationAsync()
{
return RunAsync(::conversation_translator_leave);
}
/// <summary>
/// Sets the Cognitive Speech authorization token that will be used for connecting to the server.
/// </summary>
/// <param name="authToken">The authorization token.</param>
/// <param name="region">The Azure region for this token.</param>
void SetAuthorizationToken(const SPXSTRING& authToken, const SPXSTRING& region)
{
SPX_THROW_ON_FAIL(::conversation_translator_set_authorization_token(
m_handle,
Utils::ToUTF8(authToken).c_str(),
Utils::ToUTF8(region).c_str()));
}
/// <summary>
/// Gets the authorization token.
/// </summary>
/// <returns>Authorization token</returns>
SPXSTRING GetAuthorizationToken()
{
return m_properties.GetProperty(PropertyId::SpeechServiceAuthorization_Token);
}
/// <summary>
/// Gets your participant identifier
/// </summary>
/// <returns>Participant ID</returns>
SPXSTRING GetParticipantId()
{
return m_properties.GetProperty(PropertyId::Conversation_ParticipantId);
}
/// <summary>
/// A collection of properties and their values defined for this <see cref="ConversationTranslator"/>.
/// </summary>
PropertyCollection& Properties;
protected:
explicit ConversationTranslator(SPXCONVERSATIONTRANSLATORHANDLE handle) :
m_handle(handle),
m_properties(handle),
SessionStarted(BindHandler(&ConversationTranslator::OnSessionEventChanged)),
SessionStopped(BindHandler(&ConversationTranslator::OnSessionEventChanged)),
Canceled(BindHandler(&ConversationTranslator::OnCanceledEventChanged)),
ParticipantsChanged(BindHandler(&ConversationTranslator::OnParticipantsEventChanged)),
ConversationExpiration(BindHandler(&ConversationTranslator::OnExpirationEventChanged)),
Transcribing(BindHandler(&ConversationTranslator::OnTranscriptionEventChanged)),
Transcribed(BindHandler(&ConversationTranslator::OnTranscriptionEventChanged)),
TextMessageReceived(BindHandler(&ConversationTranslator::OnTextMessageEventChanged)),
Properties(m_properties)
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
}
static inline bool ValidateHandle(SPXCONVERSATIONTRANSLATORHANDLE handle, const char* function)
{
UNUSED(function); // not used in release builds
SPX_DBG_TRACE_VERBOSE("%s: handle=0x%8p", function, (void*)handle);
bool valid = ::conversation_translator_handle_is_valid(handle);
SPX_DBG_TRACE_VERBOSE_IF(!valid, "%s: handle is INVALID!!!", function);
return valid;
}
void OnSessionEventChanged(const EventSignal<const SessionEventArgs&>& evt)
{
if (!ValidateHandle(m_handle, __FUNCTION__)) return;
PCONV_TRANS_CALLBACK callback = nullptr;
if (&evt == &SessionStarted)
{
if (SessionStarted.IsConnected())
{
callback = [](auto, auto b, auto c) { FireEvent(b, c, &ConversationTranslator::SessionStarted); };
}
conversation_translator_session_started_set_callback(m_handle, callback, this);
}
else if (&evt == &SessionStopped)
{
if (SessionStopped.IsConnected())
{
callback = [](auto, auto b, auto c) { FireEvent(b, c, &ConversationTranslator::SessionStopped); };
}
conversation_translator_session_stopped_set_callback(m_handle, callback, this);
}
}
void OnCanceledEventChanged(const EventSignal<const ConversationTranslationCanceledEventArgs&>&)
{
if (!ValidateHandle(m_handle, __FUNCTION__)) return;
PCONV_TRANS_CALLBACK callback = nullptr;
if (Canceled.IsConnected())
{
callback = [](auto, auto b, auto c) { FireEvent(b, c, &ConversationTranslator::Canceled); };
}
conversation_translator_canceled_set_callback(m_handle, callback, this);
}
void OnParticipantsEventChanged(const EventSignal<const ConversationParticipantsChangedEventArgs&>&)
{
if (!ValidateHandle(m_handle, __FUNCTION__)) return;
PCONV_TRANS_CALLBACK callback = nullptr;
if (ParticipantsChanged.IsConnected())
{
callback = [](auto, auto b, auto c) { FireEvent(b, c, &ConversationTranslator::ParticipantsChanged); };
}
conversation_translator_participants_changed_set_callback(m_handle, callback, this);
}
void OnExpirationEventChanged(const EventSignal<const ConversationExpirationEventArgs&>&)
{
if (!ValidateHandle(m_handle, __FUNCTION__)) return;
PCONV_TRANS_CALLBACK callback = nullptr;
if (ConversationExpiration.IsConnected())
{
callback = [](auto, auto b, auto c) { FireEvent(b, c, &ConversationTranslator::ConversationExpiration); };
}
conversation_translator_conversation_expiration_set_callback(m_handle, callback, this);
}
void OnTranscriptionEventChanged(const EventSignal<const ConversationTranslationEventArgs&>& evt)
{
if (!ValidateHandle(m_handle, __FUNCTION__)) return;
PCONV_TRANS_CALLBACK callback = nullptr;
if (&evt == &Transcribing)
{
if (Transcribing.IsConnected())
{
callback = [](auto, auto b, auto c) { FireEvent(b, c, &ConversationTranslator::Transcribing); };
}
conversation_translator_transcribing_set_callback(m_handle, callback, this);
}
else
{
if (Transcribed.IsConnected())
{
callback = [](auto, auto b, auto c) { FireEvent(b, c, &ConversationTranslator::Transcribed); };
}
conversation_translator_transcribed_set_callback(m_handle, callback, this);
}
}
void OnTextMessageEventChanged(const EventSignal<const ConversationTranslationEventArgs&>&)
{
if (!ValidateHandle(m_handle, __FUNCTION__)) return;
PCONV_TRANS_CALLBACK callback = nullptr;
if (TextMessageReceived.IsConnected())
{
callback = [](auto, auto b, auto c) { FireEvent(b, c, &ConversationTranslator::TextMessageReceived); };
}
conversation_translator_text_message_recevied_set_callback(m_handle, callback, this);
}
private:
/*! \cond PRIVATE */
friend class Microsoft::CognitiveServices::Speech::Connection;
DISABLE_DEFAULT_CTORS(ConversationTranslator);
inline std::future<void> RunAsync(std::function<SPXHR(SPXCONVERSATIONHANDLE)> func)
{
auto keepalive = this->shared_from_this();
return std::async(std::launch::async, [keepalive, this, func]()
{
SPX_THROW_ON_FAIL(func(m_handle));
});
}
template<typename TArg>
inline std::function<void(TArg)> BindHandler(void (ConversationTranslator::*func)(TArg))
{
return [this, func](TArg arg)
{
(this->*func)(arg);
};
}
static inline void FreeEventHandle(SPXEVENTHANDLE hEvt)
{
if (::conversation_translator_event_handle_is_valid(hEvt))
{
::conversation_translator_event_handle_release(hEvt);
}
}
template<typename T>
static inline void FireEvent(SPXEVENTHANDLE hEvt, void* pCtxt, EventSignal<const T&> ConversationTranslator::*pEvent)
{
try
{
auto pThis = static_cast<ConversationTranslator*>(pCtxt);
SPX_DBG_ASSERT(pThis != nullptr);
auto keepAlive = pThis->shared_from_this();
T eventArgs(hEvt);
(pThis->*pEvent).Signal(eventArgs);
// event classes don't properly release the handles so do that here
FreeEventHandle(hEvt);
}
catch (std::exception& ex)
{
UNUSED(ex);
FreeEventHandle(hEvt);
throw;
}
catch (...)
{
FreeEventHandle(hEvt);
throw;
}
}
/*! \endcond */
};
}}}}

262
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversation_translator_events.h

@ -0,0 +1,262 @@
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_conversation_translator_events.h: Public C++ class API declarations for ConversationTranslator related events
//
#pragma once
#include <exception>
#include <future>
#include <memory>
#include <string>
#include <cstring>
#include <speechapi_c_conversation_translator.h>
#include <speechapi_c_conversation_transcription_result.h>
#include <speechapi_cxx_conversation_transcription_eventargs.h>
#include <speechapi_cxx_translation_eventargs.h>
#include <speechapi_cxx_session_eventargs.h>
#include <speechapi_cxx_participant.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Transcription {
/// <summary>
/// Helper class with additional methods
/// Added in 1.9.0
/// </summary>
class EventHelper
{
protected:
template<typename TVal, typename THandle>
static TVal GetValue(THandle hevent, SPXHR(SPXAPI_CALLTYPE * func)(THandle hevent, TVal* ptr))
{
TVal value;
SPX_THROW_ON_FAIL(func(hevent, &value));
return value;
}
template<typename THandle>
static SPXSTRING GetStringValue(THandle hevent, SPXHR(SPXAPI_CALLTYPE * func)(THandle hevent, char * psz, uint32_t cch))
{
const uint32_t maxCharCount = 1024;
char sz[maxCharCount + 1];
SPX_THROW_ON_FAIL(func(hevent, sz, maxCharCount));
return Utils::ToSPXString(sz);
}
template<typename THandle>
static SPXSTRING GetStringValue(THandle hevent, SPXHR(SPXAPI_CALLTYPE* func)(THandle hevent, char* psz, uint32_t* pcch))
{
// query the string length
uint32_t length = 0;
SPX_THROW_ON_FAIL(func(hevent, nullptr, &length));
// retrieve the string
std::unique_ptr<char[]> buffer(new char[length]);
SPX_THROW_ON_FAIL(func(hevent, buffer.get(), &length));
return Utils::ToSPXString(buffer.get());
}
};
/// <summary>
/// Represents the result of a conversation translator recognition, or text message.
/// Added in 1.9.0
/// </summary>
class ConversationTranslationResult : public Translation::TranslationRecognitionResult, public EventHelper
{
private:
SPXSTRING m_participantId;
SPXSTRING m_originalLang;
public:
explicit ConversationTranslationResult(SPXRESULTHANDLE resultHandle) :
Translation::TranslationRecognitionResult(resultHandle),
m_participantId(GetStringValue(resultHandle, conversation_translator_result_get_user_id)),
m_originalLang(GetStringValue(resultHandle, conversation_translator_result_get_original_lang)),
ParticipantId(m_participantId),
OriginalLanguage(m_originalLang)
{
}
/// <summary>
/// The unique participant identifier
/// </summary>
const SPXSTRING& ParticipantId;
/// <summary>
/// Gets the language that the original recognition or text message is in
/// </summary>
const SPXSTRING& OriginalLanguage;
private:
DISABLE_COPY_AND_MOVE(ConversationTranslationResult);
};
/// <summary>
/// Event arguments for the ConversationExpiration event.
/// Added in 1.9.0
/// </summary>
class ConversationExpirationEventArgs : public SessionEventArgs, public EventHelper
{
private:
std::chrono::minutes m_expirationTime;
public:
/// <summary>
/// Creates a new instance.
/// </summary>
/// <param name="hevent">The event handle.</param>
explicit ConversationExpirationEventArgs(SPXEVENTHANDLE hevent) :
SessionEventArgs(hevent),
m_expirationTime(std::chrono::minutes(GetValue(hevent, conversation_translator_event_get_expiration_time))),
ExpirationTime(m_expirationTime)
{
}
/// <summary>
/// How many minutes are left until the conversation expires
/// </summary>
const std::chrono::minutes& ExpirationTime;
private:
DISABLE_COPY_AND_MOVE(ConversationExpirationEventArgs);
};
/// <summary>
/// Event arguments for the ParticipantsChanged event.
/// Added in 1.9.0
/// </summary>
class ConversationParticipantsChangedEventArgs : public SessionEventArgs, public EventHelper
{
private:
ParticipantChangedReason m_reason;
std::vector<std::shared_ptr<Participant>> m_participants;
public:
/// <summary>
/// Creates a new instance.
/// </summary>
/// <param name="hevent">The event handle.</param>
explicit ConversationParticipantsChangedEventArgs(SPXEVENTHANDLE hevent) :
SessionEventArgs(hevent),
m_reason(GetValue(hevent, conversation_translator_event_get_participant_changed_reason)),
m_participants(GetParticipants(hevent)),
Reason(m_reason),
Participants(m_participants)
{
}
/// <summary>
/// Why the participant changed event was raised (e.g. a participant joined)
/// </summary>
const ParticipantChangedReason& Reason;
/// <summary>
/// The participant(s) that joined, left, or were updated
/// </summary>
const std::vector<std::shared_ptr<Participant>>& Participants;
protected:
/*! \cond PROTECTED */
std::vector<std::shared_ptr<Participant>> GetParticipants(SPXEVENTHANDLE hevent)
{
std::vector<std::shared_ptr<Participant>> list;
SPXPARTICIPANTHANDLE hparticipant = nullptr;
for (int i = 0; hparticipant != SPXHANDLE_INVALID; i++)
{
SPX_THROW_ON_FAIL(conversation_translator_event_get_participant_changed_at_index(hevent, i, &hparticipant));
if (hparticipant != SPXHANDLE_INVALID)
{
list.push_back(std::make_shared<Participant>(hparticipant));
// the Participant object correctly frees the handle so we don't need to do anything
// special here
}
}
return list;
}
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(ConversationParticipantsChangedEventArgs);
};
/// <summary>
/// Event arguments for the ConversationTranslator <see cref="ConversationTranslator::Transcribing"/>,
/// <see cref="ConversationTranslator::Transcribed"/>, or <see cref="ConversationTranslator::TextMessageReceived"/>
/// events.
/// Added in 1.9.0
/// </summary>
class ConversationTranslationEventArgs : public RecognitionEventArgs, public EventHelper
{
private:
std::shared_ptr<ConversationTranslationResult> m_result;
public:
/// <summary>
/// Creates a new instance.
/// </summary>
/// <param name="hevent">The event handle returned by the C-API.</param>
explicit ConversationTranslationEventArgs(SPXEVENTHANDLE hevent)
: RecognitionEventArgs(hevent),
m_result(std::make_shared<ConversationTranslationResult>(GetValue(hevent, recognizer_recognition_event_get_result))),
Result(m_result)
{
}
#if defined(BINDING_OBJECTIVE_C)
private:
#endif
/// <summary>
/// Contains the conversation translation result. This could be for a canceled event,
/// a speech recognition, or a received text message.
/// </summary>
std::shared_ptr<const ConversationTranslationResult> Result;
#if defined(BINDING_OBJECTIVE_C)
public:
#else
protected:
#endif
/*! \cond PROTECTED */
/// <summary>
/// Contains the conversation translation result. This could be for a canceled event,
/// a speech recognition, or a received text message.
/// </summary>
std::shared_ptr<ConversationTranslationResult> GetResult() const { return m_result; }
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(ConversationTranslationEventArgs);
};
/// <summary>
/// Event arguments for the conversation translator canceled event.
/// Added in 1.9.0
/// </summary>
class ConversationTranslationCanceledEventArgs : public ConversationTranscriptionCanceledEventArgs
{
public:
/// <summary>
/// Creates a new instance.
/// </summary>
/// <param name="hevent">The event handle.</param>
explicit ConversationTranslationCanceledEventArgs(SPXEVENTHANDLE hevent) :
ConversationTranscriptionCanceledEventArgs(hevent)
{ }
};
}}}}

89
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_conversational_language_understanding_model.h

@ -0,0 +1,89 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license201809 for the full license information.
//
// speechapi_cxx_conversational_language_understanding_model.h: Public API declarations for PatternMatchingModel C++ class
//
#pragma once
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_language_understanding_model.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_c.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Intent {
/// <summary>
/// Represents a Conversational Language Understanding used for intent recognition.
/// </summary>
class ConversationalLanguageUnderstandingModel : public LanguageUnderstandingModel
{
public:
/// <summary>
/// Creates a Conversational Language Understanding (CLU) model using the specified model ID.
/// </summary>
/// <param name="languageResourceKey">The Azure Language resource key.</param>
/// <param name="endpoint">The Azure Language resource endpoint.</param>
/// <param name="projectName">The Conversational Language Understanding project name.</param>
/// <param name="deploymentName">The Conversational Language Understanding deployment name.</param>
/// <returns>A shared pointer to the Conversational Language Understanding model.</returns>
static std::shared_ptr<ConversationalLanguageUnderstandingModel> FromResource(const SPXSTRING& languageResourceKey, const SPXSTRING& endpoint, const SPXSTRING& projectName, const SPXSTRING& deploymentName)
{
return std::shared_ptr<ConversationalLanguageUnderstandingModel> {
new ConversationalLanguageUnderstandingModel(languageResourceKey, endpoint, projectName, deploymentName)
};
}
/// <summary>
/// Returns id for this model. Defaults to projectName-deploymentName.
/// </summary>
/// <returns>A string representing the id of this model.</returns>
SPXSTRING GetModelId() const { return m_modelId; }
/// <summary>
/// Sets the id for this model. Defaults to projectName-deploymentName.
/// </summary>
/// <param name="value">A string representing the id of this model.</param>
void SetModelId(SPXSTRING value) { m_modelId = value; }
/// <summary>
/// This is the Azure language resource key to be used with this model.
/// </summary>
SPXSTRING languageResourceKey;
/// <summary>
/// Conversational Language Understanding deployment endpoint to contact.
/// </summary>
SPXSTRING endpoint;
/// <summary>
/// Conversational Language Understanding project name.
/// </summary>
SPXSTRING projectName;
/// <summary>
/// Conversational Language Understanding deployment name.
/// </summary>
SPXSTRING deploymentName;
private:
DISABLE_COPY_AND_MOVE(ConversationalLanguageUnderstandingModel);
ConversationalLanguageUnderstandingModel(const SPXSTRING& languageResourceKey, const SPXSTRING& endpoint, const SPXSTRING& projectName, const SPXSTRING& deploymentName) :
LanguageUnderstandingModel(LanguageUnderstandingModelType::ConversationalLanguageUnderstandingModel),
languageResourceKey(languageResourceKey),
endpoint(endpoint),
projectName(projectName),
deploymentName(deploymentName)
{
m_modelId = projectName + "-" + deploymentName;
}
SPXSTRING m_modelId;
};
} } } } // Microsoft::CognitiveServices::Speech::Intent

268
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_dialog_service_config.h

@ -0,0 +1,268 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_speech_config.h>
#include <speechapi_cxx_enums.h>
#include <speechapi_c_property_bag.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Dialog {
/// <summary>
/// Class that defines base configurations for the dialog service connector object.
/// </summary>
class DialogServiceConfig
{
protected:
/*! \cond PROTECTED */
inline explicit DialogServiceConfig(SPXSPEECHCONFIGHANDLE h_config) : m_config{ h_config }
{
}
SpeechConfig m_config;
/*! \endcond */
public:
/// <summary>
/// Default destructor.
/// </summary>
virtual ~DialogServiceConfig() = default;
/// <summary>
/// Internal operator used to get underlying handle value.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXSPEECHCONFIGHANDLE() const { return static_cast<SPXSPEECHCONFIGHANDLE>(m_config); }
/// <summary>
/// Sets a property value by name.
/// </summary>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
void SetProperty(const SPXSTRING& name, const SPXSTRING& value)
{
m_config.SetProperty(name, value);
}
/// <summary>
/// Sets a property value by ID.
/// </summary>
/// <param name="id">The property id.</param>
/// <param name="value">The property value.</param>
void SetProperty(PropertyId id, const SPXSTRING& value)
{
m_config.SetProperty(id, value);
}
/// <summary>
/// Gets a property value by name.
/// </summary>
/// <param name="name">The parameter name.</param>
/// <returns>The property value.</returns>
SPXSTRING GetProperty(const SPXSTRING& name) const
{
return m_config.GetProperty(name);
}
/// <summary>
/// Gets a property value by ID.
/// </summary>
/// <param name="id">The parameter id.</param>
/// <returns>The property value.</returns>
SPXSTRING GetProperty(PropertyId id) const
{
return m_config.GetProperty(id);
}
/// <summary>
/// Sets a property value that will be passed to service using the specified channel.
/// </summary>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
/// <param name="channel">The channel used to pass the specified property to service.</param>
void SetServiceProperty(const SPXSTRING& name, const SPXSTRING& value, ServicePropertyChannel channel)
{
m_config.SetServiceProperty(name, value, channel);
}
/// <summary>
/// Sets proxy configuration
///
/// Note: Proxy functionality is not available on macOS. This function will have no effect on this platform.
/// </summary>
/// <param name="proxyHostName">The host name of the proxy server, without the protocol scheme (`http://`)</param>
/// <param name="proxyPort">The port number of the proxy server</param>
/// <param name="proxyUserName">The user name of the proxy server</param>
/// <param name="proxyPassword">The password of the proxy server</param>
void SetProxy(const SPXSTRING& proxyHostName, uint32_t proxyPort, const SPXSTRING& proxyUserName = SPXSTRING(), const SPXSTRING& proxyPassword = SPXSTRING())
{
m_config.SetProxy(proxyHostName, proxyPort, proxyUserName, proxyPassword);
}
/// <summary>
/// Set the input language to the connector.
/// </summary>
/// <param name="lang">Specifies the name of spoken language to be recognized in BCP-47 format.</param>
void SetLanguage(const SPXSTRING& lang)
{
SetProperty(PropertyId::SpeechServiceConnection_RecoLanguage, lang);
}
/// <summary>
/// Gets the input language to the connector.
/// The language is specified in BCP-47 format.
/// </summary>
/// <returns>The connetor language.</returns>
SPXSTRING GetLanguage() const
{
return GetProperty(PropertyId::SpeechServiceConnection_RecoLanguage);
}
};
/// <summary>
/// Class that defines configurations for the dialog service connector object for using a Bot Framework backend.
/// </summary>
class BotFrameworkConfig final : public DialogServiceConfig
{
public:
/// <summary>
/// Creates a bot framework service config instance with the specified subscription key and region.
/// </summary>
/// <param name="subscription">Subscription key associated with the bot</param>
/// <param name="region">The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).</param>
/// <returns>A shared pointer to the new bot framework config.</returns>
inline static std::shared_ptr<BotFrameworkConfig> FromSubscription(const SPXSTRING& subscription, const SPXSTRING& region)
{
SPXSPEECHCONFIGHANDLE h_config = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(bot_framework_config_from_subscription(&h_config, Utils::ToUTF8(subscription).c_str(), Utils::ToUTF8(region).c_str(), nullptr));
return std::shared_ptr<BotFrameworkConfig>{ new BotFrameworkConfig(h_config) };
}
/// <summary>
/// Creates a bot framework service config instance with the specified subscription key and region.
/// </summary>
/// <param name="subscription">Subscription key associated with the bot</param>
/// <param name="region">The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).</param>
/// <param name="bot_Id"> Identifier used to select a bot associated with this subscription.</param>
/// <returns>A shared pointer to the new bot framework config.</returns>
inline static std::shared_ptr<BotFrameworkConfig> FromSubscription(const SPXSTRING& subscription, const SPXSTRING& region, const SPXSTRING& bot_Id)
{
SPXSPEECHCONFIGHANDLE h_config = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(bot_framework_config_from_subscription(&h_config, Utils::ToUTF8(subscription).c_str(), Utils::ToUTF8(region).c_str(), Utils::ToUTF8(bot_Id).c_str()));
return std::shared_ptr<BotFrameworkConfig>{ new BotFrameworkConfig(h_config) };
}
/// <summary>
/// Creates a bot framework service config instance with the specified authorization token and region.
/// Note: The caller needs to ensure that the authorization token is valid. Before the authorization token
/// expires, the caller needs to refresh it by calling this setter with a new valid token.
/// As configuration values are copied when creating a new connector, the new token value will not apply to connectors that have already been created.
/// For connectors that have been created before, you need to set authorization token of the corresponding connector
/// to refresh the token. Otherwise, the connectors will encounter errors during operation.
/// </summary>
/// <param name="authToken">The authorization token.</param>
/// <param name="region">The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).</param>
/// <returns>A shared pointer to the new bot framework config.</returns>
inline static std::shared_ptr<BotFrameworkConfig> FromAuthorizationToken(const SPXSTRING& authToken, const SPXSTRING& region)
{
SPXSPEECHCONFIGHANDLE h_config = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(bot_framework_config_from_authorization_token(&h_config, Utils::ToUTF8(authToken).c_str(), Utils::ToUTF8(region).c_str(), nullptr));
return std::shared_ptr<BotFrameworkConfig>{ new BotFrameworkConfig(h_config) };
}
/// <summary>
/// Creates a bot framework service config instance with the specified authorization token and region.
/// Note: The caller needs to ensure that the authorization token is valid. Before the authorization token
/// expires, the caller needs to refresh it by calling this setter with a new valid token.
/// As configuration values are copied when creating a new connector, the new token value will not apply to connectors that have already been created.
/// For connectors that have been created before, you need to set authorization token of the corresponding connector
/// to refresh the token. Otherwise, the connectors will encounter errors during operation.
/// </summary>
/// <param name="authToken">The authorization token.</param>
/// <param name="region">The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).</param>
/// <param name="bot_Id"> Identifier used to select a bot associated with this subscription.</param>
/// <returns>A shared pointer to the new bot framework config.</returns>
inline static std::shared_ptr<BotFrameworkConfig> FromAuthorizationToken(const SPXSTRING& authToken, const SPXSTRING& region, const SPXSTRING& bot_Id)
{
SPXSPEECHCONFIGHANDLE h_config = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(bot_framework_config_from_authorization_token(&h_config, Utils::ToUTF8(authToken).c_str(), Utils::ToUTF8(region).c_str(), Utils::ToUTF8(bot_Id).c_str()));
return std::shared_ptr<BotFrameworkConfig>{ new BotFrameworkConfig(h_config) };
}
private:
inline explicit BotFrameworkConfig(SPXSPEECHCONFIGHANDLE h_config): DialogServiceConfig{ h_config }
{
}
};
/// <summary>
/// Class that defines configurations for the dialog service connector object for using a CustomCommands backend.
/// </summary>
class CustomCommandsConfig: public DialogServiceConfig
{
public:
/// <summary>
/// Creates a Custom Commands config instance with the specified application id, subscription key and region.
/// </summary>
/// <param name="appId">Custom Commands application id.</param>
/// <param name="subscription">Subscription key associated with the bot</param>
/// <param name="region">The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).</param>
/// <returns>A shared pointer to the new bot framework config.</returns>
inline static std::shared_ptr<CustomCommandsConfig> FromSubscription(const SPXSTRING& appId, const SPXSTRING& subscription, const SPXSTRING& region)
{
SPXSPEECHCONFIGHANDLE h_config = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(custom_commands_config_from_subscription(&h_config, Utils::ToUTF8(appId).c_str(), Utils::ToUTF8(subscription).c_str(), Utils::ToUTF8(region).c_str()));
return std::shared_ptr<CustomCommandsConfig>{ new CustomCommandsConfig(h_config) };
}
/// <summary>
/// Creates a Custom Commands config instance with the specified application id authorization token and region.
/// Note: The caller needs to ensure that the authorization token is valid. Before the authorization token
/// expires, the caller needs to refresh it by calling this setter with a new valid token.
/// As configuration values are copied when creating a new connector, the new token value will not apply to connectors that have already been created.
/// For connectors that have been created before, you need to set authorization token of the corresponding connector
/// to refresh the token. Otherwise, the connectors will encounter errors during operation.
/// </summary>
/// <param name="appId">Custom Commands application id.</param>
/// <param name="authToken">The authorization token.</param>
/// <param name="region">The region name (see the <a href="https://aka.ms/csspeech/region">region page</a>).</param>
/// <returns>A shared pointer to the new bot framework config.</returns>
inline static std::shared_ptr<CustomCommandsConfig> FromAuthorizationToken(const SPXSTRING& appId, const SPXSTRING& authToken, const SPXSTRING& region)
{
SPXSPEECHCONFIGHANDLE h_config = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(custom_commands_config_from_authorization_token(&h_config, Utils::ToUTF8(appId).c_str(), Utils::ToUTF8(authToken).c_str(), Utils::ToUTF8(region).c_str()));
return std::shared_ptr<CustomCommandsConfig>{ new CustomCommandsConfig(h_config) };
}
/// <summary>
/// Sets the corresponding backend application identifier.
/// </summary>
/// <param name="applicationId">Application identifier.</param>
inline void SetApplicationId(const SPXSTRING& applicationId)
{
SetProperty(PropertyId::Conversation_ApplicationId, applicationId);
}
/// <summary>
/// Gets the application identifier.
/// </summary>
/// <returns>Speech Channel Secret Key.</returns>
inline SPXSTRING GetApplicationId() const
{
return GetProperty(PropertyId::Conversation_ApplicationId);
}
private:
inline explicit CustomCommandsConfig(SPXSPEECHCONFIGHANDLE h_config): DialogServiceConfig{ h_config }
{
}
};
} } } }

547
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_dialog_service_connector.h

@ -0,0 +1,547 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_dialog_service_connector.h: Public API declarations for DialogServiceConnector C++ base class
//
#pragma once
#include <memory>
#include <future>
#include <array>
#include <speechapi_c_common.h>
#include <speechapi_c_dialog_service_connector.h>
#include <speechapi_c_operations.h>
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_enums.h>
#include <speechapi_cxx_utils.h>
#include <speechapi_cxx_audio_config.h>
#include <speechapi_cxx_keyword_recognition_model.h>
#include <speechapi_cxx_speech_config.h>
#include <speechapi_cxx_eventsignal.h>
#include <speechapi_cxx_session_eventargs.h>
#include <speechapi_cxx_speech_recognition_result.h>
#include <speechapi_cxx_speech_recognition_eventargs.h>
#include <speechapi_cxx_dialog_service_connector_eventargs.h>
#include <speechapi_cxx_dialog_service_config.h>
#include <speechapi_cxx_translation_eventargs.h>
#include <speechapi_cxx_translation_result.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
// Forward decl: facilities friend use use of Connection::FromDialogServiceConnector
class Connection;
namespace Dialog {
/// <summary>
/// Object used to connect DirectLineSpeech or CustomCommands.
/// </summary>
/// <remarks>
/// Objects of this type are created via the <see cref="FromConfig"/> factory method.
/// </remarks>
class DialogServiceConnector : public std::enable_shared_from_this<DialogServiceConnector>, public Utils::NonCopyable, public Utils::NonMovable
{
public:
/// <summary>
/// Destroys the instance.
/// </summary>
virtual ~DialogServiceConnector()
{
SPX_DBG_TRACE_SCOPE(__FUNCTION__, __FUNCTION__);
// Disconnect the event signals in reverse construction order
TurnStatusReceived.DisconnectAll();
ActivityReceived.DisconnectAll();
Canceled.DisconnectAll();
SpeechEndDetected.DisconnectAll();
SpeechStartDetected.DisconnectAll();
SessionStopped.DisconnectAll();
SessionStarted.DisconnectAll();
Recognizing.DisconnectAll();
Recognized.DisconnectAll();
if (m_handle != SPXHANDLE_INVALID)
{
::dialog_service_connector_handle_release(m_handle);
SPX_DBG_TRACE_VERBOSE("%s: m_handle=0x%8p", __FUNCTION__, (void*)m_handle);
m_handle = SPXHANDLE_INVALID;
}
}
/// <summary>
/// Creates a dialog service connector from a <see cref="DialogServiceConfig"/> and an <see cref="Audio::AudioConfig" />.
/// Users should use this function to create a dialog service connector.
/// </summary>
/// <param name="connectorConfig">Dialog service config.</param>
/// <param name="audioConfig">Audio config.</param>
/// <returns>The shared smart pointer of the created dialog service connector.</returns>
/// <example>
/// <code>
/// auto audioConfig = Audio::AudioConfig::FromDefaultMicrophoneInput();
/// auto config = CustomCommandsConfig::FromAuthorizationToken("my_app_id","my_auth_token", "my_region");
/// auto connector = DialogServiceConnector::FromConfig(config, audioConfig);
/// </code>
/// </example>
/// <remarks>
/// When speaking of <see cref="DialogServiceConfig" /> we are referring to one of the classes that inherit from it.
/// The specific class to be used depends on the dialog backend being used:
/// <ul>
/// <li><see cref="BotFrameworkConfig" /> for DirectLineSpeech</li>
/// <li><see cref="CustomCommandsConfig" /> for CustomCommands</li>
/// </ul>
/// </remarks>
static std::shared_ptr<DialogServiceConnector> FromConfig(std::shared_ptr<DialogServiceConfig> connectorConfig, std::shared_ptr<Audio::AudioConfig> audioConfig = nullptr)
{
SPXRECOHANDLE h_connector;
SPX_THROW_ON_FAIL(::dialog_service_connector_create_dialog_service_connector_from_config(
&h_connector,
Utils::HandleOrInvalid<SPXSPEECHCONFIGHANDLE, DialogServiceConfig>(connectorConfig),
Utils::HandleOrInvalid<SPXAUDIOCONFIGHANDLE, Audio::AudioConfig>(audioConfig)
));
return std::shared_ptr<DialogServiceConnector> { new DialogServiceConnector(h_connector) };
}
/// <summary>
/// Connects with the back end.
/// </summary>
/// <returns>An asynchronous operation that starts the connection.</returns>
std::future<void> ConnectAsync()
{
auto keep_alive = this->shared_from_this();
return std::async(std::launch::async, [keep_alive, this]()
{
SPX_THROW_ON_FAIL(::dialog_service_connector_connect(m_handle));
});
}
/// <summary>
/// Disconnects from the back end.
/// </summary>
/// <returns>An asynchronous operation that starts the disconnection.</returns>
std::future<void> DisconnectAsync()
{
auto keep_alive = this->shared_from_this();
return std::async(std::launch::async, [keep_alive, this]()
{
SPX_THROW_ON_FAIL(::dialog_service_connector_disconnect(m_handle));
});
}
/// <summary>
/// Sends an activity to the backing dialog.
/// </summary>
/// <param name="activity">Activity to send</param>
/// <returns>An asynchronous operation that starts the operation.</returns>
std::future<std::string> SendActivityAsync(const std::string& activity)
{
auto keep_alive = this->shared_from_this();
return std::async(std::launch::async, [keep_alive, activity, this]()
{
std::array<char, 50> buffer;
SPX_THROW_ON_FAIL(::dialog_service_connector_send_activity(m_handle, activity.c_str(), buffer.data()));
return std::string{ buffer.data() };
});
}
/// <summary>
/// Initiates keyword recognition.
/// </summary>
/// <param name="model">Specifies the keyword model to be used.</param>
/// <returns>An asynchronous operation that starts the operation.</returns>
std::future<void> StartKeywordRecognitionAsync(std::shared_ptr<KeywordRecognitionModel> model)
{
auto keep_alive = this->shared_from_this();
auto h_model = Utils::HandleOrInvalid<SPXKEYWORDHANDLE, KeywordRecognitionModel>(model);
return std::async(std::launch::async, [keep_alive, h_model, this]()
{
SPX_THROW_ON_FAIL(dialog_service_connector_start_keyword_recognition(m_handle, h_model));
});
}
/// <summary>
/// Stop keyword recognition.
/// </summary>
/// <returns>An asynchronous operation that starts the operation.</returns>
std::future<void> StopKeywordRecognitionAsync()
{
auto keep_alive = this->shared_from_this();
return std::async(std::launch::async, [keep_alive, this]()
{
SPX_THROW_ON_FAIL(dialog_service_connector_stop_keyword_recognition(m_handle));
});
}
/// <summary>
/// Starts a listening session that will terminate after the first utterance.
/// </summary>
/// <returns>An asynchronous operation that starts the operation.</returns>
std::future<std::shared_ptr<SpeechRecognitionResult>> ListenOnceAsync()
{
auto keep_alive = this->shared_from_this();
return std::async(std::launch::async, [keep_alive, this]()
{
SPX_INIT_HR(hr);
SPXRECOHANDLE h_result = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(dialog_service_connector_listen_once(m_handle, &h_result));
return std::make_shared<SpeechRecognitionResult>(h_result);
});
}
/// <summary>
/// Requests that an active listening operation immediately finish, interrupting any ongoing
/// speaking, and provide a result reflecting whatever audio data has been captured so far.
/// </summary>
/// <returns> A task representing the asynchronous operation that stops an active listening session. </returns>
std::future<void> StopListeningAsync()
{
auto keepAlive = this->shared_from_this();
auto future = std::async(std::launch::async, [keepAlive, this]() -> void {
SPX_INIT_HR(hr);
// close any unfinished previous attempt
SPX_THROW_ON_FAIL(hr = speechapi_async_handle_release(m_hasyncStopContinuous));
SPX_EXITFN_ON_FAIL(hr = dialog_service_connector_stop_listening_async(m_handle, &m_hasyncStopContinuous));
SPX_EXITFN_ON_FAIL(hr = speechapi_async_wait_for(m_hasyncStopContinuous, UINT32_MAX));
SPX_EXITFN_CLEANUP:
auto releaseHr = speechapi_async_handle_release(m_hasyncStopContinuous);
SPX_REPORT_ON_FAIL(releaseHr);
m_hasyncStopContinuous = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(hr);
});
return future;
}
/// <summary>
/// Sets the authorization token that will be used for connecting to the service.
/// Note: The caller needs to ensure that the authorization token is valid. Before the authorization token
/// expires, the caller needs to refresh it by calling this setter with a new valid token.
/// Otherwise, the connector will encounter errors during its operation.
/// </summary>
/// <param name="token">The authorization token.</param>
void SetAuthorizationToken(const SPXSTRING& token)
{
Properties.SetProperty(PropertyId::SpeechServiceAuthorization_Token, token);
}
/// <summary>
/// Gets the authorization token.
/// </summary>
/// <returns>Authorization token</returns>
SPXSTRING GetAuthorizationToken()
{
return Properties.GetProperty(PropertyId::SpeechServiceAuthorization_Token, SPXSTRING());
}
/// <summary>
/// Sets a JSON template that will be provided to the speech service for the next conversation. The service will
/// attempt to merge this template into all activities sent to the dialog backend, whether originated by the
/// client with SendActivityAsync or generated by the service, as is the case with speech-to-text results.
/// </summary>
/// <param name="activityTemplate">
/// The activity payload, as a JSON string, to be merged into all applicable activity messages.
/// </param>
void SetSpeechActivityTemplate(const SPXSTRING& activityTemplate)
{
Properties.SetProperty(PropertyId::Conversation_Speech_Activity_Template, activityTemplate);
}
/// <summary>
/// Gets the JSON template that will be provided to the speech service for the next conversation. The service will
/// attempt to merge this template into all activities sent to the dialog backend, whether originated by the
/// client with SendActivityAsync or generated by the service, as is the case with speech-to-text results.
/// </summary>
/// <returns> The JSON activity template currently set that will be used on subsequent requests. </returns>
SPXSTRING GetSpeechActivityTemplate()
{
return Properties.GetProperty(PropertyId::Conversation_Speech_Activity_Template, SPXSTRING());
}
/// <summary>
/// Signal for events containing speech recognition results.
/// </summary>
EventSignal<const SpeechRecognitionEventArgs&> Recognized;
/// <summary>
/// Signal for events containing intermediate recognition results.
/// </summary>
EventSignal<const SpeechRecognitionEventArgs&> Recognizing;
/// <summary>
/// Signals that indicates the start of a listening session.
/// </summary>
EventSignal<const SessionEventArgs&> SessionStarted;
/// <summary>
/// Signal that indicates the end of a listening session.
/// </summary>
EventSignal<const SessionEventArgs&> SessionStopped;
/// <summary>
/// Signal that indicates the first detection of speech data in the current phrase.
/// </summary>
EventSignal<const RecognitionEventArgs&> SpeechStartDetected;
/// <summary>
/// Signal that indicates the detected end of the current phrase's speech data.
/// </summary>
EventSignal<const RecognitionEventArgs&> SpeechEndDetected;
/// <summary>
/// Signal for events relating to the cancellation of an interaction. The event indicates if the reason is a direct cancellation or an error.
/// </summary>
EventSignal<const SpeechRecognitionCanceledEventArgs&> Canceled;
/// <summary>
/// Signals that an activity was received from the backend
/// </summary>
EventSignal<const ActivityReceivedEventArgs&> ActivityReceived;
/// <summary>
/// Signals that a turn status update was received from the backend
/// </summary>
EventSignal<const TurnStatusReceivedEventArgs&> TurnStatusReceived;
private:
/*! \cond PROTECTED */
template<typename T, typename F>
std::function<void(const EventSignal<const T&>&)> Callback(F f)
{
return [=, this](const EventSignal<const T&>& evt)
{
(this->*f)(evt);
};
}
static void FireEvent_Recognized(SPXRECOHANDLE, SPXEVENTHANDLE h_event, void* pv_context)
{
auto keep_alive = static_cast<DialogServiceConnector*>(pv_context)->shared_from_this();
SpeechRecognitionEventArgs event{ h_event };
keep_alive->Recognized.Signal(event);
/* Not releasing the handle as SpeechRecognitionEventArgs manages it */
}
static void FireEvent_Recognizing(SPXRECOHANDLE, SPXEVENTHANDLE h_event, void* pv_context)
{
auto keep_alive = static_cast<DialogServiceConnector*>(pv_context)->shared_from_this();
SpeechRecognitionEventArgs event{ h_event };
keep_alive->Recognizing.Signal(event);
/* Not releasing the handle as SpeechRecognitionEventArgs manages it */
}
void RecognizerEventConnectionChanged(const EventSignal<const SpeechRecognitionEventArgs&>& reco_event)
{
if (m_handle != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_handle=0x%8p", __FUNCTION__, (void*)m_handle);
SPX_DBG_TRACE_VERBOSE_IF(!::dialog_service_connector_handle_is_valid(m_handle), "%s: m_handle is INVALID!!!", __FUNCTION__);
if (&reco_event == &Recognizing)
{
::dialog_service_connector_recognizing_set_callback(m_handle, Recognizing.IsConnected() ? DialogServiceConnector::FireEvent_Recognizing : nullptr, this);
}
else if (&reco_event == &Recognized)
{
::dialog_service_connector_recognized_set_callback(m_handle, Recognized.IsConnected() ? DialogServiceConnector::FireEvent_Recognized : nullptr, this);
}
}
}
static void FireEvent_SessionStarted(SPXRECOHANDLE, SPXEVENTHANDLE h_event, void* pv_context)
{
auto keep_alive = static_cast<DialogServiceConnector*>(pv_context)->shared_from_this();
SessionEventArgs event{ h_event };
keep_alive->SessionStarted.Signal(event);
SPX_DBG_ASSERT(::recognizer_event_handle_is_valid(h_event));
/* Releasing the event handle as SessionEventArgs doesn't keep the handle */
::recognizer_event_handle_release(h_event);
}
static void FireEvent_SessionStopped(SPXRECOHANDLE, SPXEVENTHANDLE h_event, void* pv_context)
{
auto keep_alive = static_cast<DialogServiceConnector*>(pv_context)->shared_from_this();
SessionEventArgs event{ h_event };
keep_alive->SessionStopped.Signal(event);
SPX_DBG_ASSERT(::recognizer_event_handle_is_valid(h_event));
/* Releasing the event handle as SessionEventArgs doesn't keep the handle */
::recognizer_event_handle_release(h_event);
}
void SessionEventConnectionChanged(const EventSignal<const SessionEventArgs&>& session_event)
{
if (m_handle != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_handle=0x%8p", __FUNCTION__, (void*)m_handle);
SPX_DBG_TRACE_VERBOSE_IF(!::dialog_service_connector_handle_is_valid(m_handle), "%s: m_handle is INVALID!!!", __FUNCTION__);
if (&session_event == &SessionStarted)
{
::dialog_service_connector_session_started_set_callback(m_handle, SessionStarted.IsConnected() ? DialogServiceConnector::FireEvent_SessionStarted : nullptr, this);
}
else if (&session_event == &SessionStopped)
{
::dialog_service_connector_session_stopped_set_callback(m_handle, SessionStopped.IsConnected() ? DialogServiceConnector::FireEvent_SessionStopped : nullptr, this);
}
}
}
static void FireEvent_SpeechStartDetected(SPXRECOHANDLE, SPXEVENTHANDLE h_event, void* pv_context)
{
auto keep_alive = static_cast<DialogServiceConnector*>(pv_context)->shared_from_this();
RecognitionEventArgs event{ h_event };
keep_alive->SpeechStartDetected.Signal(event);
SPX_DBG_ASSERT(::recognizer_event_handle_is_valid(h_event));
/* Releasing the event handle as RecognitionEventArgs doesn't manage handle lifetime */
::recognizer_event_handle_release(h_event);
}
static void FireEvent_SpeechEndDetected(SPXRECOHANDLE, SPXEVENTHANDLE h_event, void* pv_context)
{
auto keep_alive = static_cast<DialogServiceConnector*>(pv_context)->shared_from_this();
RecognitionEventArgs event{ h_event };
keep_alive->SpeechEndDetected.Signal(event);
SPX_DBG_ASSERT(::recognizer_event_handle_is_valid(h_event));
/* Releasing the event handle as RecognitionEventArgs doesn't manage handle lifetime */
::recognizer_event_handle_release(h_event);
}
void SpeechDetectionEventConnectionChanged(const EventSignal<const RecognitionEventArgs&>& speech_detection_event)
{
if (m_handle != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_handle=0x%8p", __FUNCTION__, (void*)m_handle);
SPX_DBG_TRACE_VERBOSE_IF(!::dialog_service_connector_handle_is_valid(m_handle), "%s: m_handle is INVALID!!!", __FUNCTION__);
if (&speech_detection_event == &SpeechStartDetected)
{
::dialog_service_connector_speech_start_detected_set_callback(m_handle, SpeechStartDetected.IsConnected() ? DialogServiceConnector::FireEvent_SpeechStartDetected : nullptr, this);
}
else if (&speech_detection_event == &SpeechEndDetected)
{
::dialog_service_connector_speech_end_detected_set_callback(m_handle, SpeechEndDetected.IsConnected() ? DialogServiceConnector::FireEvent_SpeechEndDetected : nullptr, this);
}
}
}
static void FireEvent_Canceled(SPXRECOHANDLE, SPXEVENTHANDLE h_event, void* pv_context)
{
auto keep_alive = static_cast<DialogServiceConnector*>(pv_context)->shared_from_this();
SpeechRecognitionCanceledEventArgs event{ h_event };
keep_alive->Canceled.Signal(event);
/* Not releasing the handle as SpeechRecognitionCanceledEventArgs manages it */
}
void CanceledEventConnectionChanged(const EventSignal<const SpeechRecognitionCanceledEventArgs&>& canceled_event)
{
if (m_handle != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_handle=0x%8p", __FUNCTION__, (void*)m_handle);
SPX_DBG_TRACE_VERBOSE_IF(!::dialog_service_connector_handle_is_valid(m_handle), "%s: m_handle is INVALID!!!", __FUNCTION__);
if (&canceled_event == &Canceled)
{
::dialog_service_connector_canceled_set_callback(m_handle, Canceled.IsConnected() ? DialogServiceConnector::FireEvent_Canceled : nullptr, this);
}
}
}
static void FireEvent_ActivityReceived(SPXRECOHANDLE, SPXEVENTHANDLE h_event, void* pv_context)
{
auto keep_alive = static_cast<DialogServiceConnector*>(pv_context)->shared_from_this();
ActivityReceivedEventArgs event{ h_event };
keep_alive->ActivityReceived.Signal(event);
/* Not releasing the handle as ActivityReceivedEventArgs manages it */
}
void ActivityReceivedConnectionChanged(const EventSignal<const ActivityReceivedEventArgs&>& activity_event)
{
if (m_handle != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_hreco=0x%8p", __FUNCTION__, (void*)m_handle);
SPX_DBG_TRACE_VERBOSE_IF(!::dialog_service_connector_handle_is_valid(m_handle), "%s: m_handle is INVALID!!!", __FUNCTION__);
if (&activity_event == &ActivityReceived)
{
::dialog_service_connector_activity_received_set_callback(m_handle, ActivityReceived.IsConnected() ? DialogServiceConnector::FireEvent_ActivityReceived : nullptr, this);
}
}
}
static void FireEvent_TurnStatusReceived(SPXRECOHANDLE, SPXEVENTHANDLE h_event, void* pv_context)
{
auto keep_alive = static_cast<DialogServiceConnector*>(pv_context)->shared_from_this();
TurnStatusReceivedEventArgs event{ h_event };
keep_alive->TurnStatusReceived.Signal(event);
/* Not releasing the handle as TurnStatusReceivedEventArgs manages it */
}
void TurnStatusReceivedConnectionChanged(const EventSignal<const TurnStatusReceivedEventArgs&>& turn_status_event)
{
if (m_handle != SPXHANDLE_INVALID)
{
SPX_DBG_TRACE_VERBOSE("%s: m_hreco=0x%8p", __FUNCTION__, (void*)m_handle);
SPX_DBG_TRACE_VERBOSE_IF(!::dialog_service_connector_handle_is_valid(m_handle), "%s: m_handle is INVALID!!!", __FUNCTION__);
if (&turn_status_event == &TurnStatusReceived)
{
::dialog_service_connector_turn_status_received_set_callback(m_handle, TurnStatusReceived.IsConnected() ? DialogServiceConnector::FireEvent_TurnStatusReceived : nullptr, this);
}
}
}
class PrivatePropertyCollection : public PropertyCollection
{
public:
PrivatePropertyCollection(SPXRECOHANDLE h_connector) :
PropertyCollection(
[=](){
SPXPROPERTYBAGHANDLE h_prop_bag = SPXHANDLE_INVALID;
dialog_service_connector_get_property_bag(h_connector, &h_prop_bag);
return h_prop_bag;
}())
{
}
};
inline explicit DialogServiceConnector(SPXRECOHANDLE handle) :
Recognized{ Callback<SpeechRecognitionEventArgs>(&DialogServiceConnector::RecognizerEventConnectionChanged) },
Recognizing{ Callback<SpeechRecognitionEventArgs>(&DialogServiceConnector::RecognizerEventConnectionChanged) },
SessionStarted{ Callback<SessionEventArgs>(&DialogServiceConnector::SessionEventConnectionChanged) },
SessionStopped{ Callback<SessionEventArgs>(&DialogServiceConnector::SessionEventConnectionChanged) },
SpeechStartDetected{ Callback<RecognitionEventArgs>(&DialogServiceConnector::SpeechDetectionEventConnectionChanged) },
SpeechEndDetected{ Callback<RecognitionEventArgs>(&DialogServiceConnector::SpeechDetectionEventConnectionChanged) },
Canceled{ Callback<SpeechRecognitionCanceledEventArgs>(&DialogServiceConnector::CanceledEventConnectionChanged) },
ActivityReceived{ Callback<ActivityReceivedEventArgs>(&DialogServiceConnector::ActivityReceivedConnectionChanged) },
TurnStatusReceived{ Callback<TurnStatusReceivedEventArgs>(&DialogServiceConnector::TurnStatusReceivedConnectionChanged) },
m_handle{ handle },
m_properties{ handle },
Properties{ m_properties }
{
}
private:
friend class Microsoft::CognitiveServices::Speech::Connection;
SPXRECOHANDLE m_handle;
SPXASYNCHANDLE m_hasyncStopContinuous;
PrivatePropertyCollection m_properties;
/*! \endcond */
public:
/// <summary>
/// A collection of properties and their values defined for this <see cref="DialogServiceConnector"/>.
/// </summary>
PropertyCollection& Properties;
};
} } } }

148
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_dialog_service_connector_eventargs.h

@ -0,0 +1,148 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <memory>
#include <vector>
#include <speechapi_cxx_audio_stream.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Dialog {
// Forward declarations
class DialogServiceConnector;
/// <summary>
/// Class for activity received event arguments.
/// </summary>
class ActivityReceivedEventArgs: public std::enable_shared_from_this<ActivityReceivedEventArgs>
{
public:
friend DialogServiceConnector;
/// <summary>
/// Releases the event.
/// </summary>
inline ~ActivityReceivedEventArgs()
{
SPX_THROW_ON_FAIL(::dialog_service_connector_activity_received_event_release(m_handle));
}
/// <summary>
/// Gets the activity associated with the event.
/// </summary>
/// <returns>The serialized activity activity.</returns>
inline std::string GetActivity() const
{
size_t size;
SPX_THROW_ON_FAIL(::dialog_service_connector_activity_received_event_get_activity_size(m_handle, &size));
auto ptr = std::make_unique<char[]>(size + 1);
SPX_THROW_ON_FAIL(::dialog_service_connector_activity_received_event_get_activity(m_handle, ptr.get(), size + 1));
return std::string{ ptr.get() };
}
/// <summary>
/// Gets the audio associated with the event.
/// </summary>
/// <returns>The audio.</returns>
inline std::shared_ptr<Audio::PullAudioOutputStream> GetAudio() const
{
SPXAUDIOSTREAMHANDLE h_audio{ SPXHANDLE_INVALID };
SPX_THROW_ON_FAIL(::dialog_service_connector_activity_received_event_get_audio(m_handle, &h_audio));
if (h_audio == SPXHANDLE_INVALID)
{
return nullptr;
}
return std::shared_ptr<Audio::PullAudioOutputStream>(new Audio::PullAudioOutputStream(h_audio) );
}
/// <summary>
/// Checks if the event contains audio.
/// </summary>
/// <returns>True if the event contains audio, false otherwise.</returns>
inline bool HasAudio() const
{
return ::dialog_service_connector_activity_received_event_has_audio(m_handle);
}
private:
/*! \cond PROTECTED */
inline ActivityReceivedEventArgs(SPXEVENTHANDLE h_event) : m_handle{ h_event }
{
}
SPXEVENTHANDLE m_handle;
/*! \endcond */
};
/// <summary>
/// Class for turn status event arguments.
/// </summary>
class TurnStatusReceivedEventArgs : public std::enable_shared_from_this<TurnStatusReceivedEventArgs>
{
public:
friend DialogServiceConnector;
/// <summary>
/// Releases the event.
/// </summary>
inline ~TurnStatusReceivedEventArgs()
{
SPX_THROW_ON_FAIL(::dialog_service_connector_turn_status_received_release(m_handle));
}
/// <summary>
/// Retrieves the interaction ID associated with this turn status event. Interaction generally correspond
/// to a single input signal (e.g. voice utterance) or data/activity transaction and will correlate to
/// 'replyToId' fields in Bot Framework activities.
/// </summary>
/// <returns> The interaction ID associated with the turn status. </returns>
inline std::string GetInteractionId() const
{
size_t size = 0;
SPX_THROW_ON_FAIL(::dialog_service_connector_turn_status_received_get_interaction_id_size(m_handle, &size));
auto ptr = std::make_unique<char[]>(size + 1);
SPX_THROW_ON_FAIL(::dialog_service_connector_turn_status_received_get_interaction_id(m_handle, ptr.get(), size + 1));
return std::string{ ptr.get() };
}
/// <summary>
/// Retrieves the conversation ID associated with this turn status event. Conversations may span multiple
/// interactions and are the unit which a client may request resume/retry upon.
/// </summary>
/// <returns> The conversation ID associated with the turn status. </returns>
inline std::string GetConversationId() const
{
size_t size = 0;
SPX_THROW_ON_FAIL(::dialog_service_connector_turn_status_received_get_conversation_id_size(m_handle, &size));
auto ptr = std::make_unique<char[]>(size + 1);
SPX_THROW_ON_FAIL(::dialog_service_connector_turn_status_received_get_conversation_id(m_handle, ptr.get(), size + 1));
return std::string{ ptr.get() };
}
/// <summary>
/// Retrieves the numeric status code associated with this turn status event. These generally correspond to
/// standard HTTP status codes such as 200 (OK), 400 (Failure/Bad Request), and 429 (Timeout/Throttled).
/// </summary>
/// <returns> The status code associated with this event, analolgous to standard HTTP codes. </returns>
inline int GetStatusCode() const
{
int cApiStatus = 404;
SPX_THROW_ON_FAIL(::dialog_service_connector_turn_status_received_get_status(m_handle, &cApiStatus));
return cApiStatus;
}
private:
/*! \cond PROTECTED */
inline TurnStatusReceivedEventArgs(SPXEVENTHANDLE h_event) : m_handle{ h_event }
{
}
SPXEVENTHANDLE m_handle;
/*! \endcond */
};
} } } }

324
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_embedded_speech_config.h

@ -0,0 +1,324 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_embedded_speech_config.h: Public API declarations for EmbeddedSpeechConfig C++ class
//
#pragma once
#include <string>
#include <speechapi_c_common.h>
#include <speechapi_cxx_properties.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_speech_recognition_model.h>
#include <speechapi_cxx_speech_translation_model.h>
#include <speechapi_c_embedded_speech_config.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Class that defines embedded (offline) speech configuration.
/// </summary>
class EmbeddedSpeechConfig
{
protected:
/*! \cond PROTECTED */
SpeechConfig m_config;
/*! \endcond */
public:
/// <summary>
/// Internal operator used to get the underlying handle value.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXSPEECHCONFIGHANDLE() const
{
return static_cast<SPXSPEECHCONFIGHANDLE>(m_config);
}
/// <summary>
/// Creates an instance of the embedded speech config with a specified offline model path.
/// </summary>
/// <param name="path">The folder path to search for offline models.
/// This can be a root path under which several models are located in subfolders,
/// or a direct path to a specific model folder.
/// </param>
/// <returns>A shared pointer to the new embedded speech config instance.</returns>
static std::shared_ptr<EmbeddedSpeechConfig> FromPath(const SPXSTRING& path)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, path.empty());
SPXSPEECHCONFIGHANDLE hconfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(embedded_speech_config_create(&hconfig));
SPX_THROW_ON_FAIL(embedded_speech_config_add_path(hconfig, Utils::ToUTF8(path).c_str()));
auto ptr = new EmbeddedSpeechConfig(hconfig);
return std::shared_ptr<EmbeddedSpeechConfig>(ptr);
}
/// <summary>
/// Creates an instance of the embedded speech config with specified offline model paths.
/// </summary>
/// <param name="paths">The folder paths to search for offline models.
/// These can be root paths under which several models are located in subfolders,
/// or direct paths to specific model folders.
/// </param>
/// <returns>A shared pointer to the new embedded speech config instance.</returns>
static std::shared_ptr<EmbeddedSpeechConfig> FromPaths(const std::vector<SPXSTRING>& paths)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, paths.empty());
SPXSPEECHCONFIGHANDLE hconfig = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(embedded_speech_config_create(&hconfig));
for (const SPXSTRING& path : paths)
{
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, path.empty());
SPX_THROW_ON_FAIL(embedded_speech_config_add_path(hconfig, Utils::ToUTF8(path).c_str()));
}
auto ptr = new EmbeddedSpeechConfig(hconfig);
return std::shared_ptr<EmbeddedSpeechConfig>(ptr);
}
/// <summary>
/// Gets a list of available speech recognition models.
/// </summary>
/// <returns>Speech recognition model info.</returns>
std::vector<std::shared_ptr<SpeechRecognitionModel>> GetSpeechRecognitionModels()
{
std::vector<std::shared_ptr<SpeechRecognitionModel>> models;
uint32_t numModels = 0;
SPX_THROW_ON_FAIL(embedded_speech_config_get_num_speech_reco_models(static_cast<SPXSPEECHCONFIGHANDLE>(m_config), &numModels));
for (uint32_t i = 0; i < numModels; i++)
{
SPXSPEECHRECOMODELHANDLE hmodel = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(embedded_speech_config_get_speech_reco_model(static_cast<SPXSPEECHCONFIGHANDLE>(m_config), i, &hmodel));
auto model = std::make_shared<SpeechRecognitionModel>(hmodel);
models.push_back(model);
}
return models;
}
/// <summary>
/// Sets the model for speech recognition.
/// </summary>
/// <param name="name">The model name.</param>
/// <param name="license">The license text.</param>
void SetSpeechRecognitionModel(const SPXSTRING& name, const SPXSTRING& license)
{
SPX_THROW_ON_FAIL(embedded_speech_config_set_speech_recognition_model(
static_cast<SPXSPEECHCONFIGHANDLE>(m_config), Utils::ToUTF8(name).c_str(), Utils::ToUTF8(license).c_str()));
}
/// <summary>
/// Gets the model name for speech recognition.
/// </summary>
/// <returns>The speech recognition model name.</returns>
SPXSTRING GetSpeechRecognitionModelName() const
{
return GetProperty(PropertyId::SpeechServiceConnection_RecoModelName);
}
/// <summary>
/// Sets the speech recognition output format.
/// </summary>
/// <param name="format">Speech recognition output format (simple or detailed).</param>
void SetSpeechRecognitionOutputFormat(OutputFormat format)
{
m_config.SetOutputFormat(format);
}
/// <summary>
/// Gets the speech recognition output format.
/// </summary>
/// <returns>Speech recognition output format (simple or detailed).</returns>
OutputFormat GetSpeechRecognitionOutputFormat() const
{
return m_config.GetOutputFormat();
}
/// <summary>
/// Sets the profanity option. This can be used to remove profane words or mask them.
/// </summary>
/// <param name="profanity">Profanity option value.</param>
void SetProfanity(ProfanityOption profanity)
{
m_config.SetProfanity(profanity);
}
/// <summary>
/// Sets the voice for embedded speech synthesis.
/// </summary>
/// <param name="name">The voice name of the embedded speech synthesis.</param>
/// <param name="license">The license text.</param>
void SetSpeechSynthesisVoice(const SPXSTRING& name, const SPXSTRING& license)
{
SPX_THROW_ON_FAIL(embedded_speech_config_set_speech_synthesis_voice(
static_cast<SPXSPEECHCONFIGHANDLE>(m_config), Utils::ToUTF8(name).c_str(), Utils::ToUTF8(license).c_str()));
}
/// <summary>
/// Gets the voice name for embedded speech synthesis.
/// </summary>
/// <returns>The speech synthesis model name, i.e. the voice name.</returns>
SPXSTRING GetSpeechSynthesisVoiceName() const
{
return GetProperty(PropertyId::SpeechServiceConnection_SynthOfflineVoice);
}
/// <summary>
/// Sets the speech synthesis output format (e.g. Riff16Khz16BitMonoPcm).
/// </summary>
/// <param name="formatId">Specifies the output format ID</param>
void SetSpeechSynthesisOutputFormat(SpeechSynthesisOutputFormat formatId)
{
m_config.SetSpeechSynthesisOutputFormat(formatId);
}
/// <summary>
/// Gets the speech synthesis output format.
/// </summary>
/// <returns>The speech synthesis output format.</returns>
SPXSTRING GetSpeechSynthesisOutputFormat() const
{
return m_config.GetSpeechSynthesisOutputFormat();
}
/// <summary>
/// Gets a list of available speech translation models.
/// </summary>
/// <returns>Speech translation model info.</returns>
std::vector<std::shared_ptr<SpeechTranslationModel>> GetSpeechTranslationModels()
{
std::vector<std::shared_ptr<SpeechTranslationModel>> models;
uint32_t numModels = 0;
SPX_THROW_ON_FAIL(embedded_speech_config_get_num_speech_translation_models(static_cast<SPXSPEECHCONFIGHANDLE>(m_config), &numModels));
for (uint32_t i = 0; i < numModels; i++)
{
SPXSPEECHRECOMODELHANDLE hmodel = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(embedded_speech_config_get_speech_translation_model(static_cast<SPXSPEECHCONFIGHANDLE>(m_config), i, &hmodel));
auto model = std::make_shared<SpeechTranslationModel>(hmodel);
models.push_back(model);
}
return models;
}
/// <summary>
/// Sets the model for speech translation.
/// </summary>
/// <param name="name">Model name.</param>
/// <param name="license">License text.</param>
void SetSpeechTranslationModel(const SPXSTRING& name, const SPXSTRING& license)
{
SPX_THROW_ON_FAIL(embedded_speech_config_set_speech_translation_model(
static_cast<SPXSPEECHCONFIGHANDLE>(m_config), Utils::ToUTF8(name).c_str(), Utils::ToUTF8(license).c_str()));
}
/// <summary>
/// Gets the model name for speech translation.
/// </summary>
/// <returns>The speech translation model name.</returns>
SPXSTRING GetSpeechTranslationModelName() const
{
return GetProperty(PropertyId::SpeechTranslation_ModelName);
}
/// <summary>
/// Sets the model for keyword recognition.
/// This is for customer specific models that are tailored for detecting
/// wake words and direct commands.
/// </summary>
/// <param name="name">Model name.</param>
/// <param name="license">License text.</param>
void SetKeywordRecognitionModel(const SPXSTRING& name, const SPXSTRING& license)
{
SPX_THROW_ON_FAIL(embedded_speech_config_set_keyword_recognition_model(
static_cast<SPXSPEECHCONFIGHANDLE>(m_config), Utils::ToUTF8(name).c_str(), Utils::ToUTF8(license).c_str()));
}
/// <summary>
/// Gets the model name for keyword recognition.
/// </summary>
/// <returns>The keyword recognition model name.</returns>
SPXSTRING GetKeywordRecognitionModelName() const
{
return GetProperty(PropertyId::KeywordRecognition_ModelName);
}
/// <summary>
/// Sets a property value by name.
/// </summary>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
void SetProperty(const SPXSTRING& name, const SPXSTRING& value)
{
m_config.SetProperty(name, value);
}
/// <summary>
/// Sets a property value by ID.
/// </summary>
/// <param name="id">The property id.</param>
/// <param name="value">The property value.</param>
void SetProperty(PropertyId id, const SPXSTRING& value)
{
m_config.SetProperty(id, value);
}
/// <summary>
/// Gets a property value by name.
/// </summary>
/// <param name="name">The parameter name.</param>
/// <returns>The property value.</returns>
SPXSTRING GetProperty(const SPXSTRING& name) const
{
return m_config.GetProperty(name);
}
/// <summary>
/// Gets a property value by ID.
/// </summary>
/// <param name="id">The parameter id.</param>
/// <returns>The property value.</returns>
SPXSTRING GetProperty(PropertyId id) const
{
return m_config.GetProperty(id);
}
/// <summary>
/// Destructs the object.
/// </summary>
virtual ~EmbeddedSpeechConfig() = default;
protected:
/*! \cond PROTECTED */
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
inline explicit EmbeddedSpeechConfig(SPXSPEECHCONFIGHANDLE hconfig) : m_config(hconfig)
{
}
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(EmbeddedSpeechConfig);
};
}}}

1685
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_enums.h

File diff suppressed because it is too large

108
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_event_logger.h

@ -0,0 +1,108 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <string>
#include <sstream>
#include <iterator>
#include <functional>
#include <azac_api_c_diagnostics.h>
#include <azac_api_cxx_common.h>
#include <speechapi_cxx_log_level.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Diagnostics {
namespace Logging {
/// <summary>
/// Class with static methods to control callback-based SDK logging.
/// Turning on logging while running your Speech SDK scenario provides
/// detailed information from the SDK's core native components. If you
/// report an issue to Microsoft, you may be asked to provide logs to help
/// Microsoft diagnose the issue. Your application should not take dependency
/// on particular log strings, as they may change from one SDK release to another
/// without notice.
/// Use EventLogger when you want to get access to new log strings as soon
/// as they are available, and you need to further process them. For example,
/// integrating Speech SDK logs with your existing logging collection system.
/// Added in version 1.20.0
/// </summary>
/// <remarks>Event logging is a process wide construct. That means that if (for example)
/// you have multiple speech recognizer objects running in parallel, you can only register
/// one callback function to receive interleaved logs from all recognizers. You cannot register
/// a separate callback for each recognizer.</remarks>
class EventLogger
{
public:
using CallbackFunction_Type = ::std::function<void(std::string message)>;
/// <summary>
/// Register a callback function that will be invoked for each new log messages.
/// </summary>
/// <param name="callback">callback function to call. Set a nullptr value
/// to stop the Event Logger.</param>
/// <remarks>You can only register one callback function. This call will happen on a working thread of the SDK,
/// so the log string should be copied somewhere for further processing by another thread, and the function should return immediately.
/// No heavy processing or network calls should be done in this callback function.</remarks>
static void SetCallback(CallbackFunction_Type callback = nullptr)
{
AZAC_THROW_ON_FAIL(diagnostics_logmessage_set_callback(nullptr == callback ? nullptr : LineLogged));
SetOrGet(true, callback);
}
/// <summary>
/// Sets or clears filters for callbacks.
/// Once filters are set, the callback will be invoked only if the log string
/// contains at least one of the strings specified by the filters. The match is case sensitive.
/// </summary>
/// <param name="filters">Optional. Filters to use, or an empty list to clear previously set filters</param>
static void SetFilters(std::initializer_list<std::string> filters = {})
{
std::string str = "";
if (filters.size() > 0)
{
std::ostringstream filtersCollapsed;
std::copy(filters.begin(), filters.end(), std::ostream_iterator<std::string>(filtersCollapsed, ";"));
str = filtersCollapsed.str();
}
AZAC_THROW_ON_FAIL(diagnostics_logmessage_set_filters(str.c_str()));
}
/// <summary>
/// Sets the level of the messages to be captured by the logger
/// </summary>
/// <param name="level">Maximum level of detail to be captured by the logger.</param>
static void SetLevel(Level level)
{
const auto levelStr = Details::LevelToString(level);
diagnostics_set_log_level("event", levelStr);
}
private:
static CallbackFunction_Type SetOrGet(bool set, CallbackFunction_Type callback)
{
static CallbackFunction_Type staticCallback = nullptr;
if (set)
{
staticCallback = callback;
}
return staticCallback;
}
static void LineLogged(const char* line)
{
auto callback = SetOrGet(false, nullptr);
if (nullptr != callback)
{
callback(line);
}
}
};
}}}}}

47
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_eventargs.h

@ -0,0 +1,47 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_eventargs.h: Public API declarations for EventArgs C++ base class
//
#pragma once
#include <string>
#include <speechapi_cxx_common.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Base class for event arguments.
/// </summary>
class EventArgs
{
public:
/// <summary>
/// Destructor.
/// </summary>
virtual ~EventArgs() {}
protected:
/*! \cond PROTECTED */
/// <summary>
/// Constructor.
/// </summary>
EventArgs() {};
/*! \endcond */
private:
DISABLE_COPY_AND_MOVE(EventArgs);
};
} } } // Microsoft::CognitiveServices::Speech

202
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_eventsignal.h

@ -0,0 +1,202 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_eventsignal.h: Public API declarations for the EventSignal<T> class. This derives from
// EventSignalBase<T> and uses runtime type information (RTTI) to facilitate management and disconnection of handlers
// without explicit callback token management.
//
#pragma once
#include <algorithm>
#include <functional>
#include <mutex>
#include <string>
#include <speechapi_cxx_eventsignalbase.h>
// TODO: TFS#3671067 - Vision: Consider moving majority of EventSignal to AI::Core::Details namespace, and refactoring Vision::Core::Events to inherit, and relay to private base
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Clients can connect to the event signal to receive events, or disconnect from the event signal to stop receiving events.
/// </summary>
/// <remarks>
/// At construction time, connect and disconnect callbacks can be provided that are called when
/// the number of connected clients changes from zero to one or one to zero, respectively.
/// </remarks>
// <typeparam name="T">
template <class T>
class EventSignal : public EventSignalBase<T>
{
public:
/// <summary>
/// Callback type that is used for signalling the event to connected clients.
/// </summary>
using CallbackFunction = std::function<void(T eventArgs)>;
/// <summary>
/// A monotonically increasing token used for registration, tracking, and unregistration of callbacks.
/// </summary>
using CallbackToken = uint32_t;
/// <summary>
/// Type for callbacks used when any client connects to the signal (the number of connected clients changes from zero to one) or
/// the last client disconnects from the signal (the number of connected clients changes from one to zero).
/// </summary>
using NotifyCallback_Type = std::function<void(EventSignal<T>&)>;
/// <summary>
/// Constructs an event signal with empty register and disconnect callbacks.
/// <summary>
EventSignal() : EventSignal(nullptr)
{
}
/// <summary>
/// Constructor.
/// <summary>
/// <param name="connectedAndDisconnected">Callback to invoke if the number of connected clients changes from zero to one, or one to zero</param>
EventSignal(NotifyCallback_Type connectedAndDisconnected)
: EventSignal(connectedAndDisconnected, connectedAndDisconnected)
{
}
/// <summary>
/// Constructor.
/// <summary>
/// <param name="connected">Callback to invoke if the number of connected clients changes from zero to one.</param>
/// <param name="disconnected">Callback to invoke if the number of connected clients changes from one to zero.</param>
EventSignal(NotifyCallback_Type connected, NotifyCallback_Type disconnected)
: EventSignalBase<T>()
, m_firstConnectedCallback(connected)
, m_lastDisconnectedCallback(disconnected)
{
}
/// <summary>
/// Addition assignment operator overload.
/// Connects the provided callback <paramref name="callback"/> to the event signal, see also <see cref="Connect"/>.
/// </summary>
/// <param name="callback">Callback to connect.</param>
/// <returns>Event signal reference.</returns>
EventSignal<T>& operator+=(CallbackFunction callback)
{
Connect(callback);
return *this;
}
/// <summary>
/// Subtraction assignment operator overload.
/// Disconnects the provided callback <paramref name="callback"/> from the event signal, see also <see cref="Disconnect"/>.
/// </summary>
/// <param name="callback">Callback to disconnect.</param>
/// <returns>Event signal reference.</returns>
EventSignal<T>& operator-=(CallbackFunction callback)
{
Disconnect(callback);
return *this;
}
/// <summary>
/// Connects given callback function to the event signal, to be invoked when the event is signalled.
/// </summary>
/// <remarks>
/// When the number of connected clients changes from zero to one, the connect callback will be called, if provided.
/// </remarks>
/// <param name="callback">Callback to connect.</param>
void Connect(CallbackFunction callback)
{
std::unique_lock<std::recursive_mutex> lock(m_mutex);
auto shouldFireFirstConnected = m_callbacks.empty() && m_firstConnectedCallback != nullptr;
(void)EventSignalBase<T>::RegisterCallback(callback);
lock.unlock();
if (shouldFireFirstConnected)
{
m_firstConnectedCallback(*this);
}
}
#ifndef AZAC_CONFIG_CXX_NO_RTTI
/// <summary>
/// Disconnects given callback.
/// <summary>
/// <remarks>
/// When the number of connected clients changes from one to zero, the disconnect callback will be called, if provided.
/// </remarks>
/// <param name="callback">Callback function.</param>
void Disconnect(CallbackFunction callback)
{
std::unique_lock<std::recursive_mutex> lock(m_mutex);
auto itMatchingCallback = std::find_if(
m_callbacks.begin(),
m_callbacks.end(),
[&](const std::pair<CallbackToken, CallbackFunction>& item)
{
return callback.target_type() == item.second.target_type();
});
auto removeHappened = EventSignal<T>::UnregisterCallback(itMatchingCallback->first);
lock.unlock();
if (removeHappened && m_callbacks.empty() && m_lastDisconnectedCallback != nullptr)
{
m_lastDisconnectedCallback(*this);
}
}
#else
void Disconnect(CallbackFunction)
{
// Callback disconnection without a stored token requires runtime type information.
// To remove callbacks with RTTI disabled, use UnregisterCallback(token).
SPX_THROW_HR(SPXERR_NOT_IMPL);
}
#endif
/// <summary>
/// Disconnects all registered callbacks.
/// </summary>
void DisconnectAll()
{
std::unique_lock<std::recursive_mutex> lock(m_mutex);
auto shouldFireLastDisconnected = !m_callbacks.empty() && m_lastDisconnectedCallback != nullptr;
EventSignal<T>::UnregisterAllCallbacks();
lock.unlock();
if (shouldFireLastDisconnected)
{
m_lastDisconnectedCallback(*this);
}
}
/// <summary>
/// Signals the event with given arguments <paramref name="t"/> to all connected callbacks.
/// <summary>
/// <param name="t">Event arguments to signal.</param>
void Signal(T t)
{
EventSignalBase<T>::Signal(t);
}
private:
using EventSignalBase<T>::m_mutex;
using EventSignalBase<T>::m_callbacks;
NotifyCallback_Type m_firstConnectedCallback;
NotifyCallback_Type m_lastDisconnectedCallback;
EventSignal(const EventSignal&) = delete;
EventSignal(const EventSignal&&) = delete;
EventSignal& operator=(const EventSignal&) = delete;
};
} } } // Microsoft::CognitiveServices::Speech

166
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_eventsignalbase.h

@ -0,0 +1,166 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_eventsignalbase.h: Public API declarations for EventSignalBase<T> C++ template class
//
#pragma once
#include <algorithm>
#include <functional>
#include <map>
#include <mutex>
#include <string>
// TODO: TFS#3671067 - Vision: Consider moving majority of EventSignal to AI::Core::Details namespace, and refactoring Vision::Core::Events to inherit, and relay to private base
#include <speechapi_cxx_common.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Clients can connect to the event signal to receive events, or disconnect from the event signal to stop receiving events.
/// </summary>
/// <remarks>
/// At construction time, connect and disconnect callbacks can be provided that are called when
/// the number of connected clients changes from zero to one or one to zero, respectively.
/// </remarks>
// <typeparam name="T">
template <class T>
class EventSignalBase
{
public:
/// <summary>
/// Constructs an event signal with empty connect and disconnect actions.
/// <summary>
EventSignalBase() :
m_nextCallbackToken(0)
{
}
/// <summary>
/// Destructor.
/// <summary>
virtual ~EventSignalBase()
{
UnregisterAllCallbacks();
}
/// <summary>
/// Callback type that is used for signalling the event to connected clients.
/// </summary>
using CallbackFunction = std::function<void(T eventArgs)>;
/// <summary>
/// The argument type for the callback event
/// </summary>
using CallbackArgument = T;
/// <summary>
/// A monotonically increasing token used for registration, tracking, and unregistration of callbacks.
/// </summary>
using CallbackToken = uint32_t;
/// <summary>
/// Registers a callback to this EventSignalBase and assigns it a unique token.
/// </summary>
/// <param name="callback"> The callback to register. </param>
/// <returns>
/// The new token associated with this registration that can be used for subsequent unregistration.
/// </returns>
CallbackToken RegisterCallback(CallbackFunction callback)
{
std::unique_lock<std::recursive_mutex> lock(m_mutex);
auto token = m_nextCallbackToken;
m_nextCallbackToken++;
m_callbacks.emplace(token, callback);
return token;
}
/// <summary>
/// If present, unregisters a callback from this EventSource associated with the provided token. Tokens are
/// returned from RegisterCallback at the time of registration.
/// </summary>
/// <param name="token">
/// The token associated with the callback to be removed. This token is provided by the return value of
/// RegisterCallback at the time of registration.
/// </param>
/// <returns> A value indicating whether any callback was unregistered in response to this request. </returns>
bool UnregisterCallback(CallbackToken token)
{
std::unique_lock<std::recursive_mutex> lock(m_mutex);
return (bool)m_callbacks.erase(token);
}
/// <summary>
/// Function call operator.
/// Signals the event with given arguments <paramref name="t"/> to connected clients, see also <see cref="Signal"/>.
/// </summary>
/// <param name="t">Event arguments to signal.</param>
void operator()(T t)
{
Signal(t);
}
/// <summary>
/// Unregisters all registered callbacks.
/// <summary>
void UnregisterAllCallbacks()
{
std::unique_lock<std::recursive_mutex> lock(m_mutex);
m_callbacks.clear();
}
/// <summary>
/// Signals the event with given arguments <paramref name="t"/> to all connected callbacks.
/// <summary>
/// <param name="t">Event arguments to signal.</param>
void Signal(T t)
{
std::unique_lock<std::recursive_mutex> lock(m_mutex);
auto callbacksSnapshot = m_callbacks;
for (auto callbackCopyPair : callbacksSnapshot)
{
// now, while a callback is in progress, it can disconnect itself and any other connected
// callback. Check to see if the next one stored in the copy container is still connected.
bool stillConnected = (std::find_if(m_callbacks.begin(), m_callbacks.end(),
[&](const std::pair<CallbackToken, CallbackFunction> item) {
return callbackCopyPair.first == item.first;
}) != m_callbacks.end());
if (stillConnected)
{
callbackCopyPair.second(t);
}
}
}
/// <summary>
/// Checks if a callback is connected.
/// <summary>
/// <returns>true if a callback is connected</returns>
bool IsConnected() const
{
std::unique_lock<std::recursive_mutex> lock(m_mutex);
return !m_callbacks.empty();
}
protected:
std::map<CallbackToken, CallbackFunction> m_callbacks;
CallbackToken m_nextCallbackToken;
mutable std::recursive_mutex m_mutex;
private:
EventSignalBase(const EventSignalBase&) = delete;
EventSignalBase(const EventSignalBase&&) = delete;
EventSignalBase& operator=(const EventSignalBase&) = delete;
};
} } } // Microsoft::CognitiveServices::Speech

115
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_file_logger.h

@ -0,0 +1,115 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
#pragma once
#include <string>
#include <sstream>
#include <iterator>
#include <azac_api_c_diagnostics.h>
#include <speechapi_c_property_bag.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_cxx_log_level.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
namespace Diagnostics {
namespace Logging {
/// <summary>
/// Class with static methods to control file-based SDK logging.
/// Turning on logging while running your Speech SDK scenario provides
/// detailed information from the SDK's core native components. If you
/// report an issue to Microsoft, you may be asked to provide logs to help
/// Microsoft diagnose the issue. Your application should not take dependency
/// on particular log strings, as they may change from one SDK release to another
/// without notice.
/// FileLogger is the simplest logging solution and suitable for diagnosing
/// most on-device issues when running Speech SDK.
/// Added in version 1.20.0
/// </summary>
/// <remarks>File logging is a process wide construct. That means that if (for example)
/// you have multiple speech recognizer objects running in parallel, there will be one
/// log file containing interleaved logs lines from all recognizers. You cannot get a
/// separate log file for each recognizer.</remarks>
class FileLogger
{
public:
/// <summary>
/// Starts logging to a file.
/// </summary>
/// <param name="filePath">Path to a log file on local disk</param>
/// <param name="append">Optional. If true, appends to existing log file. If false, creates a new log file</param>
/// <remarks>Note that each write operation to the file is immediately followed by a flush to disk.
/// For typical usage (e.g. one Speech Recognizer and a Solid State Drive (SSD)) this should not
/// cause performace issues. You may however want to avoid file logging when running many Speech
/// SDK recognizers or other SDK objects simultaneously. Use MemoryLogger or EventLogger instead.</remarks>
static void Start(const SPXSTRING& filePath, bool append = false)
{
SPXPROPERTYBAGHANDLE hpropbag = SPXHANDLE_INVALID;
SPX_THROW_HR_IF(SPXERR_INVALID_ARG, filePath.empty());
SPX_THROW_ON_FAIL(property_bag_create(&hpropbag));
SPX_THROW_ON_FAIL(property_bag_set_string(hpropbag, -1, "SPEECH-LogFilename", Utils::ToUTF8(filePath).c_str()));
SPX_THROW_ON_FAIL(property_bag_set_string(hpropbag, -1, "SPEECH-AppendToLogFile", append ? "1" : "0"));
SPX_THROW_ON_FAIL(diagnostics_log_start_logging(hpropbag, nullptr));
SPX_THROW_ON_FAIL(property_bag_release(hpropbag));
}
/// <summary>
/// Stops logging to a file.
/// </summary>
/// <remarks>This call is optional. If logging as been started,
/// the log file will be written when the process exists normally.</remarks>
static void Stop()
{
SPX_THROW_ON_FAIL(diagnostics_log_stop_logging());
}
/// <summary>
/// Sets or clears the filters that apply to file logging.
/// Once filters are set, the callback will be invoked only if the log string
/// contains at least one of the strings specified by the filters. The match is case sensitive.
/// </summary>
/// <param name="filters">Optional. Filters to use, or an empty list to remove previously set filters.</param>
static void SetFilters(std::initializer_list<std::string> filters = {})
{
SPXPROPERTYBAGHANDLE hpropbag = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(property_bag_create(&hpropbag));
PropBagSetFilter(hpropbag, filters);
SPX_THROW_ON_FAIL(diagnostics_log_apply_properties(hpropbag, nullptr));
SPX_THROW_ON_FAIL(property_bag_release(hpropbag));
}
/// <summary>
/// Sets the level of the messages to be captured by the logger
/// </summary>
/// <param name="level">Maximum level of detail to be captured by the logger.</param>
static void SetLevel(Level level)
{
const auto levelStr = Details::LevelToString(level);
diagnostics_set_log_level("memory", levelStr);
}
private:
static void PropBagSetFilter(AZAC_HANDLE hpropbag, std::initializer_list<std::string> filters)
{
std::string str = "";
if (filters.size() > 0)
{
std::ostringstream filtersCollapsed;
std::copy(filters.begin(), filters.end(), std::ostream_iterator<std::string>(filtersCollapsed, ";"));
str = filtersCollapsed.str();
}
SPX_THROW_ON_FAIL(property_bag_set_string(hpropbag, -1, "SPEECH-LogFileFilters", str.c_str()));
}
};
}}}}}

70
Unreal/Plugins/AvatarCore_STT/Source/ThirdParty/AzureWrapper/include/cxx_api/speechapi_cxx_grammar.h

@ -0,0 +1,70 @@
//
// Copyright (c) Microsoft. All rights reserved.
// See https://aka.ms/csspeech/license for the full license information.
//
// speechapi_cxx_grammar.h: Public API declarations for Grammar C++ class
//
#pragma once
#include <speechapi_cxx_common.h>
#include <speechapi_cxx_smart_handle.h>
#include <speechapi_cxx_string_helpers.h>
#include <speechapi_c.h>
namespace Microsoft {
namespace CognitiveServices {
namespace Speech {
/// <summary>
/// Represents base class grammar for customizing speech recognition.
/// Added in version 1.5.0.
/// </summary>
class Grammar
{
public:
/// <summary>
/// Creates a grammar from a storage ID.
/// Added in version 1.7.0.
/// </summary>
/// <param name="storageId)">The persisted storage ID of the language model.</param>
/// <returns>The grammar.</returns>
/// <remarks>
/// Creating a grammar from a storage ID is only usable in specific scenarios and is not generally possible.
/// </remarks>
static std::shared_ptr<Grammar> FromStorageId(const SPXSTRING& storageId)
{
SPXGRAMMARHANDLE hgrammar = SPXHANDLE_INVALID;
SPX_THROW_ON_FAIL(grammar_create_from_storage_id(&hgrammar, Utils::ToUTF8(storageId.c_str())));
return std::make_shared<Grammar>(hgrammar);
}
/// <summary>
/// Internal constructor. Creates a new instance using the provided handle.
/// </summary>
/// <param name="hgrammar">Grammar handle.</param>
explicit Grammar(SPXGRAMMARHANDLE hgrammar = SPXHANDLE_INVALID) : m_hgrammar(hgrammar) { }
/// <summary>
/// Destructor, does nothing.
/// </summary>
virtual ~Grammar() { }
/// <summary>
/// Internal. Explicit conversion operator.
/// </summary>
/// <returns>A handle.</returns>
explicit operator SPXGRAMMARHANDLE() { return m_hgrammar; }
protected:
/*! \cond PROTECTED */
DISABLE_COPY_AND_MOVE(Grammar);
SmartHandle<SPXGRAMMARHANDLE, &grammar_handle_release> m_hgrammar;
/*! \endcond */
};
} } } // Microsoft::CognitiveServices::Speech

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save