The Animated Face The face with the lip
Monday, December 3rd, 2007The Animated Face The face with the lip synchronization is implemented as a subclass of the Swing JPanel class. This class has the name Face and is created in the com.bdaum.dukeSpeaks package. The class implements the AnimationListener interface, which was created in the Animation Events section. This allows you to register the face as AnimationListener with an Animator instance. It will receive AnimationEvents from the Animator and can then react accordingly to these events. The Face.java class package com.bdaum.dukeSpeaks; import java.awt.*; import javax.swing.JPanel; import com.sun.speech.freetts.relp.AnimationEvent; import com.sun.speech.freetts.relp.AnimationListener; public class Face extends JPanel implements AnimationListener { // Relative mouth dimensions, derived from current phoneme float mouthWidth = 0.80f; float mouthHeight = 0.05f; // Relative eye pupil position, derived from current phoneme float eyePos = 0.16f; The processAnimationEvent() method receives animation events (AnimationEvent). From the transmitted phoneme it computes the size and shape of the mouth and the position of the eye pupils. The mouth is always drawn as an ellipsoid but with varying positions and diameters. After these values are computed, the repaint() method is called. This enforces the redrawing of the Face component. /** * @see com.sun.speech.freetts.relp.AnimationListener * #processAnimationEvent(AnimationEvent) */ public void processAnimationEvent(AnimationEvent e) { // Set current phoneme String phone = e.phone; if (phone.equals(”pau”)) { // In pauses pupils must look upwards eyePos = 0.15f; // In pauses mouth remains closed mouthWidth = 0.80f; mouthHeight = 0.05f; } else { // Otherwise pupils look downwards eyePos = 0.4f; // Analyze first character of phoneme char p1 = phone.charAt(0); switch (p1) { // Uh’s and Oh’s case ‘o’ : 85 Project One: Duke Speaks
Are you a Mac user in a search of Mac web hosting provider? We are. once upon a time, we were just like you, trying to find somebody who knows. Unfortunately, we had no luck, so we decided to help many others like you, and us. our team developed Mac friendly web hosting plans, feature packed, constantly monitored, and more than affordable. With us, you are home. Sign up.