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

Commit

Permalink
Adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
lucoiso committed Mar 15, 2024
1 parent 446608d commit 58e065b
Show file tree
Hide file tree
Showing 83 changed files with 4,698 additions and 4,477 deletions.
86 changes: 43 additions & 43 deletions AzSpeech.uplugin
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
{
"FileVersion": 3,
"Version": 33,
"VersionName": "1.6.16",
"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",
"CreatedBy": "Lucas Vilas-Boas",
"CreatedByURL": "https://github.com/lucoiso",
"DocsURL": "https://github.com/lucoiso/UEAzSpeech/wiki",
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/94ad3e51c6f443718cdb312b48742bb3",
"SupportURL": "https://github.com/lucoiso/UEAzSpeech/issues",
"CanContainContent": false,
"IsBetaVersion": true,
"IsExperimentalVersion": false,
"Installed": false,
"Modules": [
{
"Name": "AzSpeech",
"Type": "Runtime",
"LoadingPhase": "Default",
"PlatformAllowList": [
"Win64",
"Android"
]
},
{
"Name": "AzSpeechEditor",
"Type": "Editor",
"LoadingPhase": "Default",
"PlatformAllowList": [
"Win64",
"Mac",
"Linux"
]
}
],
"Plugins": [
{
"Name": "AndroidPermission",
"Enabled": true,
"Optional": true
}
]
"FileVersion": 3,
"Version": 34,
"VersionName": "1.6.17",
"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",
"CreatedBy": "Lucas Vilas-Boas",
"CreatedByURL": "https://github.com/lucoiso",
"DocsURL": "https://github.com/lucoiso/UEAzSpeech/wiki",
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/94ad3e51c6f443718cdb312b48742bb3",
"SupportURL": "https://github.com/lucoiso/UEAzSpeech/issues",
"CanContainContent": false,
"IsBetaVersion": true,
"IsExperimentalVersion": false,
"Installed": false,
"Modules": [
{
"Name": "AzSpeech",
"Type": "Runtime",
"LoadingPhase": "Default",
"PlatformAllowList": [
"Win64",
"Android"
]
},
{
"Name": "AzSpeechEditor",
"Type": "Editor",
"LoadingPhase": "Default",
"PlatformAllowList": [
"Win64",
"Mac",
"Linux"
]
}
],
"Plugins": [
{
"Name": "AndroidPermission",
"Enabled": true,
"Optional": true
}
]
}
274 changes: 137 additions & 137 deletions Config/DefaultAzSpeech.ini

Large diffs are not rendered by default.

57 changes: 27 additions & 30 deletions Source/AzSpeech/AzSpeech.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,36 @@

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");
}
}
164 changes: 85 additions & 79 deletions Source/AzSpeech/Private/AzSpeech.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,127 +27,132 @@
#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());
#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("/")));
#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
Expand All @@ -157,15 +162,16 @@ void FAzSpeechModule::StartupModule()

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 58e065b

Please sign in to comment.