Decimate by 4
This commit is contained in:
@@ -679,7 +679,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
|
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
|
||||||
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
|
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
|
||||||
|
|
||||||
sphinxConfig.setSampleRate((int)(book.getAudioFormat().getSampleRate() / 3f));
|
sphinxConfig.setSampleRate((int)(book.getAudioFormat().getSampleRate() / 4f));
|
||||||
|
|
||||||
StreamSpeechRecognizer recognizer;
|
StreamSpeechRecognizer recognizer;
|
||||||
|
|
||||||
|
|||||||
@@ -579,30 +579,23 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
setText("[recognising...]");
|
setText("[recognising...]");
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(this);
|
AudiobookRecorder.window.bookTreeModel.reload(this);
|
||||||
|
|
||||||
AudioInputStream s = AudioSystem.getAudioInputStream(getFile());
|
|
||||||
AudioFormat format = getAudioFormat();
|
AudioFormat format = getAudioFormat();
|
||||||
|
|
||||||
int frameSize = format.getFrameSize();
|
byte[] inData = getRawAudioData();
|
||||||
int length = (int)s.getFrameLength();
|
int inLength = inData.length;
|
||||||
byte[] data = new byte[length * frameSize];
|
int bps = format.getFrameSize();
|
||||||
|
int inSamples = inLength / bps;
|
||||||
|
|
||||||
s.read(data);
|
int outSamples = inSamples / 4;
|
||||||
|
byte[] outData = new byte[outSamples * bps];
|
||||||
|
|
||||||
int channels = format.getChannels();
|
for (int i = 0; i < outSamples; i++) {
|
||||||
int newLen = (length / 3);
|
for (int j = 0; j < bps; j++) {
|
||||||
byte[] decimated = new byte[newLen * 2];
|
outData[i * bps + j] = inData[(i * 4) * bps + j];
|
||||||
|
|
||||||
for (int i = 0; i < newLen; i++) {
|
|
||||||
if (channels == 1) {
|
|
||||||
decimated[i * 2] = data[i * 6];
|
|
||||||
decimated[i * 2 + 1] = data[i * 6 + 1];
|
|
||||||
} else {
|
|
||||||
decimated[i * 2] = data[i * 12];
|
|
||||||
decimated[i * 2 + 1] = data[i * 12 + 1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteArrayInputStream bas = new ByteArrayInputStream(decimated);
|
ByteArrayInputStream bas = new ByteArrayInputStream(outData);
|
||||||
recognizer.startRecognition(bas);
|
recognizer.startRecognition(bas);
|
||||||
SpeechResult result;
|
SpeechResult result;
|
||||||
String res = "";
|
String res = "";
|
||||||
@@ -633,7 +626,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
AudioInputStream s = AudioSystem.getAudioInputStream(getFile());
|
AudioInputStream s = AudioSystem.getAudioInputStream(getFile());
|
||||||
AudioFormat format = getAudioFormat();
|
AudioFormat format = getAudioFormat();
|
||||||
|
|
||||||
sphinxConfig.setSampleRate((int)(format.getSampleRate() / 3f));
|
sphinxConfig.setSampleRate((int)(format.getSampleRate() / 4f));
|
||||||
|
|
||||||
StreamSpeechRecognizer recognizer;
|
StreamSpeechRecognizer recognizer;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user