我目前对此很陌生,所以请保持简单易懂。
我有一个项目,我必须将声音分类为好,坏或中立。我的计划是获取样本数据集的所有频率和音高,并使用SVM训练它们。
为了获得所有.wav文件的音高和频率。我做了代码,从音频文件中找到PCM数据。现在我该如何将这些数据应用于快速傅里叶变换算法以获得频率?在将字节数组应用于FFT算法之前还有更多的事情需要考虑吗?
这是我将wav文件转换为pcm字节数组的代码:
int totalFramesRead = 0;
File fileIn = new File(inputFile);
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(fileIn);
int bytesPerFrame = audioInputStream.getFormat().getFrameSize();
if (bytesPerFrame == AudioSystem.NOT_SPECIFIED) {
// some audio formats may have unspecified frame size
// in that case we may read any amount of bytes
bytesPerFrame = 1;
}
// Set an arbitrary buffer size of 1024 frames.
int numBytes = 1024 * bytesPerFrame;
byte[] audioBytes = new byte[numBytes];
try {
int numBytesRead = 0;
int numFramesRead = 0;
// Try to read numBytes bytes from the file.
while ((numBytesRead = audioInputStream.read(audioBytes)) != -1) {
// Calculate the number of frames actually read.
numFramesRead = numBytesRead / bytesPerFrame;
totalFramesRead += numFramesRead;
}
return audioBytes[];
}
答案 0 :(得分:0)