Convert Byte Array to Wav File

Convert byte array to wav file

Try this:

System.IO.File.WriteAllBytes("yourfilepath.wav", bytes);

byte array to wav file

  1. Create separate methods: One to load audio, one to encrypt, one to decrypt, one to play the audio.
  2. Create unit tests so you can verify encryption and decryption (the value after decrypt must be the same as before encryption)
  3. You probably have working code to load and play audio already
  4. Put all four method calls into your test application and see if it still can play a sound

This will not solve your problem but give you a structured and maintainable approach. Very likely your encryption does not match the decryption.

You may want to replace your crypto efforts with Apache commons-crypto.
Look at their example for encryption/decryption of byte array. But since you want to stream the results, it may be even better to look at encryption/decryption of byte stream.

NAudio Convert Byte Array to Wav

This blog post explains how to use the WaveFileWriter class for this purpose:

byte[] testSequence = new byte[] { 0x1, 0x2, 0xFF, 0xFE };
using (WaveFileWriter writer = new WaveFileWriter(fileName, waveFormat))
{
writer.WriteData(testSequence, 0, testSequence.Length);
}

JavaScript converting audio byte array to wav file or valid AudioBuffer

Holy crap, i've finally figured it out. My solution ended up using this package.

Starting with a binary file that i need to read in a big-endian Float32 format:

import createBuffer from "audio-buffer-from"

var res = await fetch(response.url);
var buffer = await res.arrayBuffer();
var dataview = new DataView(buffer);
var mFloatArray = new Float32Array(buffer.byteLength / 4);

for (let i = 0; i < mFloatArray.length; i++) {
mFloatArray[i] = dataview.getFloat32(i*4);
}

audioBuffer = createBuffer(mFloatArray, { sampleRate: 16000 });
this.wavesurfer.loadDecodedBuffer(audioBuffer);

This successfully loaded into wavesurfer!

Convert byte array to .wav java

So, there are LOTS of .WAV formats, here's some documentation:

  • http://en.wikipedia.org/wiki/WAV
  • http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ (note endian changes)
  • http://www.lightlink.com/tjweber/StripWav/WAVE.html

It's not just a stream of data bytes, but it's close... Just a bit of header and you should be good.

I suppose you could also use something like http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/sampled/spi/AudioFileWriter.html



Related Topics



Leave a reply



Submit