감사합니다. 글쎄, 내가하려는 것은 .wav 파일 (짧은 오디오 만)을 가져 와서 int로 변환하는 것이고 모든 것이 오디오 ... 내가 왜이 일을하는지 묻는다면, 내가 arduino 프로젝트를하고 있기 때문에, 그리고 arduino가 노래를 연주하게하고, 그 일을 위해 int 배열이 필요하다. 모든 int는 톤입니다. 그래서 "멜로디 음표를 나타내는 int가 저장된 txt로 .wav 파일을 변환하는 작은 응용 프로그램을 작성하면이 값을 arduino 프로젝트 코드에 복사해야합니다"라고 생각했습니다. 이 모든 일이 끝나면 "당신의 문제는 무엇입니까?"라고 묻는 것일 수 있습니다. 나는 코드를 작성하고 "일하고있다"는 유일한 문제는 txt가 각 줄에 "1024"만을 가지고 있다는 것입니다 ... 그래서 분명히 문제가 있습니다. 모든 톤은 1024입니다. -_-wav 파일을 txt 파일로 변환
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();
}
}이 코드 비트 in
데이터의 1024 바이트를 판독
일반적인 접근 방법은 시작하기에 적합하지 않습니다. WAV 파일은 시간 영역 데이터를 저장합니다. 즉 신호 대 시간 (예를 들어, 440Hz 톤은 예를 들어 WAV 파일에서 440Hz 사인파의 샘플 값일 수있다). "톤"에 대한 개념은 주파수 도메인입니다. 즉, 신호 강도 대 주파수. WAV 파일의 원시 파형에서 "멜로디"정보를 추출하려면 몇 가지 유형의 주파수 분석 (이산 FFT 검색)을 수행하거나 하드웨어 측면을 수정하고 대신 Arduino에서 원시 디지털 오디오를 재생해야합니다 주파수를 매개 변수화하는 것. –
그건 그렇고, 파일 형식 자체에 대해서는 [잘 설명되어 있습니다] (https : //ccrma.stanford.edu/courses/422/projects/WaveFormat /), 여기 [http://www.labbookpages.co.uk/audio/javaWavFiles.html]에서 데이터를 읽는 좋은 예가 있습니다. 그러나 이미 작업을 수행하고있는 [AudioInputStream] (http://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/AudioInputStream.html)을 사용하는 것이 좋습니다 (WAV 이외의 형식도 지원합니다. http://sweb.cityu.edu.hk/sm1204/2012A/page20/index.html (Java Sound API와 통합 된 일부 FFT 라이브러리를 설명)을 참조하십시오. –
접근 방식이 올바른지 아닌지에 상관없이 대답의 코드에 문제가 발생했습니다. 희망이 도움이됩니다. – CharlieS