Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- MongoDB
- 리액트
- Docker
- JavaScript
- vue.js
- MySQL
- REACT
- grafana
- spring
- Jenkins Pipeline
- grpc
- IntelliJ
- jpa
- jenkins github
- 리눅스
- Spring Boot
- jenkins jdk
- jenkins github 연동
- nginx
- jenkins 설치
- error
- Jenkins
- Linux
- gradle
- docker network
- CI/CD
- jenkins install
- subnetmask
- java
- jenkins maven
Archives
- Today
- Total
뭐든 즐기면서 ;)
java 음성 파일에서의 pitch 추출 방법 본문
728x90
'TarsosDSP' 라이브러리 사용.
build.gradle에 추가
repositories {
mavenCentral()
maven {
name = "TarsosDSP repository"
url = "https://mvn.0110.be/releases"
}
}
dependencies {
/*오디오 pitch 추출 라이브러리*/
implementation 'be.tarsos.dsp:core:2.5'
implementation 'be.tarsos.dsp:jvm:2.5'
}
java 적용 예제 코드
import be.tarsos.dsp.AudioDispatcher;
import be.tarsos.dsp.AudioEvent;
import be.tarsos.dsp.io.jvm.JVMAudioInputStream;
import be.tarsos.dsp.pitch.PitchDetectionHandler;
import be.tarsos.dsp.pitch.PitchDetectionResult;
import be.tarsos.dsp.pitch.PitchProcessor;
import org.springframework.stereotype.Service;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.File;
import java.io.IOException;
...
public void export() {
String audioFilePath = "C:\\Users\\mindslab\\Desktop\\sample\\음성\\examples_src_main_resources_happy.wav";
try {
AudioInputStream audioStream = AudioSystem.getAudioInputStream(new File(audioFilePath));
JVMAudioInputStream jvmAudioStream = new JVMAudioInputStream(audioStream);
AudioDispatcher dispatcher = new AudioDispatcher(jvmAudioStream, 1024, 0);
PitchDetectionHandler pitchHandler = new PitchDetectionHandler() {
@Override
public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
float pitchInHz = pitchDetectionResult.getPitch();
System.out.println(audioEvent.getTimeStamp() + ": Detected pitch: " + pitchInHz + " Hz");
}
};
PitchProcessor pitchProcessor = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.YIN, 44100, 1024, pitchHandler);
dispatcher.addAudioProcessor(pitchProcessor);
dispatcher.run();
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
728x90
Comments