how about convert wav file to base64 via function library c++?

how about convert wav file to base64 via function library c++?

Hello :).

Just fyi, someone needs a little more context to help out. Just converting bytes to Base64 via Unreal Engine c++ is easy (the docs are online).

But how to load or access it’s bytes so that you can do the conversion depends on where the file came from and when you’re trying to do the conversion. If you’re importing it as an asset in the editor, that’s completely different than if you have a wav file coming from a microphone api, which is completely different than if you have a file in the file system you’re processing from the editor… Etc.

Could you can explain a little more about what you’re trying to do and why?

1 Like

thankyou so much for your reply.
yep , i’m assigned create function blueprint about converting Wav file (import from ) to Base64 for next ASR (audio speech recognition).

How can I find example about that?

thankyou so much

To call the Base64 API’s in UE, your module would need to include the ‘Core’ module. Then it can call FBase64::Encode()…

You include modules by editing your module’s *.Build.cs file. Your file probably already has a line like this:

		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

And that will cause UE to include the Core, CoreUObject, Engine, and InputCore modules, which means you and call the Base64 Encoder. Once the module is included you can include the Base64 header file:

#include "Misc/Base64.h"

So, hopefully you have a wav file in memory from your API an you can do use this API to get a Base64 string:

Source/Runtime/Core/Public/Misc/Base64.h.

	/**
	 * Encodes the source into a Base64 string
	 *
	 * @param Source The binary data to encode
	 * @param Length Length of the binary data to be encoded
	 *
	 * @return Base64 encoded string containing the binary data.
	 */
	static FString Encode(const uint8* Source, uint32 Length);
1 Like

yeah , i’m already setting in *.Build.cs file and .

but how i can convert wave file from USoundWave to The binary data to encode.

Thankyou so much from your support.

Hi! Could you plaese help me to solve Base64ToImage frome json file? Thanks!
Here is i got some code from internet:

UTexture2D* UMyBlueprintFunctionLibrary::Base64_ToImage(FString Source)
{
TArray data_buffer;
bool isDecode = FBase64::Decode(Source, data_buffer);
if (isDecode) {
return CreateBitTextureAtRuntime(data_buffer);
}
else {
return nullptr;
}
}
UTexture2D* UMyBlueprintFunctionLibrary::CreateBitTextureAtRuntime(TArray& BGRA8PixelData)
{
const float Resolution = FGenericPlatformMath::Sqrt(BGRA8PixelData.Num() / 4);
UTexture2D* Texture = UTexture2D::CreateTransient(Resolution, Resolution, PF_B8G8R8A8);
FTexture2DMipMap& Mip = Texture->PlatformData->Mips[0];
const int32 BufferSize = BGRA8PixelData.Num();
void* MipBulkData = Mip.BulkData.Lock(LOCK_READ_WRITE);
Mip.BulkData.Realloc(BufferSize);
FMemory::Memcpy(MipBulkData, BGRA8PixelData.GetData(), BufferSize);
Mip.BulkData.Unlock();
Texture->UpdateResource();

return Texture;

}

I am also converting audio to base 64, facing encoding issues

Hy do you find any help in this.?