Having a hard time sending binary audio chunks

Issue #140 new
Former user created an issue

I'm using JSR223 to stream in audio file and store frames of 4096 bytes. I'm doing this in order to stream the audio to websocket in real time.

I've then tried to push each frame byte array into user variables like vars.putObject(audioData) where audioData is a type byte[] and then use that data in WebSocket Single Write Sampler like ${audioData}

However, the data is always getting being toString'd.

I've also tried vars.put("audioData", Base64.getEncoder().encodeToString(audioData)) and then accessed the data in WebSocket Single Write Sampler like ${__base64Decode(${wuwData})}

In this scenario i'm getting "request data is not binary". I notice that it seems to be expecting hex, but i've also tried the hex method but the server i'm connecting to is not expecting hex and therefore is not accepting it.

The only way i've been able to get this to work is to write each chunk to a file and then read request data from file. Seems like the binary file logic is different from the binary request data logic. Obviously this isn't a very scalable solution.

Is there any way to do this with this plugin?

Comments (3)

  1. Peter Doornbosch repo owner

    Hi,

    The sampler expects hex indeed, and converts this to binary before sending it to the server. Currently it is not possible to (programmatically) inject binary data in the sampler.

    The solution to your problem, is to convert the audioData to hex and use that data in the sampler. Your approach with the base64 encoding is still trying to write binary data in the sample, this won’t work. Just convert audioData to hex encoded String and use that in the sampler (which will convert the hex to binary again). Not very elegant and maybe the conversions harm performance, but it should work.

    In the long run, we could a checkbox to indicate the data passed into the sampler is already binary, that would be a nice improvement.

    Hth

    Peter

  2. Zak Lowman

    Okay, I tried the hex solution again and it worked this time. Not sure what I did the first time. I found a conversion function with decent performance on SO.

    I think that may be a worthwhile improvement. Thanks for you help!

    -Zak

  3. Log in to comment