Convert audio file to a byte array in matlab

爷,独闯天下 提交于 2019-12-03 00:51:50

问题


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;

回答1:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!