Results 1 to 4 of 4
  1. #1
    treeface99 is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Default Sphinx 4 Voice Recognition acting WEIRD!

    hi

    I am performing speech recognition using sphinx4. I am implementing a game of blackjack and am using the speech recognition to input commands into the program such as 'start game' , 'stick' , 'twist' ect.

    I have altered Sphinx-4's helloWorld demo to look like this:

    Java Code:
    package edu.cmu.sphinx.demo.helloworld4;
    
    import edu.cmu.sphinx.frontend.util.Microphone;
    import edu.cmu.sphinx.recognizer.Recognizer;
    import edu.cmu.sphinx.result.Result;
    import edu.cmu.sphinx.util.props.ConfigurationManager;
    
    
    public class HelloWorld extends Thread {
    
    	public int speech =0;
    	public Recognizer recognizer;
    	public Result result;
    	
    
    
    	public HelloWorld(){
    		ConfigurationManager cm;
    
    
    		cm = new ConfigurationManager(HelloWorld.class.getResource("helloworld.config.xml"));			
    
    	
    		recognizer = (Recognizer) cm.lookup("recognizer");
    		recognizer.allocate();
    
    		// start the microphone or exit if the programm if this is not possible
    		Microphone microphone = (Microphone) cm.lookup("microphone");
    		if (!microphone.startRecording()) {
    			System.out.println("Cannot start microphone.");
    			recognizer.deallocate();
    			System.exit(1);
    		}}
    	public void run(){
    		
    
    	}
    	
    	
    
    	public int listen(){
    		//  public static void main(String[] args) {
    
    
    		System.out.println("Say: (Stick Or Twist or start)" );
    		// loop the recognition until the programm exits.
    
    		System.out.println("Start speaking. Press Ctrl-C to quit.\n");
    
    		result = recognizer.recognize();
    
    		if (result != null) {
    			String resultText = result.getBestFinalResultNoFiller();
    			System.out.println("You said:" + resultText + '\n');
    			if(resultText.equals("start game")){
    				speech = 1;	
    				
    			}
    			else if(resultText.equals("stick")){
    				speech = 2;
    			}
    			else if(resultText.equals("twist")){
    				speech = 3;
    			}else if(resultText.equals("player")){
    				speech = 4;
    			}else if(resultText.equals("dealer")){
    				speech = 5;
    			}
    		} else {
    			System.out.println("I can't hear what you said.\n");
    		}
    
    
    		return speech;
    	}
    
    
    
    }
    (I am experimenting with threading which is why the run() method is unused. Ignore that)

    int speech is being returned to my main class where the appropriate action is performed. Here is what is happening.

    If I speak at a normal volume into the mic, it recognises what has been said and prints the word in the console (as it should). It doesn't however update int speech and return the value. If I speak the word at a loud volume, it will again identify the word, print it in the console, update int speech and return the value.

    So if I speak at a normal volume, it recognises the command but doesn't execute it, if I speak loudly, it does perform the command!!

    Its frustrating because the program is being unreliable when it clearly does identify what I am saying.

    Any ideas? Many Thanks

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default Re: Sphinx 4 Voice Recognition acting WEIRD!

    What do you mean by " it recognises the command"? What values does the program show that makes you say that?
    How is that related to setting the value of the variable: speech?

    Can you post the printout from the program and add some comments describing what the program does?

    Why do you have the '\n' at the end of the println statement? Change it to "<\n" to delimit the String that is being printed.
    Last edited by Norm; 04-14-2012 at 02:28 AM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    treeface99 is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Default Re: Sphinx 4 Voice Recognition acting WEIRD!

    hi, Thanks for your responce.

    The function is listening out for 5 pieces of speech: start game, stick, twist, player and dealer. When it successfully identifies one of these words, it will assign the spoken word(s) to a string called 'resultText' and print the resultText in the console - System.out.println("You said:" + resultText + '\n');

    The if statements that follow literally just assign an value to an integer called speech. e.g if the string resultText == "start game", speech will = 1. When speech is returned back to the main, program knows to start the game because a 1 has been returned.

    Here is an example of what is happening:

    if I say the word "stick" into the microphone at a normal volume, the program will recognise the word (because it prints it in the console) but int speech is not being returned correctly for some reason.

    If i say the word "stick" at a high volume - again the function will recognise it (because it prints it in the console) and speech will be assigned the value 2 and returned to the main where the stick() class will executed.

    int speech is only being updated when the word is shouted. When it is spoke at a normal volume, the function is recognising correctly (because it is printed correctly in the console) but int speech is not being returned properly.


    I hope that is a little clearer,

    Many Thanks

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default Re: Sphinx 4 Voice Recognition acting WEIRD!

    it is printed correctly in the console) but int speech is not being returned properly.
    It's your code that sets the value of the speech variable. What is the value of the String that determines what the variable speech will be set to? Did you change what was being printed out by the program as I suggested? What does the program print out?
    Copy and paste here the contents of the console showing what is printed for the different tests. Add comments to it showing the different tests you did.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 02-14-2012, 10:27 PM
  2. Windows Voice Recognition
    By D-Technodude in forum New To Java
    Replies: 3
    Last Post: 03-10-2011, 09:26 AM
  3. Replies: 6
    Last Post: 01-14-2011, 04:08 PM
  4. Voice recognition with TalkingJava SDK
    By elektronische in forum Advanced Java
    Replies: 4
    Last Post: 01-14-2011, 02:56 PM
  5. recognition of spoken numbers; voice dialing
    By johnyjj2 in forum New To Java
    Replies: 1
    Last Post: 08-26-2009, 01:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •