public class Recognizer
extends com.sun.jna.PointerType
implements java.lang.AutoCloseable
| Constructor and Description |
|---|
Recognizer(Model model,
float sampleRate)
Creates the recognizer object.
|
Recognizer(Model model,
float sampleRate,
SpeakerModel spkModel)
Creates the recognizer object with speaker recognition.
|
Recognizer(Model model,
float sampleRate,
java.lang.String grammar)
Creates the recognizer object with the phrase list.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptWaveForm(byte[] data,
int len)
Accept and process new chunk of voice data.
|
boolean |
acceptWaveForm(float[] data,
int len) |
boolean |
acceptWaveForm(short[] data,
int len) |
void |
close()
Releases recognizer object.
|
java.lang.String |
getFinalResult()
Returns speech recognition result.
|
java.lang.String |
getPartialResult()
Returns partial speech recognition.
|
java.lang.String |
getResult()
Returns speech recognition result
|
void |
reset()
Resets the recognizer.
|
void |
setGrammar(java.lang.String grammar)
Reconfigures recognizer to use grammar.
|
void |
setMaxAlternatives(int maxAlternatives)
Configures recognizer to output n-best results.
|
void |
setPartialWords(boolean partial_words)
Like above return words and confidences in partial results.
|
void |
setSpeakerModel(SpeakerModel spkModel)
Adds speaker model to already initialized recognizer.
|
void |
setWords(boolean words)
Enables words with times in the output
|
public Recognizer(Model model, float sampleRate) throws java.io.IOException
model - VoskModel containing static data for recognizer. Model can be
shared across recognizers, even running in different threads.sampleRate - The sample rate of the audio you are going to feed into the recognizer.
Make sure this rate matches the audio content, it is a common
issue causing accuracy problems.java.io.IOException - if the recognizer could not be createdpublic Recognizer(Model model, float sampleRate, SpeakerModel spkModel)
model - VoskModel containing static data for recognizer. Model can be
shared across recognizers, even running in different threads.sampleRate - The sample rate of the audio you are going to feed into the recognizer.
Make sure this rate matches the audio content, it is a common
issue causing accuracy problems.spkModel - speaker model for speaker identificationpublic Recognizer(Model model, float sampleRate, java.lang.String grammar)
model - VoskModel containing static data for recognizer. Model can be
shared across recognizers, even running in different threads.sampleRate - The sample rate of the audio you are going to feed into the recognizer.
Make sure this rate matches the audio content, it is a common
issue causing accuracy problems.grammar - The string with the list of phrases to recognize as JSON array of strings,
for example "["one two three four five", "[unk]"]".public void setMaxAlternatives(int maxAlternatives)
{
"alternatives": [
{ "text": "one two three four five", "confidence": 0.97 },
{ "text": "one two three for five", "confidence": 0.03 },
]
}
maxAlternatives - - maximum alternatives to return from recognition resultspublic void setWords(boolean words)
"result" : [{
"conf" : 1.000000,
"end" : 1.110000,
"start" : 0.870000,
"word" : "what"
}, {
"conf" : 1.000000,
"end" : 1.530000,
"start" : 1.110000,
"word" : "zero"
}, {
"conf" : 1.000000,
"end" : 1.950000,
"start" : 1.530000,
"word" : "zero"
}, {
"conf" : 1.000000,
"end" : 2.340000,
"start" : 1.950000,
"word" : "zero"
}, {
"conf" : 1.000000,
"end" : 2.610000,
"start" : 2.340000,
"word" : "one"
}],
words - - boolean valuepublic void setPartialWords(boolean partial_words)
partial_words - - boolean valuepublic void setSpeakerModel(SpeakerModel spkModel)
spkModel - Speaker recognition modelpublic boolean acceptWaveForm(byte[] data,
int len)
data - - audio data in PCM 16-bit mono formatlen - - length of the audio datapublic boolean acceptWaveForm(short[] data,
int len)
public boolean acceptWaveForm(float[] data,
int len)
public java.lang.String getResult()
{
"text" : "what zero zero zero one"
}
If alternatives enabled it returns result with alternatives, see also #setMaxAlternatives().
If word times enabled returns word time, see also #setWordTimes().public java.lang.String getPartialResult()
{
"partial" : "cyril one eight zero"
}
public java.lang.String getFinalResult()
public void setGrammar(java.lang.String grammar)
grammar - Set of phrases in JSON array of strings or "[]" to use default model graph.Recognizer(Model, float, String)public void reset()
public void close()
close in interface java.lang.AutoCloseable