TalkingMouthDemo

TalkingMouthDemo is a brief demonstration in Objective-C / Cocoa of the basic NSSpeechSynthesizer/Delegate support to sync the spoken phonemes with images of individual mouth shapes to produce an animated mouth.

Details

I posted an explanation of this code and the methodology behind it in the post titled “Talking Face Speech Synthesizer Demo“.

Usage

Only relevant parts are highlighted here. The full code (including the

-imageForPhoneme:

method as well as the example phoneme images) are available in the project.

- (IBAction)speak:(id)sender
{
     // Start speaking
     [synthesizer startSpeakingString:[textField stringValue]];
}

- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender
 willSpeakPhoneme:(short)phonemeOpcode
{
     // Set the right image for the incoming phoneme opcode
     if (phonemeOpcode && [[self phonemes] count])
          [imageView setImage:[self imageForPhoneme:phonemeOpcode]];
}

- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender
 didFinishSpeaking:(BOOL)success
{
     // Finished speaking, so silence is golden
     [imageView setImage:[[self phonemes] objectAtIndex:0]];
}

- (NSImage *)imageForPhoneme:(short)phonemeOpcode
{
     return [[self phonemes] objectAtIndex:phonemeOpcode];
}

License

This source code and the phoneme images are free to use in any private, public, or commercial software products with no restrictions.

Source & Demo

Joshua Nozzi is a Cocoa Developer for Hire
  1. No comments yet.

  1. No trackbacks yet.