【发布时间】:2014-03-27 11:44:06
【问题描述】:
我正在尝试使用 Android 将 wav 文件读入数组。为了验证结果,我使用 Matlab 读取了相同的 wav 文件。问题是价值观不同。非常感谢您在解决此问题方面的帮助。 请在下面找到带有相关结果的 Matlab 和 Android 代码:
Matlab 代码:
fName = 'C:\Users\me\Desktop\audioText.txt';
fid = fopen(fName,'w');
dlmwrite(fName,y_sub,'-append','delimiter','\t','newline','pc');
Matlab 结果:
0.00097656 0.00045776 0.0010681 0.00073242 0.00054932 -0.00064087 0.0010376 -0.00027466 -0.00036621 -9.1553e-05 0.00015259 0.0021362 -0.00024414 -3.0518e-05 -0.00021362
安卓代码:
String filePath;
private static DataOutputStream fout;
ByteArrayOutputStream out;
BufferedInputStream in;
filePath = "mnt/sdcard/audio.wav";
out = new ByteArrayOutputStream();
try {
in = new BufferedInputStream(new FileInputStream(filePath));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int read;
byte[] buff = new byte[2000000];
try {
while ((read = in.read(buff)) > 0)
{
out.write(buff, 0, read);
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
out.flush();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
byte[] audioBytes = out.toByteArray();
}
Android 结果:
82、73、70、70、92、108、40、0、87、65、86、69、102、109
谢谢,
【问题讨论】:
-
你在测试传感器数据吗??
-
wav 文件是传感器数据的记录,但这有关系吗?
-
不,我没有。你有什么线索吗?
-
你知道WAV文件是怎么编码的吗? 16 位、24 位等?确保在将 WAV 文件中的值直接打印为文本时使用正确的位宽。此外,请确保使用正确的打印格式。我会说浮点数或十六进制最适合这样的比较。