gtreshchev / RuntimeAudioImporter

Runtime Audio Importer plugin for Unreal Engine. Importing audio of various formats at runtime.
MIT License
336 stars 69 forks source link

Streaming Sound Wave playback keeps being reset to 0 #60

Closed quantumlover closed 8 months ago

quantumlover commented 8 months ago

Hello everyone, nice to meet you 👋

I got an issue with audio streaming and it feels like I am stack. Spent around three days on that already.

I receive audio bytes from my python server using web sockets. After that I feed it to Append Audio Data from Encoded. Looks like it works as expected in general. But it keeps resetting my sound wave playback time to 0 every time it receives new data. When it receives the last chunk it plays the whole message from the very start to the very end. I thought that maybe somehow I feed wrong data. But I am not sure.

The error looks like that and I receive them every time I process new data chunk:

Validity of PCM data in memory: Valid, number of PCM frames: 2304, PCM data size: 2304
LogRuntimeAudioImporter: Stopping the active sound 'BP_TEST_C_2' because it is using the same sound wave 'StreamingSoundWave_7' (only one imported sound wave can be played at a time)
LogRuntimeAudioImporter: The playback time for the sound wave 'StreamingSoundWave_7' will be set to '0.000000'
LogRuntimeAudioImporter: Stopping the active sound 'BP_TEST_C_2' because it is using the same sound wave 'StreamingSoundWave_7' (only one imported sound wave can be played at a time)

Even though I initialize Streaming Sound Wave at begin play event and set it to variable. Which I then reuse. I attached a screenshot with my blueprint logic. Any advice is appreciated as I am not sure what else to try. Thank you.

image

gtreshchev commented 8 months ago

Hi, the reason for this behavior, where playback starts from 0 each time audio data is populated, is simply because you're calling the PlaySound2D function every time after you call AppendAudioDataFromEncoded. If you want to play it persistently as you receive your audio data, you should call the PlaySound2D function only once, such as on Begin Play, and then only call the AppendAudioDataFromEncoded. This should resolve your issue.

quantumlover commented 8 months ago

Thank you very much. Looks like I was code blind. Your suggestion helped.