Example


Here is an example of how to use CeedVocal SDK step by step.

1. Loading the acoustic model
Loading the acoustic model for the appropriate language is needed before any speech recognition can happen. Add both .enchmm and .fastied files to the resources of you app and create the recognizer with this call:
    speechRecognizer = [[CVSpeechRecognizer alloc] initWithLanguage:CV_LANGUAGE_ENGLISH acousticModel:[[NSBundle mainBundle] pathForResource:@"ceedmodel-en" ofType:@"enchmm"]];

2. Setting the recognizer delegate
To be notified when speech is recognized, you should add a delegate to the recognizer. This is done this way (assuming self is the delegate):
    speechRecognizer.delegate = self;
Your delegate object must implement the appropriate delegate method:

- (void)speechRecognizerDidRecognizeSpeech:(CVSpeechRecognizer*)recognizer
{
    [result release];
    result = [NSMutableString new];

    int i=0;
    for(id res in [recognizer recognizedPhrases])
    {
    NSLog(@"%@ (score=%f)", res, [recognizer scoreForRecognizedPhrase:res]);

    [(NSMutableString*)result appendString:[NSString stringWithFormat:@"%d. %@ (score=%f)\n", ++i, res, [recognizer scoreForRecognizedPhrase:res]]];
    }

    // Call to UI on main thread only !!!
    [self performSelectorOnMainThread:@selector(updateResult:) withObject:nil waitUntilDone:YES];

    // If you need to stop the recognizer, do it on main thread
    //[self performSelectorOnMainThread:@selector(stopRecognition:) withObject:nil waitUntilDone:YES];
}

This method will be invoked from the recognizer thread. Therefore, you should not make any direct UI call from there, but instead do it through a main thread invocation. The same hold true if you want to stop the recognizer (only from the main thread).

3. Adding some words to be recognized
Adding the words to be recognized is next done. Do not forget to call prepareRecognizer after that.
    [speechRecognizer addPhrase:@"flower"]; [speechRecognizer addPhrase:@"sun"]; [speechRecognizer addPhrase:@"mountain"]; [speechRecognizer addPhrase:@"river"]; [speechRecognizer addPhrase:@"sky"]; [speechRecognizer addPhrase:@"clouds"]; [speechRecognizer prepareRecognizer];

4. Starting speech recognition
Starting the recognizer is done that way:
    [speechRecognizer startRecognition];
Stopping it that way:
    [speechRecognizer stopRecognition];