Reputation: 3055
I have done these steps
1- downloaded latest version of Sphinx4 from https://sourceforge.net/projects/cmusphinx/files/sphinx4/5prealpha/
2- installed Gradle IDE Pack 3.8.x + 1.0.x in Eclipse (Gradle plugin).
3- Imported Sphinx4 as Gradle STS project.
Now I got errors as shown in below picture
For the sake of time I have commented these errors because I don't know why these errors I am getting.
Now I want to RUN Sphinx4 but I dont know what to run and how to run. I have done my best with google and trying to do for days. but did not got positive results.
If any one can help me to solve the issue and guide me how to run sphinx4 as gradle that would be great. As you can see there are 4 projects sphinx so Which one to run.
That might be silly to ask, "If I run successfully what would be output"
PS: I am new to Gradle and Sphinx4 and also have taken look at this link
Upvotes: 1
Views: 247
Reputation: 7255
You can find tutorials: -> here <-
Although i am adding the jars to the classpath differently it will work for you.
Simple example code:
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Port;
import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
import edu.cmu.sphinx.api.SpeechResult;
public class Main {
// Logger
private Logger logger = Logger.getLogger(getClass().getName());
// Variables
private String result;
// Threads
Thread speechThread;
Thread resourcesThread;
// LiveRecognizer
private LiveSpeechRecognizer recognizer;
/**
* Constructor
*/
public Main() {
// Loading Message
logger.log(Level.INFO, "Loading..\n");
// Configuration
Configuration configuration = new Configuration();
// Load model from the jar
configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
// if you want to use LanguageModelPath disable the 3 lines after which
// are setting a custom grammar->
// configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin")
// Grammar
configuration.setGrammarPath("resource:/grammars");
configuration.setGrammarName("grammar");
configuration.setUseGrammar(true);
try {
recognizer = new LiveSpeechRecognizer(configuration);
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
}
// Start recognition process pruning previously cached data.
recognizer.startRecognition(true);
// Start the Thread
startSpeechThread();
startResourcesThread();
}
/**
* Starting the main Thread of speech recognition
*/
protected void startSpeechThread() {
// alive?
if (speechThread != null && speechThread.isAlive())
return;
// initialise
speechThread = new Thread(() -> {
logger.log(Level.INFO, "You can start to speak...\n");
try {
while (true) {
/*
* This method will return when the end of speech is
* reached. Note that the end pointer will determine the end
* of speech.
*/
SpeechResult speechResult = recognizer.getResult();
if (speechResult != null) {
result = speechResult.getHypothesis();
System.out.println("You said: [" + result + "]\n");
// logger.log(Level.INFO, "You said: " + result + "\n")
} else
logger.log(Level.INFO, "I can't understand what you said.\n");
}
} catch (Exception ex) {
logger.log(Level.WARNING, null, ex);
}
logger.log(Level.INFO, "SpeechThread has exited...");
});
// Start
speechThread.start();
}
/**
* Starting a Thread that checks if the resources needed to the
* SpeechRecognition library are available
*/
protected void startResourcesThread() {
// alive?
if (resourcesThread != null && resourcesThread.isAlive())
return;
resourcesThread = new Thread(() -> {
try {
// Detect if the microphone is available
while (true) {
if (AudioSystem.isLineSupported(Port.Info.MICROPHONE)) {
// logger.log(Level.INFO, "Microphone is available.\n")
} else {
// logger.log(Level.INFO, "Microphone is not
// available.\n")
}
// Sleep some period
Thread.sleep(350);
}
} catch (InterruptedException ex) {
logger.log(Level.WARNING, null, ex);
resourcesThread.interrupt();
}
});
// Start
resourcesThread.start();
}
/**
* Takes a decision based on the given result
*/
public void makeDesicion(String result) {
//implemented in the part 2
}
/**
* Java Main Application Method
*
* @param args
*/
public static void main(String[] args) {
// // Be sure that the user can't start this application by not giving
// the
// // correct entry string
// if (args.length == 1 && "SPEECH".equalsIgnoreCase(args[0]))
new Main();
// else
// Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Give me
// the correct entry string..");
}
}
Grammar File:
#JSGF V1.0;
/**
* JSGF Grammar
*/
grammar grammar;
public <numbers> = (one | two | three| four| five | six | seven | eight | nine | ten);
public <action> = (plus | minus | multiply | division);
public <final> = (show result);
Upvotes: 1
Reputation: 1452
These errors occur because your encoding isn't set right.
In Eclipse go to Edit -> Set Encoding -> UTF-8
Upvotes: 0
Reputation: 25220
Tutorial says
A number of sample demos are included in sphinx4 sources in order to give you understanding how to run Sphinx4. You can run them from sphinx4-samples jar:
You just need to read it carefully.
Upvotes: 1