Java voice recognition for very small dictionary
The accuracy on such task must be 100%. Here is the code sample to use with the grammar:
public class TranscriberDemoGrammar {
public static void main(String[] args) throws Exception {
System.out.println("Loading models...");
Configuration configuration = new Configuration();
configuration.setAcousticModelPath("file:en-us-8khz");
configuration.setDictionaryPath("cmu07a.dic");
configuration.setGrammarPath("file:./");
configuration.setGrammarName("digits");
configuration.setUseGrammar(true);
StreamSpeechRecognizer recognizer =
new StreamSpeechRecognizer(configuration);
InputStream stream = new FileInputStream(new File("file.wav"));
recognizer.startRecognition(stream);
SpeechResult result;
while ((result = recognizer.getResult()) != null) {
System.out.format("Hypothesis: %s\n",
result.getHypothesis());
}
recognizer.stopRecognition();
}
}
You also need to make sure that both sample rate and audio bandwidth matches the decoder configuration
http://cmusphinx.sourceforge.net/wiki/faq#qwhat_is_sample_rate_and_how_does_it_affect_accuracy
Use the microphone in java for speech recognition with VOSK
this code work correctly for me you can use this:
public static void main(String[] args) {
LibVosk.setLogLevel(LogLevel.DEBUG);
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 60000, 16, 2, 4, 44100, false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
TargetDataLine microphone;
SourceDataLine speakers;
try (Model model = new Model("model");
Recognizer recognizer = new Recognizer(model, 120000)) {
try {
microphone = (TargetDataLine) AudioSystem.getLine(info);
microphone.open(format);
microphone.start();
ByteArrayOutputStream out = new ByteArrayOutputStream();
int numBytesRead;
int CHUNK_SIZE = 1024;
int bytesRead = 0;
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, format);
speakers = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
speakers.open(format);
speakers.start();
byte[] b = new byte[4096];
while (bytesRead <= 100000000) {
numBytesRead = microphone.read(b, 0, CHUNK_SIZE);
bytesRead += numBytesRead;
out.write(b, 0, numBytesRead);
speakers.write(b, 0, numBytesRead);
if (recognizer.acceptWaveForm(b, numBytesRead)) {
System.out.println(recognizer.getResult());
} else {
System.out.println(recognizer.getPartialResult());
}
}
System.out.println(recognizer.getFinalResult());
speakers.drain();
speakers.close();
microphone.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Getting started with Speech Recognition and Sphinx
Make sure to inspect the file carefully. According to the docs your file must be either 8khz or 16khz and mono only. There are many tools available to do this -- I use audacity, but probably overkill for just a basic conversion like this.
Search Data by voice recognition instead of typing in text box
Voice recognition is itself a big industry, someone can speak in native language, others can say two zero one or two hundred one and many other combinations.Again its an application - web based / mobile based / desktop based the API features will be according.
Is there an API for voice recognition of a person used for authentication
You can use this library to differentiate users on the basis of Audio Input, It works pretty well for me. https://github.com/amaurycrickx/recognito
implement Voice recognition for number detection in android
there are a few examples here on SO for offline speach recongnition. Check this und this. In the second one they are also talking about the google speech api which works since api level 23 offline. This are generell voice recongnition and here are someone that cuts out only the numbers of it.
Related Topics
Calling a Servlet from Jsp File on Page Load
How to Check the Jdk Version Used to Compile a .Class File
What Is This Date Format? 2011-08-12T20:17:46.384Z
A Quick and How to Join Array Elements With a Separator (The Opposite of Split) in Java
Spring Security Does Not Allow CSS or Js Resources to Be Loaded
Add Buttons to Tabs and Tab Area Javafx
When Exactly Is It Leak Safe to Use (Anonymous) Inner Classes
How to Parse a Dynamic JSON Key in a Nested JSON Result
Replacing a Fragment with Another Fragment Inside Activity Group
Access Viewpager Fragment Method from Activity
What Determines the Current Working Directory of Tomcat Java Process
Itext Get Field Coordinates from Existing PDF
Exception in Thread "Main" Java.Lang.Noclassdeffounderror: Org/Apache/Hadoop/Util/Platformname
Object Header Size in Java on 64Bit Vm with <4Gb Ram