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

[button link="http://media.nozzi.name/sourcecode/TalkingMouthDemo.zip" style="green" size="large"]Download Source[/button]

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2011 Joshua NozziJoshua Nozzi is a Cocoa developer for hire.Suffusion theme by Sayontan Sinha