react-native passing ArrayBuffer or Uint16Array to native ReadableArray on Android-ThrowExceptions

Exception or error:

I’m receiving a PCM buffer from websocket onmessage method as result

    console.log('cleblanc length of TTS data ' + result.byteLength);
    const buff = new Uint16Array(result);
    console.log('cleblanc TTS data ' + buff);

and my native method

  public void playTts(ReadableArray readableArray)

It’s causing Malformed calls from JS: field sizes are different

I’d like to pass the data as a ReadableArray, but when I try using ReadableMap and passing result directly it results in the Java layer receiving an empty map. Should I try converting it to a String or is there a way to make this work.

How to solve:

So I wound up converting the ReadableArray to a base64 string like this;

new Buffer(result).toString('base64')

And then simply decoding it in the Java like this;

samples[producerIdx] = Base64.decode(data, Base64.DEFAULT);

Where samples is a new byte[32][];

Leave a Reply

Your email address will not be published. Required fields are marked *