I remember something a while back about syncing characters with audio... this is along that vein (although not audio based) and thought you might find it useful. I made a basic phoneme function that will have the character's mouth graphic mime out the letters of the sentence. The basic logic is that it takes your string, converts it into an array, then cycles through the array telling the mouth movie clip to stop on whatever letter is assigned to it.
I only used the basic 9 phoneme's, but the code is simple enough that it should be pretty easy to manipulate and/or add more complexity to if needed. Enjoy!
Click to Play
(Javascript Required)
speakTest.swf [ 122.02 KiB | Viewed 2910 times ]
edit - Tried to attach the source file, but for some reason the forums are telling me .fla is a non-allowed extension?
Here is the basic code:
(1) on the main timeline, this makes the array when you click the button:
Spoiler (click to show/hide):
- Code: Select All Code
var strArray:Array = new Array();
var talkSpeed:Number = 75;
mcText.text = "";
mcSpeed.text = talkSpeed;
mcOutput.text = "";
mcClicker.onRelease = function(){
var arrayPos:Number = 0;
var strPos:Number = 0;
var strLen:Number = _root.mcText.text.length;
var strConv:String = "";
var strVal:String = "";
for(i=0;i<=strLen;i++){
if(textInput.charAt(i) <> " "){
strConv = _root.mcText.text.charAt(i);
strArray[arrayPos] = strConv.toUpperCase();
arrayPos += 1;
}
}
strArray[arrayPos] = ">";
talkSpeed = mcSpeed.text;
mcMouth.gotoAndStop("speak");
}
(2) this is on the main frame of the mouth movie clip, telling it what to pull when it hits which letters:
Spoiler (click to show/hide):
- Code: Select All Code
var intervalId:Number;
var count:Number = 0;
var maxCount:Number = (_root.strArray.length - 1);
var duration:Number = _root.talkSpeed;
function executeCallback(param:String) {
getMouth(param);
if(param <> ">"){
_root.mcOutput.text = _root.mcOutput.text + param;
}
clearInterval(intervalId);
if(count < maxCount) {
count++;
intervalId = setInterval(this, "executeCallback", duration, _root.strArray[count]);
}
}
function getMouth(phenom):Void{
if(phenom=="A"){
mcMouth.gotoAndStop("A");
}else if(phenom=="E"){
mcMouth.gotoAndStop("E");
}else if(phenom=="I"){
mcMouth.gotoAndStop("I");
}else if(phenom=="O"){
mcMouth.gotoAndStop("O");
}else if(phenom=="U" or phenom=="W"){
mcMouth.gotoAndStop("W");
}else if(phenom=="F" or phenom=="V"){
mcMouth.gotoAndStop("F");
}else if(phenom=="M" or phenom=="N" or phenom=="B"){
mcMouth.gotoAndStop("M");
}else if(phenom=="L"){
mcMouth.gotoAndStop("L");
}else if(phenom=="S" or phenom=="D" or phenom=="G" or phenom=="R" or phenom=="T" or phenom=="C" or phenom=="K"){
mcMouth.gotoAndStop("S");
}else if(phenom==" "){
mcMouth.gotoAndStop("close");
}else if(phenom==">"){
_root.mcMouth.gotoAndStop("silent");
}
}
if(intervalId != null) {
clearInterval(intervalId);
}
if(count==maxCount){
_root.mcMouth.gotoAndStop("silent");
}
intervalId = setInterval(this, "executeCallback", duration, _root.strArray[count]);
stop();