Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
AzSpeech v1.6.10
Browse files Browse the repository at this point in the history
  • Loading branch information
lucoiso authored Aug 12, 2023
2 parents 1359429 + c9653b9 commit 9b11ed9
Show file tree
Hide file tree
Showing 155 changed files with 5,908 additions and 4,115 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Content/** filter=lfs diff=lfs merge=lfs -text
Source/ThirdParty/AzureWrapper/libs/iOS/libMicrosoft.CognitiveServices.Speech.core.a filter=lfs diff=lfs merge=lfs -text
9 changes: 5 additions & 4 deletions AzSpeech.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 25,
"VersionName": "1.6.8",
"Version": 27,
"VersionName": "1.6.10",
"FriendlyName": "AzSpeech - Voice and Text",
"Description": "Integrates Azure Speech Cognitive Services into the Engine by adding functions to perform recognition and synthesis via asynchronous tasks.",
"Category": "Game Features",
Expand All @@ -19,15 +19,16 @@
"Name": "AzSpeech",
"Type": "Runtime",
"LoadingPhase": "Default",
"WhitelistPlatforms": [
"PlatformAllowList": [
"Win64",
"Android"
]
},
{
"Name": "AzSpeechEditor",
"Type": "Editor",
"WhitelistPlatforms": [
"LoadingPhase": "Default",
"PlatformAllowList": [
"Win64",
"Mac",
"Linux"
Expand Down
60 changes: 30 additions & 30 deletions Source/AzSpeech/AzSpeech.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@

public class AzSpeech : ModuleRules
{
public AzSpeech(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
CppStandard = CppStandardVersion.Cpp17;
bEnableExceptions = true;
public AzSpeech(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
CppStandard = CppStandardVersion.Cpp17;
bEnableExceptions = true;

PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));
PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));

PublicDependencyModuleNames.AddRange(new[]
{
"Core",
"AzureWrapper"
});
PublicDependencyModuleNames.AddRange(new[]
{
"Core",
"AzureWrapper"
});

PrivateDependencyModuleNames.AddRange(new[]
{
"Engine",
"CoreUObject",
"Projects",
"AndroidPermission",
"DeveloperSettings",
"AudioCaptureCore",
"AssetRegistry",
"Projects",
"Json"
});
PrivateDependencyModuleNames.AddRange(new[]
{
"Engine",
"CoreUObject",
"Projects",
"AndroidPermission",
"DeveloperSettings",
"AudioCaptureCore",
"AssetRegistry",
"Projects",
"Json"
});

if (Target.bBuildEditor)
{
PrivateDependencyModuleNames.Add("UnrealEd");
}
if (Target.bBuildEditor)
{
PrivateDependencyModuleNames.Add("UnrealEd");
}

PrivateIncludePathModuleNames.Add("DesktopPlatform");
}
PrivateIncludePathModuleNames.Add("DesktopPlatform");
}
}
167 changes: 84 additions & 83 deletions Source/AzSpeech/Private/AzSpeech.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "AzSpeech.h"
#include "AzSpeechInternalFuncs.h"
#include "AzSpeech/AzSpeechHelper.h"
#include "LogAzSpeech.h"
#include <Modules/ModuleManager.h>
#include <Interfaces/IPluginManager.h>
#include <Misc/Paths.h>
Expand All @@ -26,146 +27,146 @@
#ifdef AZSPEECH_WHITELISTED_BINARIES
TArray<FString> GetWhitelistedRuntimeLibs()
{
TArray<FString> WhitelistedLibs;
TArray<FString> WhitelistedLibs;

const FString WhitelistedLibsDef(AZSPEECH_WHITELISTED_BINARIES);
WhitelistedLibsDef.ParseIntoArray(WhitelistedLibs, TEXT(";"));
const FString WhitelistedLibsDef(AZSPEECH_WHITELISTED_BINARIES);
WhitelistedLibsDef.ParseIntoArray(WhitelistedLibs, TEXT(";"));

return WhitelistedLibs;
return WhitelistedLibs;
}

FString GetRuntimeLibsDirectory()
{
FString BinariesDirectory;
FString BinariesDirectory;

#if WITH_EDITOR
#ifdef AZSPEECH_THIRDPARTY_BINARY_SUBDIR
const TSharedPtr<IPlugin> PluginInterface = IPluginManager::Get().FindPlugin("AzSpeech");
BinariesDirectory = FPaths::Combine(PluginInterface->GetBaseDir(), TEXT("Source"), TEXT("ThirdParty"), TEXT("AzureWrapper"), TEXT(AZSPEECH_THIRDPARTY_BINARY_SUBDIR));
const TSharedPtr<IPlugin> PluginInterface = IPluginManager::Get().FindPlugin("AzSpeech");
BinariesDirectory = FPaths::Combine(PluginInterface->GetBaseDir(), TEXT("Source"), TEXT("ThirdParty"), TEXT("AzureWrapper"), TEXT(AZSPEECH_THIRDPARTY_BINARY_SUBDIR));
#endif
#else
BinariesDirectory = FPaths::GetPath(FPlatformProcess::ExecutablePath());
BinariesDirectory = FPaths::Combine(BinariesDirectory, TEXT("ThirdParty"), TEXT("AzSpeech"));
BinariesDirectory = FPaths::GetPath(FPlatformProcess::ExecutablePath());
BinariesDirectory = FPaths::Combine(BinariesDirectory, TEXT("ThirdParty"), TEXT("AzSpeech"));
#endif

if (AzSpeech::Internal::HasEmptyParam(BinariesDirectory))
{
UE_LOG(LogAzSpeech_Internal, Error, TEXT("%s: Failed to get the location of the runtime libraries. Please check and validate your installation."), *FString(__func__));
return FString();
}
if (AzSpeech::Internal::HasEmptyParam(BinariesDirectory))
{
UE_LOG(LogAzSpeech_Internal, Error, TEXT("%s: Failed to get the location of the runtime libraries. Please check and validate your installation."), *FString(__func__));
return FString();
}

FPaths::NormalizeDirectoryName(BinariesDirectory);
FPaths::NormalizeDirectoryName(BinariesDirectory);

#if PLATFORM_HOLOLENS
FPaths::MakePathRelativeTo(BinariesDirectory, *(FPaths::RootDir() + TEXT("/")));
FPaths::MakePathRelativeTo(BinariesDirectory, *(FPaths::RootDir() + TEXT("/")));
#endif

return BinariesDirectory;
return BinariesDirectory;
}

void LogLastError(const FString& FailLib)
{
const uint32 ErrorID = FPlatformMisc::GetLastError();
TCHAR ErrorBuffer[MAX_SPRINTF];
FPlatformMisc::GetSystemErrorMessage(ErrorBuffer, MAX_SPRINTF, ErrorID);
const uint32 ErrorID = FPlatformMisc::GetLastError();
TCHAR ErrorBuffer[MAX_SPRINTF];
FPlatformMisc::GetSystemErrorMessage(ErrorBuffer, MAX_SPRINTF, ErrorID);

UE_LOG(LogAzSpeech_Internal, Warning, TEXT("%s: Failed to load runtime library \"%s\": %u (%s)."), *FString(__func__), *FailLib, ErrorID, ErrorBuffer);
UE_LOG(LogAzSpeech_Internal, Warning, TEXT("%s: Failed to load runtime library \"%s\": %u (%s)."), *FString(__func__), *FailLib, ErrorID, ErrorBuffer);
}

void FAzSpeechModule::LoadRuntimeLibraries()
{
const FString BinariesDirectory = GetRuntimeLibsDirectory();
const TArray<FString> WhitelistedLibs = GetWhitelistedRuntimeLibs();

UE_LOG(LogAzSpeech_Internal, Display, TEXT("%s: Loading runtime libraries in directory \"%s\"."), *FString(__func__), *BinariesDirectory);

FPlatformProcess::PushDllDirectory(*BinariesDirectory);

for (const FString& RuntimeLib : WhitelistedLibs)
{
void* Handle = nullptr;

// Attempt to load the file more than one time in case of a temporary lock
constexpr unsigned int MaxAttempt = 5u;
constexpr float AttemptSleepDelay = 0.5f;
for (unsigned int Attempt = 1u; !Handle && Attempt <= MaxAttempt; ++Attempt)
{
if (Attempt > 1u)
{
FPlatformProcess::Sleep(AttemptSleepDelay);
}

UE_LOG(LogAzSpeech_Internal, Display, TEXT("%s: Attempting to load runtime library \"%s\" (%u/%u)."), *FString(__func__), *RuntimeLib, Attempt, MaxAttempt);
if (Handle = FPlatformProcess::GetDllHandle(*RuntimeLib); Handle)
{
break;
}
}

if (!Handle)
{
LogLastError(FPaths::Combine(BinariesDirectory, RuntimeLib));
continue;
}

UE_LOG(LogAzSpeech_Internal, Display, TEXT("%s: Loaded runtime library \"%s\"."), *FString(__func__), *RuntimeLib);
RuntimeLibraries.Add(Handle);
}

FPlatformProcess::PopDllDirectory(*BinariesDirectory);
const FString BinariesDirectory = GetRuntimeLibsDirectory();
const TArray<FString> WhitelistedLibs = GetWhitelistedRuntimeLibs();

UE_LOG(LogAzSpeech_Internal, Display, TEXT("%s: Loading runtime libraries in directory \"%s\"."), *FString(__func__), *BinariesDirectory);

FPlatformProcess::PushDllDirectory(*BinariesDirectory);

for (const FString& RuntimeLib : WhitelistedLibs)
{
void* Handle = nullptr;

// Attempt to load the file more than one time in case of a temporary lock
constexpr unsigned int MaxAttempt = 5u;
constexpr float AttemptSleepDelay = 0.5f;
for (unsigned int Attempt = 1u; !Handle && Attempt <= MaxAttempt; ++Attempt)
{
if (Attempt > 1u)
{
FPlatformProcess::Sleep(AttemptSleepDelay);
}

UE_LOG(LogAzSpeech_Internal, Display, TEXT("%s: Attempting to load runtime library \"%s\" (%u/%u)."), *FString(__func__), *RuntimeLib, Attempt, MaxAttempt);
if (Handle = FPlatformProcess::GetDllHandle(*RuntimeLib); Handle)
{
break;
}
}

if (!Handle)
{
LogLastError(FPaths::Combine(BinariesDirectory, RuntimeLib));
continue;
}

UE_LOG(LogAzSpeech_Internal, Display, TEXT("%s: Loaded runtime library \"%s\"."), *FString(__func__), *RuntimeLib);
RuntimeLibraries.Add(Handle);
}

FPlatformProcess::PopDllDirectory(*BinariesDirectory);
}

void FAzSpeechModule::UnloadRuntimeLibraries()
{
UE_LOG(LogAzSpeech_Internal, Display, TEXT("%s: Unloading runtime libraries."), *FString(__func__));
UE_LOG(LogAzSpeech_Internal, Display, TEXT("%s: Unloading runtime libraries."), *FString(__func__));

for (void*& Handle : RuntimeLibraries)
{
if (!Handle)
{
continue;
}
for (void*& Handle : RuntimeLibraries)
{
if (!Handle)
{
continue;
}

FPlatformProcess::FreeDllHandle(Handle);
Handle = nullptr;
}
FPlatformProcess::FreeDllHandle(Handle);
Handle = nullptr;
}

RuntimeLibraries.Empty();
RuntimeLibraries.Empty();
}
#endif

void FAzSpeechModule::StartupModule()
{
const TSharedPtr<IPlugin> PluginInterface = IPluginManager::Get().FindPlugin("AzSpeech");
UE_LOG(LogAzSpeech_Internal, Display, TEXT("Initializing plugin %s version %s."), *PluginInterface->GetFriendlyName(), *PluginInterface->GetDescriptor().VersionName);
const TSharedPtr<IPlugin> PluginInterface = IPluginManager::Get().FindPlugin("AzSpeech");
UE_LOG(LogAzSpeech_Internal, Display, TEXT("Initializing plugin %s version %s."), *PluginInterface->GetFriendlyName(), *PluginInterface->GetDescriptor().VersionName);

#if !PLATFORM_ANDROID && !UE_BUILD_SHIPPING
if (FPaths::DirectoryExists(UAzSpeechHelper::GetAzSpeechLogsBaseDir()))
{
IFileManager::Get().DeleteDirectory(*UAzSpeechHelper::GetAzSpeechLogsBaseDir(), false, true);
}
if (FPaths::DirectoryExists(UAzSpeechHelper::GetAzSpeechLogsBaseDir()))
{
IFileManager::Get().DeleteDirectory(*UAzSpeechHelper::GetAzSpeechLogsBaseDir(), false, true);
}
#endif

#ifdef AZSPEECH_WHITELISTED_BINARIES
LoadRuntimeLibraries();
LoadRuntimeLibraries();
#endif

#if WITH_EDITOR && !AZSPEECH_SUPPORTED_PLATFORM
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString("Currently, AzSpeech does not officially support the platform you're using/targeting. If you encounter any issue and can/want to contribute, get in touch! :)\n\nRepository Link: github.com/lucoiso/UEAzSpeech"));
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString("Currently, AzSpeech does not officially support the platform you're using/targeting. If you encounter any issue and can/want to contribute, get in touch! :)\n\nRepository Link: github.com/lucoiso/UEAzSpeech"));
#endif
}

void FAzSpeechModule::ShutdownModule()
{
const TSharedPtr<IPlugin> PluginInterface = IPluginManager::Get().FindPlugin("AzSpeech");
UE_LOG(LogAzSpeech_Internal, Display, TEXT("Shutting down plugin %s version %s."), *PluginInterface->GetFriendlyName(), *PluginInterface->GetDescriptor().VersionName);
const TSharedPtr<IPlugin> PluginInterface = IPluginManager::Get().FindPlugin("AzSpeech");
UE_LOG(LogAzSpeech_Internal, Display, TEXT("Shutting down plugin %s version %s."), *PluginInterface->GetFriendlyName(), *PluginInterface->GetDescriptor().VersionName);

#ifdef AZSPEECH_WHITELISTED_BINARIES
UnloadRuntimeLibraries();
UnloadRuntimeLibraries();
#endif
}

#undef LOCTEXT_NAMESPACE
#undef AZSPEECH_SUPPORTED_PLATFORM

IMPLEMENT_MODULE(FAzSpeechModule, AzSpeech)
IMPLEMENT_MODULE(FAzSpeechModule, AzSpeech)
Loading

0 comments on commit 9b11ed9

Please sign in to comment.