How to access USoundWave RawData in a runtime build?


I am trying to serialize a USoundWave to a .wav file. I had the following

						FArchive* WaveAr = IFileManager::Get().CreateFileWriter(*WaveFilePath, 0);

						const void* AudioData = SoundAsset->RawData.GetPayload().Get().GetData();
						uint64 AudioDataSize = SoundAsset->RawData.GetPayload().Get().GetSize();
						const void* AudioData = SoundAsset->RawData.LockReadOnly();
						int32 AudioDataSize = SoundAsset->RawData.GetBulkDataSize();
						WaveAr->Serialize((void*) AudioData, AudioDataSize);

Where SoundAsset is a USoundWave passed into the function.
However, it seems like in 5.1 and above, RawData was made editor only, so. Is there some other way I can access this data so I can use it similarly?

At the top of the file you can see

* If you need access to the underlying audio data, use GetImportedSoundWaveData and avoid touching this.

Hi, I’m sorry, what file does it say that in? Also, GetImportedSoundWaveData seems like it is also Editor only?

it’s in USoundWave => so inside of SoundWave.h and SoundWave.cpp
Yeah after taking a longer look it seems to be editor only.

I think the audio may be automatically compressed on build.
You may need to run it through AudioDecompressor to uncompress it and read the data
AudioDevice.cpp seems to have an working decompression syntax.


Perhaps you could use Audio.h

/** Utility to serialize raw PCM data into a wave file. */
ENGINE_API void SerializeWaveFile(TArray<uint8>& OutWaveFileData, const uint8* InPCMData, const int32 NumBytes, const int32 NumChannels, const int32 SampleRate);