Page 1 of 1

Speaking logic (this is for you KaTsu)

PostPosted: Mon Oct 22, 2012 2:39 am
by GoRepeat
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 2914 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();

Re: Speaking logic (this is for you KaTsu)

PostPosted: Mon Oct 22, 2012 2:56 am
by BlueLight
I say you cheated! I had for the string
"Fuck fuck fuck fuck

1 1 1 1"

and the lips repeated the same 4 actions. It should be doing the repeat 8 times or something. And it's the same set of actions.

Re: Speaking logic (this is for you KaTsu)

PostPosted: Mon Oct 22, 2012 3:46 am
by GoRepeat
I am confused, if you wrote "fuck" 4 times, it would mouth out "fuck" four times? Numbers don't really do anything as I didn't add code for them. I suppose I could set to recognize 1-9 easily enough, but we would need to start getting pretty complex for anything higher as there is no logical correlation between the numeric symbol and the pronunciation.

It isn't cheating, just a little on the dumb side since it was a concept design

Re: Speaking logic (this is for you KaTsu)

PostPosted: Mon Oct 22, 2012 4:00 am
by BlueLight
oh well... um... never mind....
I will try this later with and see if i can prove it doesn't work with real words.

stupid computer not being able to read epic number characters!

Re: Speaking logic (this is for you KaTsu)

PostPosted: Mon Oct 22, 2012 4:24 am
by BlueLight
Dammit! it works... Buy your amzing talking lips for only 50 easy payments of 999,999,999,999.99 and 9 over 10

Re: Speaking logic (this is for you KaTsu)

PostPosted: Mon Oct 22, 2012 11:48 am
by GoRepeat
lol if it makes you feel any better, I didnt add logic for it to tell the difference between a hard and soft "C" or like the difference between "T" and "TH" (although this could be added easily enough). I also realize I forgot to reset the text output so it looks weird after a few rounds!

I think 125 speed looks the "best" although its really funny if you set it to like 500 "Can you see the words coming out of my mouth?"

Re: Speaking logic (this is for you KaTsu)

PostPosted: Mon Oct 22, 2012 1:17 pm
by KaTsuO_O
Ah, thank you, this is certainly something useful. I was going to just make a really simple open and close animation because that's prett charming, but this is probably going to look better. Transitions between the mouths and emotions is something I'll have to add but that won't be too much of a problem.