|
Hello fellow Unity users Me and my brother is in the process of making a game, that will contain a LOT of recorded dialogue. So we want to be able to lip sync, without having to do every single line by hand. We don't care if it's top of the line lip syncing, it just has to move the characters mouth when it's talking, and stop when finished. Think like the old playstation era, where there were no lip, only mouth movement. Are there any addon for this, maybe in the asset store, or where can I at least find it? Or are there an easy way to to it ourselves? And do mind that we have limited money, so we possibly won't have hundreds of dollars to spare. Are there at least a way where a character can open his mouth more/less depending on the volume of the sounds coming out? I could imagine this is a kinda easy script to make?
(comments are locked)
|
|
This script uses audio.GetSpectrumData to analyze the audio data and to calculate the instantaneous volume of a given range of frequencies. In order to use GetSpectrumData, we must supply a power-of-two sized float array as the first argument, which the function fills with the spectrum of the sound currently playing. Each element in this array contains the instantaneous volume (0..1) of its corresponding frequency, calculated as N * 24000Hz / arraySize where N is the element index. I've made a few more tests, and got better results filtering the output of BandVol. I also inverted the movement - the mouth moved down instead of up, like a human chin. The code below include a Moving Average filter and the modified Update. If you want to test it, just delete the old Update and paste this code at the script's end.
Jul 05 '11 at 04:29 AM
aldonaletto
Sweet! Nice work @aldonaletto!
Jul 05 '11 at 04:32 AM
Chris D
After some tests in another case, I concluded that Unity samples sounds at 48000Hz, not 44100Hz as assumed previously in this answer. The only thing altered in the script is the initialization value of fMax: it changed to 24000 (was 22050 ). I fixed the answer text too - the frequency associated to element[N] is calculated by N*24000/arraySize (instead of N*22050/arraySize).
Aug 21 '11 at 12:39 PM
aldonaletto
Hi Aldonaletto, I'm trying to figure out this script, even just to get a cube moving up or down. The function BandVol has "for (var i=n1; i]]] " at the end, which appears to be an error. Was there something else that worked?
Jul 19 '12 at 11:45 PM
wakeupscreaming
Is there a reason you divide by 24000 (fMax) when calculating the indices in the array in BandVol(), and not 48000? Is it 24000 pr channel?
Dec 11 '12 at 12:56 PM
havardh
(comments are locked)
|
|
Here's what I've found:
If you don't particularly care about the accuracy of the animations, just rig your characters' mouths and play an animation any time they're supposed to speak. Alternatively, bones are just transforms so you should be able to reference them like any other transform. @ChrisD, the last suggestion will not work: audio.volume is the volume you set, not the clip instantaneous volume. The instantaneous volume could be get from audio.GetSpectrumData - IF we knew how to use it, of course, what isn't true because the docs are too vague about this function...
Jul 04 '11 at 06:32 PM
aldonaletto
Ah, good call, thanks Al. I did find this forum thread mentioning GetOutputData, though. Maybe it'd be worth fiddling (blindly experimenting) with that?
Jul 04 '11 at 08:14 PM
Chris D
Good suggestion. I'll try their script. With a little (or a lot of) luck maybe I put something to work.
Jul 04 '11 at 08:36 PM
aldonaletto
If you get anything to work, please share! Even though my brother and I know some programming, we're still kind of new to the whole unity scene.
Jul 04 '11 at 08:40 PM
Tails1942
@ChrisD, thanks for the hints. I read the forum and also found an interesting tutorial at http://unity3dtutorial.com/unity-3d-tutorials/audio-based-procedural-levelgeneration-manipulation-in-unity-3/ which showed how to use GetSpectrumData. I've posted an answer which can do reasonably the mouth control based on the audio played.
Jul 05 '11 at 03:49 AM
aldonaletto
(comments are locked)
|
|
if I were doing lipsyncs, I would probably rig up some standard phoneme mouth shapes/blends (M-E-O-W), and write some sort of custom blending system that would interpret a magpie (or similar) script and blend to the appropriate mouth shape. magpie, and other software like it, will take recorded dialogue and attempt to generate a 'timing script' based on phonemes it detects. My experience with it usually needed very little cleanup work- after that you have a pretty usable 'script' from which you can get all the timing info about your dialogue. From there you could easily write something that parsed the lipsync timing, and if a particular phoneme is detected, just blend to that shape. This is all just theory- I haven't implemented it before, but if I were that's probably how I would do it if accuracy were any concern.
(comments are locked)
|
|
Great stuff aldonaletto, I was looking for exactly this! However the BandVol function doesn't seem to respond to audio played with the PlayOneShot, only clips directly assigned to the audio component. Any idea how to get around that? In the spirit of sharing, I managed to get ok looking results by using the value returned by your script and hooking them up to an additive animation. I basically made a mouth animation which starts closed, opens with an O-like shape, then goes on to a wider shout style pose. This animation is enabled from the start with a maximum weight and zero playback speed. Since it's additive it won't affect any objects at frame 0. I then used your BandVol function to control the normalized time of the additive animation. Since the additive animation has nonlinear movement and some variation in it, it gave a more organic result than if I were to rotate the jaw or maybe fade a pose in and out by controlling its weight. I also used a cutoff value making the character close his mouth at low values. Encouraging a more "talky" motion as opposed to a half-open vibrating pose that can happen at lower volumes. And finally a Lerp so I could tweak how smooth the mouth movements should be. In the end it worked well for my cartoony flappy-mouth character. The extra variables used: The setup of the additive animation from Start() and the function running the mouthpose void LipSynch() { mouthTargetPose = BandVol(frqLow,frqHigh)* volume; You can get better results if you tweak the volume and voiceVolumeCutoff to match each voiceclip. Good job! Matching animations to the sound spectrum is the best way to achieve more realistic results. Congratulations! If possible, post a movie in youtube and place a link here to show the results. var sounds: AudioClip[]; // set the array size and clips at the Inspector ... // when you want to play the sound n: audio.clip = sounds[n]; audio.Play(); ... This works fine, even if you change the clip before the previous one has finished: the old clip just stops and the new one starts playing. Since isPlaying works as well, you can use it to know when the clip has ended.
Aug 02 '11 at 09:15 PM
aldonaletto
Hi guys, I've manage to use this kind of solution to have lip sync in my Unity game. But I got a little problem. Sometimes, when my character is shouting for instance, the animation keeps on playing, and the mouth goes crazy! Check the image. My guess is that somehow the delta frame keeps on being added? I tried to truncate it, to disable the anim when the mouthCurrentPose reaches 1.. but without success. Any ideas? thanks!! alt text
Jan 03 '12 at 03:18 PM
khamael
Dear God! The guy in the picture looks like a The Ring victim! I'm a complete stupid on animations, but would try to clamp the value assigned to normalizedTime to 0..1:
Jan 03 '12 at 03:37 PM
aldonaletto
Yeah.. I thought of clamping, but it doesn't work. my code is like this
function LipSync()
{
mouthTargetPose = MovingAverage(BandVol(frqLow,frqHigh) * volume);
// Tweak the voiceVolumeCutoff to get a good result, I used 0.1f myself
if(mouthTargetPose < voiceVolumeCutoff)
mouthTargetPose = 0.0f;
//mouthCurrentPose = Mathf.Lerp(0,mouthTargetPose,Time.deltaTime*mouthBlendSpeed);
mouthCurrentPose = Mathf.Clamp (mouthTargetPose, 0, 1);
sphere.transform.position.z = mouthCurrentPose;
mouth.normalizedTime = mouthCurrentPose;
}
The sphere is just to see it bouncing around, for 'debug', and mouth is the animationclip animation["anim_talk"]. It has like 15 frames, from mouth closed, mouth open, and mouth closed again. My guess is that when the sound is too loud, it passes and stays in the clamped valued, and somehow the delta keeps on being added?.. weird no, although useful for other torture anims ;)
Jan 03 '12 at 03:48 PM
khamael
Hi there, another addition to my problem. I thought that another way to do some facial animation would be to apply some transforms in the bones, simple stuff like move the jaw or something. So I did a little script where I open or close the jaw (just by changing the transform.position.y of it, on keypress) it works fine. BTW, I store the y position of the jaw in the Update, and add the delta in LateUpdate - not sure if it's the proper way to do it, but it seems to work. Now the problem is when I have another animation running. When I trigger an animation that moves the head, if I then trigger move jaw script, say with jaw.position.y = oldy - 0.001, the jaw keeps on moving down till the end of the animation clip. What's happening here? Probably it's the same cause as with the additive animation! Any ideas????
Jan 05 '12 at 02:26 PM
khamael
(comments are locked)
|
|
Hi, never tried with a mic.. did you check if you get something in data, from the audio.GetOutputData(data, 0) ?
(comments are locked)
|
1 2 next page »

That sounds awesome!