Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)
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
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.
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
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!
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.
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