感谢您阅读本文,我想做的是获取一个.wav文件(仅一个简短的音频)并将其转换为int,每个代表音频的音调...如果您要问为什么我之所以这样做,是因为我正在做一个arduino项目,并且我想让arduino播放一首歌,为此,我需要一个int数组,其中每个int都是一个音调。因此,我想:“好吧,如果我编写一个小应用程序以将任何.wav文件转换为txt,并在其中存储代表旋律音符的整数,我只需要将此值复制到arduino项目代码中即可”;因此,毕竟,您可能会问“您的问题是什么?”;我完成了代码,并且“正常工作”,唯一的问题是txt每行仅包含“ 1024” ...因此,显然我遇到了问题,
package WaveToText;
import java.io.*;
/**
*
* @author Luis Miguel Mejía Suárez
* @project This porject is to convert a wav music files to a int array
* Which is going to be printed in a txt file to be used for an arduino
* @serial 1.0.1 (05/11/201)
*/
public final class Converter
{
/**
*
* @Class Here is where is going to be allowed all the code for the application
*
* @Param Text is an .txt file where is going to be stored the ints
* @Param MyFile is the input of the wav file to be converted
*/
PrintStream Text;
InputStream MyFile;
public Converter () throws FileNotFoundException, IOException
{
MyFile = new FileInputStream("C:\\Users\\luismiguel\\Dropbox\\ESTUDIO\\PROGRAMAS\\JAVA\\WavToText\\src\\WaveToText\\prueba.wav");
Text = new PrintStream(new File("Notes.txt"));
}
public void ConvertToTxt() throws IOException
{
BufferedInputStream in = new BufferedInputStream(MyFile);
int read;
byte[] buff = new byte[1024];
while ((read = in.read(buff)) > 0)
{
Text.println(read);
}
Text.close();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
// TODO code application logic here
Converter Exc = new Converter();
Exc.ConvertToTxt();
}
}
等等等等....很多事情都不在这里...。您不能只读取字节并将其发送给Arduino,因为正如您所说的那样,Arduino期望音符编号。Wav文件中的数字首先是带有音频信息的“标题”,然后是代表信号(波形)中离散点的数字。如果您想获取笔记,则需要一些用于音高检测或音乐转录的算法。
如果您的音乐是单声道的或接近单声道的,则音高检测可能会起作用。对于完整乐队的歌曲,这将很麻烦。
所以...
我想“ Arduino部分”将播放单声道音乐,并且您需要在特定时刻提取信号的基本频率(这称为音高检测,并且有不同的处理方式(自相关,amdf,频谱analisys)) 。您还必须保留音符的时间安排。
当您提取频率时,有一个公式可以将频率转换为代表钢琴上音符编号的整数。n = 12(log2(f / 440))+ 49其中n是整数音符编号,f是音符的基频。在计算之前,您还应该对从音高识别算法获得的频率进行量化(最精确的音符频率为google)。
但是我真的建议做更多的研究。在几乎没有乐器演奏,鼓,歌手都在一起的音乐中,很难检测到音符。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句