Skip to content

Commit

Permalink
Merge pull request alphacep#151 from hviana/patch-1
Browse files Browse the repository at this point in the history
Add support for speaker model in Android
  • Loading branch information
nshmyrev authored Jun 22, 2020
2 parents e5c08f7 + 51c2968 commit b831c9a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions android/src/main/java/org/kaldi/SpeechRecognizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ public SpeechRecognizer(Model model) throws IOException {
}
}

public SpeechRecognizer(Model model, SpkModel spkModel) throws IOException {
recognizer = new KaldiRecognizer(model, spkModel, 16000.0f);
sampleRate = 16000;
bufferSize = Math.round(sampleRate * BUFFER_SIZE_SECONDS);
recorder = new AudioRecord(
AudioSource.VOICE_RECOGNITION, sampleRate,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT, bufferSize * 2);

if (recorder.getState() == AudioRecord.STATE_UNINITIALIZED) {
recorder.release();
throw new IOException(
"Failed to initialize recorder. Microphone might be already in use.");
}
}

/**
* Adds listener.
*/
Expand Down

0 comments on commit b831c9a

Please sign in to comment.