I want to convert an audio file (.wav/.mp3) to a byte array like in C#. Here's my code,
string imageName = Guid.NewGuid().ToString() + ".mp3";
byte[] file = System.Convert.FromBase64String(Filep);
File.WriteAllBytes(Server.MapPath("FILE/" + imageName), file);
return imageName;
If you want to read the raw audio data, use audioread
. You call it like so:
[y,Fs] = audioread(filename);
filename
would be the file name of your file (.mp3/.wav) and what is returned is a matrix of values stored in y
and the sampling frequency of the file in Fs
. y
would be a matrix such that the number of rows tells you the number of samples that your audio consists of, and the number of columns tells you how many channels the audio has. For example, mono audio would be a single column vector while stereo audio would be a two-column matrix: the first column being the left channel and the second column being the right channel.
For more information, check out the MathWorks doc I linked you to above.
来源:https://stackoverflow.com/questions/27631005/convert-audio-file-to-a-byte-array-in-matlab