Fri, Nov 22, 2:04 PM CST

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Lipsync script: 1st approximation


ockham ( ) posted Sat, 24 March 2001 at 5:57 PM · edited Fri, 22 November 2024 at 1:35 PM

Here's a primitive version, which actually works pretty well "from a distance". Read the comments in the PY file to see the assumptions and requirements. Essentially, you import your sound file, lay out the length of animation frames to be >= the sound file length, and then run the PY script to move the lips. Any other movements, whether manual or scripted, can be added on after that. # ---------------------------------------# # ---------------------------------------# # Lipsync (1st try) --3/24/01 ---- by ockham # [ occam24@gateway.net ]-# #----------------------------------------# # This is an inflexible 1st approximation of a # lipsyncing script. # It assumes you've set things up in a certain # way: # 1. The sound must be already imported # into the PZ3. # 2. The animation should be set up for 10 FPS, # with a length in # seconds at least as long as the sound file. # 3. The figure speaking is "Figure 1", and has # the usual head parameters. # 4. Sound must be mono, 16-bit, 11025 # samples/sec. # 5. Sound amplitude is not # automatically normalized; # if the movements are too large, # use a WAV editor # to cut the overall amplitude of your sound. # ------------------------------------# import sys import wave import poser import Numeric import fft # -----------------------------------------# scene = poser.Scene() figure = scene.Figure("Figure 1") # Find the sound. try: Filename = scene.Sound() except: print("No sound file present") # Open the sound file fp = wave.open(Filename, 'r') # Figure how much of the wave file # goes with one frame of # the animation. PPS = fp.getframerate() TotalSamps = fp.getnframes() FPS = scene.FramesPerSecond() PPF = PPS / FPS #This gives us the 'jumps' in sound file for each animation frame # ---------------------------------# # -- Main loop -------------------# # ---------------------------------# for i in range(scene.NumFrames()): # Set file position corresponding # to this animation frame try: fp.setpos(i * PPF) except: x=1 try: buf = fp.readframes(1024) except: print("readframes fails") SoundLen = len(buf) if SoundLen < 1024: exit else: #convert buf to array of float floatbuf = Numeric.array(buf,"Float") #do fft on buf fft.real_fft(floatbuf,1024) #floatbuf.astype('d') # Now use that number to set the Open Lips. scene.SetFrame(i) joint = figure.Actor("Head") # The only part we need, so set it once. # Using 1024 for size of FFT, we end up # with 512 spectral lines. # The sample rate is 11025, so Nyquist # is about 5.5KHz. # Very loosely, then, each line is 10 Hz. # Glottal should # be centered around 150 Hz, or the 15th # line, and should # control the Open Lips parameter. alterParm = joint.Parameter("OpenLips") val = abs(floatbuf[15]) * 0.03 alterParm.SetValue(val) # Try emphasizing the /o/-shape for F1 # around 600 Hz. alterParm = joint.Parameter("Mouth O") val = abs(floatbuf[50]) * 0.005 alterParm.SetValue(val) # Try emphasizing the /i/-shape for # F2 around 2KHz; alterParm = joint.Parameter("Smile") val = abs(floatbuf[200]) * 0.004 alterParm.SetValue(val) alterParm = joint.Parameter("Frown") val = abs(floatbuf[180]) * 0.006 alterParm.SetValue(val) # -------------------------------------------# fp.close() # Done with sound file # --------------------------------------#

My python page
My ShareCG freebies


ockham ( ) posted Sat, 24 March 2001 at 6:02 PM

Oops, the bloody indentations didn't come through properly. I'll have to leave that to the reader.... If you email me, I can send you the script ZIPped up so that its form will be preserved. occam24@gateway.net

My python page
My ShareCG freebies


bushi ( ) posted Sat, 24 March 2001 at 8:25 PM

Yes, it's very annoying isn't it. We're going to have to figure out a way around this problem. Maybe substitute '~'s for the indenting spaces and have a generally available script to convert the '~'s back to spaces? Good work on the script. If you like I can host a ZIPped version of the script so you won't have to deal with the e-mail.


ockham ( ) posted Sun, 25 March 2001 at 1:15 AM

Thanks for the offer of hosting; no emails yet, so I'll wait and see. I don't want to put it into a form that looks permanent until I smooth out more of the wrinkles. The basic algorithm is good, but it needs to adjust to various circumstances on its own. .....ockham

My python page
My ShareCG freebies


bushi ( ) posted Sun, 25 March 2001 at 1:22 AM

That's fine. The offer's open-ended. I would like to see the script as you have it now though. The e-mail address is bushi@spiritone.com. Thanks!


jcarp ( ) posted Mon, 26 March 2001 at 12:08 PM

Anthony Appleyard had the answer to indents in another thread. Use the pre pre HTML tags around your code in the post. (You'll have to imagine the angle brackets in that last sentence because the post will eat anything in angle brackets even wrapped in pre pre. I don't know what's up with that, but I quess it means you'll have to avoid angle bracket pairs in your code. Still it's an improvement.) For instance (quoting but formatting from above using tags),

    if SoundLen < 1024:
       exit
    else:
                #convert buf to array of float
       floatbuf = Numeric.array(buf,"Float")

QED. Cheers for Anthony!


jcarp ( ) posted Mon, 26 March 2001 at 12:21 PM

As for posting long scripts, there seems to be some limit to posts (don't know what it is exactly). The preview anyway comes back with a server error message. Probably an anti-rant or anti-ramble feature. :-)


duanemoody ( ) posted Tue, 03 April 2001 at 12:14 PM

If you want to enclose an HTML tag for display only, show angle brackets in HTML-friendly forums like these, just type in (for example)

 to get


jcarp ( ) posted Tue, 03 April 2001 at 1:19 PM

Got it (at last). You're saying use the 'less-than' (<)and 'greater-than'(>) HTML characters to stand in for angle brackets. Sorry to be dense. Thanx. Also, finally realized that

 won't use tabs.  I've been pasting in from an editor that expands tabs to spaces.


jcarp ( ) posted Tue, 03 April 2001 at 1:33 PM

Ah, I see. The preview doesn't exactly work, does it? That's discouraging. Anyway, I guess it's clear enough that 'less-than' is the & l t ;, etc. And it's the PRE (imagine the damn brackets) that doesn't use tabs for spacing. Mildly interested in what this shows up as ...


Mason ( ) posted Wed, 04 April 2001 at 3:53 PM

I'll talk with the forum gys and see if we can get this forum changed to have 1. Longer message limits 2. No auto formatting of text so we can pass around scripts.


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.