Convert byte array to wav file
Try this:
System.IO.File.WriteAllBytes("yourfilepath.wav", bytes);
byte array to wav file
- Create separate methods: One to load audio, one to encrypt, one to decrypt, one to play the audio.
- Create unit tests so you can verify encryption and decryption (the value after decrypt must be the same as before encryption)
- You probably have working code to load and play audio already
- 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
How to Calculate Sum (Total) of Datatable Columns Using C#
Read and Parse a Json File in C#
How to Submit Disabled Input in ASP.NET MVC
C# Download Big File from Server With Less Memory Consumption
Select Multiple Fields from List in Linq
How to Make Blazor Http Get Json Async Request
How to Get a Specific Column Value from a Datatable
Download File from an ASP.NET Web API Method Using Angularjs
How to Automatically Increment Numbers in C#
How to Get Name by String Value from a .Net Resource (Resx) File
Unexpected Character Encountered While Parsing Value
How to Dynamically Adjust Table Column Width in Rdlc Report
How to Perform Join Between Multiple Tables in Linq Lambda
How to Refresh an Entity Framework Core Dbcontext
Generate C# Class from SQL Server Table Without Store Procedure
C# Double - Tostring() Formatting With Two Decimal Places But No Rounding
How to Save Mailmessage Object to Disk as *.Eml or *.Msg File