Hi,
I am trying to send an HTTP request at runtime with an audio file. The request takes a wav audio byte as parameter (multipart/form-data).
If I have access to the original wav file, I can read it as bytes array then send it directly using this tutorial. However, I would prefer not to use the original file as it may not exist anymore.
Audio files are imported in Unreal as USoundWave
. I am using USoundWave::GetImportedSoundWaveData()
to get the audio bytes. It seems that the header byte part is NOT included in the returned bytes, which is required for meâŚ
Do you know how to get or create the wav header file with my USoundWave ? Or, do you know any other method that could work (i tried using xdbxdbxâs answer but sadly it didnât work) ?
void Test(USoundWave* Audio, ...)
{
TArray<uint8> AudioBytes;
uint32 SR;
uint16 Channels;
if(Audio->GetImportedSoundWaveData(AudioBytes, SR, Channels))
{
UE_LOG(LogTemp, Warning, TEXT("PCM data size is %d"), AudioBytes.Num());
}
....
}
To view the uploaded file, I created a small REST API server using FastAPI. I printed the size of the file as well as the beginning and the end bytes.
This is what I have by sending the file directly (not through Unreal, i used Postman):
size is 46124
begin bytes are b'RIFF$\xb4\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00"V\x00\x00D\xac\x00\x00\x02\x00\x10\x00data\x00\xb4\x00\x00\x00\x00\x00\x00\x00\x00'
end bytes are b"\x86\x00\x86\x00\x86\x00\x82\x00\x82\x00{\x00\x7f\x00\x82\x00\x7f\x00\x7f\x00{\x00{\x00w\x00w\x00w\x00w\x00w\x00t\x00t\x00w\x00t\x00l\x00p\x00p\x00i\x00i\x00i\x00i\x00e\x00e\x00i\x00e\x00a\x00a\x00a\x00^\x00^\x00Z\x00W\x00W\x00W\x00S\x00L\x00L\x00L\x00D\x00D\x00A\x00A\x00=\x00=\x00:\x00:\x006\x002\x002\x00/\x00/\x00/\x00/\x00'\x00'\x00'\x00$\x00'\x00 \x00 \x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x19\x00\x19\x00\x15\x00\x15\x00\x15\x00\x12\x00\x12\x00\x0e\x00\x0e\x00\n\x00\n\x00\n\x00\x07\x00\x07\x00\x03\x00\x03\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
And this is what I have by sending the file through Unreal:
size is 46080
begin bytes are b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
end bytes are b"\x86\x00\x86\x00\x86\x00\x82\x00\x82\x00{\x00\x7f\x00\x82\x00\x7f\x00\x7f\x00{\x00{\x00w\x00w\x00w\x00w\x00w\x00t\x00t\x00w\x00t\x00l\x00p\x00p\x00i\x00i\x00i\x00i\x00e\x00e\x00i\x00e\x00a\x00a\x00a\x00^\x00^\x00Z\x00W\x00W\x00W\x00S\x00L\x00L\x00L\x00D\x00D\x00A\x00A\x00=\x00=\x00:\x00:\x006\x002\x002\x00/\x00/\x00/\x00/\x00'\x00'\x00'\x00$\x00'\x00 \x00 \x00\x1d\x00\x1d\x00\x1d\x00\x1d\x00\x19\x00\x19\x00\x15\x00\x15\x00\x15\x00\x12\x00\x12\x00\x0e\x00\x0e\x00\n\x00\n\x00\n\x00\x07\x00\x07\x00\x03\x00\x03\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
We can see that the header part of the file
RIFF$\xb4\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00"V\x00\x00D\xac\x00\x00\x02\x00\x10\x00data\x00\xb4 ...
is missing when I send the bytes through Unreal. How do I get/create it ?
Thanks for your help !