Hi,
I am getting an audio wav file bytes data from an HTTP response and I am trying to make a SoundWave and play it at runtime.
In order to make the HTTP Request I use the C++ HTTP Module and I get the bytes using FHttpResponsePtr->GetContent()
.
In order to create the SoundWave I use FWaveModInfo combined with FSoundWavePCMWriter:
USoundWave* WavBytesToSoundWave(const TArray<uint8>& AudioBytes, bool& Success, FString& OutReason)
{
// from: https://github.com/getnamo/SocketIOClient-Unreal/blob/master/Source/CoreUtility/Private/CUBlueprintLibrary.cpp#L281
// and: https://forums.unrealengine.com/t/loading-raw-wav-in-runtime-into-usoundwave/126017
// and: https://medium.com/@bdmccowan/how-to-use-audio-capture-component-and-audio-capture-in-unreal-c-59a78c13221
FWaveModInfo WaveModInfo;
Success = WaveModInfo.ReadWaveInfo(AudioBytes.GetData(), AudioBytes.Num(), &OutReason);
if(Success)
{
UE_LOG(LogTemp, Display, TEXT("NUM SAMPLE IS %d, SAMPLE DATA SIZE IS %d"), WaveModInfo.GetNumSamples(), WaveModInfo.SampleDataSize);
Audio::FSoundWavePCMWriter Writer;
TArray<int16> ConvertedArray;
ConvertedArray.Reset(WaveModInfo.GetNumSamples());
ConvertedArray.AddUninitialized(WaveModInfo.GetNumSamples());
for(uint32 i = 0; i < WaveModInfo.SampleDataSize; i+=2)
{
ConvertedArray[i/2] = static_cast<int16>(WaveModInfo.SampleDataStart[i]) | static_cast<int16>(WaveModInfo.SampleDataStart[i + 1]) << 8;
}
Audio::FSampleBuffer Buffer(ConvertedArray.GetData(), WaveModInfo.GetNumSamples(), *WaveModInfo.pChannels, *WaveModInfo.pSamplesPerSec);
USoundWave* SoundWave = Writer.SynchronouslyWriteSoundWave(Buffer);
UE_LOG(LogTemp, Display, TEXT("SOUNDWAVE DURATION: %f"), SoundWave->Duration);
return SoundWave;
}
UE_LOG(LogTemp, Error, TEXT("Couldn't convert wav bytes to soundwave: %s"), *OutReason);
return nullptr;
}
It was working fine with the previous version of Unreal Engine, however with version 5.4 the created SoundWave is only played for a few milliseconds then stops automatically with no error message or crash. I am a bit lost on what to do because there is no error…
This is what I added to try to debug:
UE 5.3 (working):
LogBlueprintUserMessages: [Ariel_Demo_C_1] 129544
LogTemp: Display: NUM SAMPLE IS 64750, SAMPLE DATA SIZE IS 129500
LogTemp: Display: SOUNDWAVE DURATION: 2.697917
LogBlueprintUserMessages: [Ariel_Demo_C_1] PLAYING
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.007892
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.015799
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.023707
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.031614
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.031614
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.039521
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.047429
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.047429
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.055336
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.063243
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.071151
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.079058
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.086965
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.086965
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.094873
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.10278
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.10278
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.110687
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.118595
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.126502
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.134409
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.142317
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.142317
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.150224
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.158131
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.158131
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.166039
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.173946
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.181853
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.189761
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.197668
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.197668
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.205575
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.213483
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.213483
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.22139
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.229297
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.237205
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.245112
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.253019
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.253019
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.260927
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.268834
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.268834
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.276741
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.284649
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.292556
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.300463
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.308371
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.308371
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.316278
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.324185
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.324185
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.332093
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.34
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.347907
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.355815
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.363722
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.363722
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.371629
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.379537
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.387444
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.387444
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.395351
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.403259
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.411166
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.419073
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.419073
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.426981
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.434888
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.442795
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.442795
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.450703
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.45861
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.466517
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.474425
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.474425
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.482332
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.490239
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.498147
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.506054
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.506054
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.513961
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.521869
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.529776
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.529776
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.537683
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.545591
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.553498
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.561405
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.561405
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.569313
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.57722
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.585127
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.585127
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.593035
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.600942
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.608849
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.616757
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.624664
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.624664
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.632571
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.640479
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.640479
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.648386
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.656293
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.664201
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.672108
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.680015
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.680015
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.687923
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.69583
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.69583
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.703737
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.711645
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.719552
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.727459
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.735367
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.735367
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.743274
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.751181
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.751181
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.759089
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.766996
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.774903
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.782811
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.790718
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.790718
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.798625
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.806533
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.806533
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.81444
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.822347
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.830255
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.838162
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.84607
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.84607
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.853977
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.861884
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.861884
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.869792
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.877699
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.885606
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.893514
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.901421
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.901421
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.909328
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.917235
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.917235
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.925143
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.93305
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.940958
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.948865
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.956772
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.956772
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.96468
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.972587
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.980494
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.980494
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.988402
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.996309
LogBlueprintUserMessages: [Ariel_Demo_C_1] 1.0
LogBlueprintUserMessages: [Ariel_Demo_C_1] 1.0
LogBlueprintUserMessages: [Ariel_Demo_C_1] STOPPED
UE 5.4 (not working):
LogBlueprintUserMessages: [Ariel_Demo_C_1] 125944
LogTemp: Display: NUM SAMPLE IS 62950, SAMPLE DATA SIZE IS 125900
LogTemp: Display: SOUNDWAVE DURATION: 2.622917
LogBlueprintUserMessages: [Ariel_Demo_C_1] PLAYING
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.0
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.008118
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.016251
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.024384
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.024384
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.032518
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.040651
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.048785
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.048785
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.056918
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.065052
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.073185
LogBlueprintUserMessages: [Ariel_Demo_C_1] 0.073185
LogBlueprintUserMessages: [Ariel_Demo_C_1] STOPPED
Does someone have encounter the same problem? Does anyone have successfully created a SoundWave from bytes at runtime with Unreal 5.4? I would be very grateful if you could help me!
P.S: For now, I can useUSoundWaveProcedural
with QueueAudio()
method for UE 5.4. This works well, however this is not optimal since I want to be able to convert back the SoundWave to bytes array later on, and I couldn’t find a way to get the raw PCM data from an USoundWaveProcedural (which is kind of logic because a Procedural Sound does not have Raw Data)…