Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    51
    Rep Power
    0

    Unhappy Speech Recognition

    I have a code with me for Speech Recognition
    Java Code:
    package javaapplication20;
    
    /**
     *
     * @author Priyanka
     */
    import javax.speech.Central;
    import javax.speech.recognition.*;
    import javax.speech.EngineCentral;
    import java.io.FileReader;
    import java.util.Locale;
    
    public class Main extends ResultAdapter {
          static Recognizer recognizer;
    
          public void resultAccepted(ResultEvent resultEvent) {
                Result result = (Result)(resultEvent.getSource());
                ResultToken resultToken[] = result.getBestTokens();
    
                for (int nIndex = 0; nIndex < resultToken.length; nIndex++){
                      System.out.print(resultToken[nIndex].getSpokenText() + " ");
                }
                try {
    
                      // Deallocate the recognizer
                      recognizer.forceFinalize(true);
                      recognizer.deallocate();
                }catch (Exception exception) {
                      exception.printStackTrace();
                }
                System.exit(0);
          }
    
          public static void main(String args[]) {
                try {
                          //   Line 41: Central.registerEngineCentral("com.cloudgarden.speech.CGEngineCentral");
                      RecognizerModeDesc desc =new RecognizerModeDesc(Locale.US,Boolean.TRUE);
                      // Create a recognizer that supports US English.
                      recognizer = Central.createRecognizer(desc);
    
                      // Start up the recognizer
                      recognizer.allocate();
    
                      // Load the grammar from a file, and enable it
                     FileReader fileReader =
                         new FileReader("C:\\Users\\Priyanka\\Desktop\\my_grammar.grammar");
                      RuleGrammar grammar = recognizer.loadJSGF(fileReader);
                      grammar.setEnabled(true);
    
                      // Add the listener to get results
                      recognizer.addResultListener(new Main());
    
                      // Commit the grammar
                      recognizer.commitChanges();
                      recognizer.waitEngineState(Recognizer.LISTENING);
    
                      // Request focus and start listening
                      recognizer.requestFocus();
                      recognizer.resume();
    
                      recognizer.waitEngineState(Recognizer.FOCUS_ON);
    
                      recognizer.forceFinalize(true);
                      recognizer.waitEngineState(Recognizer.DEALLOCATED);
    
    
                } catch (Exception e) {
                      e.printStackTrace();
                      System.exit(0);
                }
          }
    }


    But for this code i am getting an exception of javax.speech.EngineException: javax.speech.Central: no class found for com.cloudgarden.speech.CGEngineCentral
    at javax.speech.Central.registerEngineCentral(Central .java:706)
    at javaapplication20.Main.main(Main.java:41)

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Do you have the cloudgarden jar file?
    Is it on your classpath?

  3. #3
    Join Date
    Mar 2009
    Posts
    51
    Rep Power
    0

    Unhappy

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package javaapplication20;
    
    /**
     *
     * @author Priyanka
     */
    import javax.speech.Central;
    import javax.speech.recognition.*;
    
    import java.io.FileReader;
    import java.util.Locale;
    
    public class Main extends ResultAdapter {
          static Recognizer recognizer;
    
          public void resultAccepted(ResultEvent resultEvent) {
                Result result = (Result)(resultEvent.getSource());
                ResultToken resultToken[] = result.getBestTokens();
    
                for (int nIndex = 0; nIndex < resultToken.length; nIndex++){
                      System.out.print(resultToken[nIndex].getSpokenText() + " ");
                }
                try {
    
                      // Deallocate the recognizer
                      recognizer.forceFinalize(true);
                      recognizer.deallocate();
                }catch (Exception exception) {
                      exception.printStackTrace();
                }
                System.exit(0);
          }
    
          public static void main(String args[]) {
                try {
                     // Central.registerEngineCentral("com.cloudgarden.speech.CGEngineCentral");
                      RecognizerModeDesc desc =
                           new RecognizerModeDesc(Locale.US,Boolean.TRUE);
                      // Create a recognizer that supports US English.
                      recognizer = Central.createRecognizer(desc);
    
                      // Start up the recognizer
                      recognizer.allocate();
    
                      // Load the grammar from a file, and enable it
                     FileReader fileReader =
                         new FileReader("C:\\Users\\Priyanka\\Desktop\\my_grammar.grammar.txt");
                      RuleGrammar grammar = recognizer.loadJSGF(fileReader);
                      grammar.setEnabled(true);
    
                      // Add the listener to get results
                      recognizer.addResultListener(new Main());
    
                      // Commit the grammar
                      recognizer.commitChanges();
                      recognizer.waitEngineState(Recognizer.LISTENING);
    
                      // Request focus and start listening
                      recognizer.requestFocus();
                      recognizer.resume();
    
                      recognizer.waitEngineState(Recognizer.FOCUS_ON);
    
                      recognizer.forceFinalize(true);
                      recognizer.waitEngineState(Recognizer.DEALLOCATED);
    
    
                } catch (Exception e) {
                      e.printStackTrace();
                      System.exit(0);
                }
          }
    }
    My GRammar File
    Java Code:
    #JSGF V1.0;
    
    grammar com.sarf.talkingjava.example;
    
    public <startExample> = (please | My name is sarf | 
    What is your Name | Open Firefox | Open notepad |Open grammar |
    Please to meet you ) *;
    public <endExample> = [thanks | thank you | thank you very much];
    I get the output as
    CloudGarden's JSAPI1.0 implementation
    Version 1.7.0
    Implementation contained in files cgjsapi.jar and cgjsapi170.dll
    >> Initializing Cloudgarden's JSAPI 1.0, version 1.7.0
    >> Free for personal use only.
    >> Any form of commercial, corporate or institutional use requires purchase of a
    license.
    >> Please visit Cloud Garden (Java Resources) for details.

    But even when i speak the words in the grammar no response is coming

Similar Threads

  1. Voice recognition with TalkingJava SDK
    By elektronische in forum Advanced Java
    Replies: 4
    Last Post: 01-14-2011, 03:56 PM
  2. Image recognition
    By mortarr in forum New To Java
    Replies: 1
    Last Post: 12-21-2010, 06:38 PM
  3. Optical Character recognition
    By silversurfer2in in forum New To Java
    Replies: 2
    Last Post: 12-16-2010, 05:53 AM
  4. Speech Recognition In Java
    By hackernewbie in forum Advanced Java
    Replies: 6
    Last Post: 01-19-2010, 12:06 AM
  5. API for Character Recognition
    By LankanSniper in forum Advanced Java
    Replies: 5
    Last Post: 03-25-2009, 12:39 PM

Posting Permissions

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