How do I string of data from this function

Hello,

I’ve found this function from stackoverflow here: http://stackoverflow.com/questions/5366727/convert-array-of-byte-values-to-base64-encoded-string-and-break-long-lines-java

The function:


function encode(data)
{
    var str = String.fromCharCode.apply(null,data);
    return btoa(str).replace(/.{76}(?=.)/g,'$&\
');
}

I’ve tried to convert an array of byte with the function unsuccessful.
My byte array of data looks like this:


ByteData = [78, 255, 98, 247, 156, ..., 160];

It is generated dynamically via dataview of Uint8Array like this:


ByteData = new Uint8Array(BitCount);

for (var i = 0; i < ByteData.length; ++i) {
     // ByteData.length = 2048
}

How do I generate the result that looks like this:


T2dnUwACAAAAAAAAAAA+HAAAAAAAAGyawCEBQGZpc2hlYWQAAwAAAAAAAAAAAAAA6AMAAAAAAAAAAAAAAAAAAOgDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABPZ2dTAAIAAAAAAAAAAINDAAAAAAAA9LkergEeAXZvcmJpcwAAAAACRKwAAAAAAAAA7gIAAAAAALgBT2dnUwAAAAAAAAAAAAA+HAAAAQAAAPvOJxcBUGZpc2JvbmUALAAAAINDAAADAAAARKwAAAAAAAABAAAAAAAAAAAAAAAAAAAAAgAAAAAAAABDb250ZW50LVR5cGU6IGF1ZGlvL3ZvcmJpcw0KT2dnUwAAAAAAAAAAAACDQwAAAQAAAGLSAC4Qdv

For further in formation it’s sound data. Once I convert the binary data to base64 format I can play it with the <audio> tag.

Hope I explain clearly and thanks in advance