In this example, when calling rockOn(), the servos move to the stated positions and then, inmoov says "Rock on".
How do I have inmoov say "rock on" while the servos are moving to position? IS there a way to execute Parallel?
 
def rockOn():       
       leftThumb.moveTo(180)
       leftIndex.moveTo(0)
       leftMiddle.moveTo(180)
       leftRing.moveTo(180)
       leftPinky.moveTo(0)
       talk ("rock on")

GroG

8 years 10 months ago

Hello tdp378 and Welcome,

talk("rock on") must be part of your script - and within this method which is not shown, I'm guessing their is something like..

what you could possibly do is :

def rockOn():       
       mouth.speak("rock on");
       sleep(0.5) # a delay 'might' be necessary depending on the latency of the audio playing a cached file
       leftThumb.moveTo(180)
       leftIndex.moveTo(0)
       leftMiddle.moveTo(180)
       leftRing.moveTo(180)
       leftPinky.moveTo(0)
 

The thing I am trying to figure out is having the voice speak while movements are taking place. Currently, it says rock on before the servo moves. I want it to say rock on during the servo moves. If that makes sense. It executes in steps I guess.

Step 1. Say rock on
Step 2. Move servos

I am trying to get it to combine step 1 and 2 to execute simultaneously. This is not a good example because the speaking text is very short. What if I wanted inmoov to speak a paragraph. Basically I would not be able to have him move while he is talking correct?

Incorrect , 

my sample should be valid.

MyRobotLab - is massively multi-threaded.

It's just usually people want to block the execution thread until speaking is done.

InMoov primarily uses speakBlocking("some text - like Let's Rock") - this stops execution until the speech is finished.

But the Speech synthesis  regular 'speak' command will not block - meaning you can do anything else you want with that same thread - like move servos, motors etc .. 'simultaneously'

I see the error of my ways! Thank you!

The mouth control service does not seem to work recently that's why I just put the talk method in my script. Now I see that that method has to complete before the movement is made. Is there any reason why the mouth control service would be erring out?

I started the keyboard service and assigned keys to a couple of methods. The methods work and the speeh says the words but the mouth does not move

below is my entire script

from time import sleep
import threading
from org.myrobotlab.service import Arduino
from org.myrobotlab.service import Runtime
from org.myrobotlab.service import Servo
leftPort = "COM15"
 
# create the services
 
keyboard = Runtime.start("keyboard", "Keyboard")
keyboard.addKeyListener(python)
 
i01 = Runtime.createAndStart("i01", "InMoov")
i01.startMouthControl(leftPort)
i01.startMouth()
 
 
#####
#webgui = Runtime.start("webgui","WebGui")
 
# set voice
#voices = acapelaSpeech.getVoices()
#for voice in voices:
 #   acapelaSpeech.setVoice("Will")
 
 
sleep(1) # give it a second for the serial device to get ready
 
# tweaking default settings of Neck
i01.startHead(leftPort)
 
i01.head.neck.setMinMax(0,180)
i01.head.neck.map(0,180,15,155)
i01.head.neck.setRest(100)
i01.head.rothead.setMinMax(0,180)
i01.head.rothead.map(0,180,30,150)
i01.head.rothead.setRest(86)
# tweaking default settings Mouth
i01.head.jaw.setMinMax(0,180)
i01.head.jaw.map(0,180,20,70)
i01.head.jaw.setRest(20)
i01.head.jaw.setSpeed(1)
 
# tweaking default settings of left hand
i01.startLeftHand(leftPort)
 
i01.leftHand.thumb.setMinMax(0,180)
i01.leftHand.index.setMinMax(0,180)
i01.leftHand.majeure.setMinMax(0,180)
i01.leftHand.ringFinger.setMinMax(0,180)
i01.leftHand.pinky.setMinMax(0,180)
i01.leftHand.thumb.map(0,180,5,140)
i01.leftHand.index.map(0,180,5,140)
i01.leftHand.majeure.map(0,180,5,176)
i01.leftHand.ringFinger.map(0,180,5,175)
i01.leftHand.pinky.map(0,180,5,112)
 
 
 
#####################################################
i01.startEar()
ear = i01.ear
 
ear.addCommand("open hand","python","openLeftHand")
 
ear.startListening()
ear.addListener("recognized", "python", "heard")
def heard(phrase):
      #talk ("you said " + phrase)
      print "heard ", phrase
 
 
#Keyboard Commands
def onKey(key):
    if(key == 'O'): # Open Hand
        openLeftHand()
        i01.mouth.speak ("hand open")
    elif(key == 'C'): # close hand
      closeLeftHand()
      i01.mouth.speak ("hand closed")
    
# Reusable Movements
def openLeftHand():
       i01.moveHand("left",0,0,0,0,0,50)
 
def closeLeftHand():
       i01.moveHand("left",180,180,180,180,180,50)
       
 
 

Ok, I think i have the communication problem fixed. I send another no worky However, the jaw still will not move while speaking. Everything else appears to be working properly. The hand moves correctly and the voice speaks the correct phrase. I can move all sliders and the servos respond in tune. 

I am at a loss. Am I missing something in my code for the mouth control service? If I put the below method in my script and invoke talk("yada yada yada")  the mouth moves correctly but not with the mouthControl service.

def talk (sent): 
  speech.speak(sent)
  ison = False
  a = sent.split()
  for word in a:
    if word[len(word)-2:] == "es" : # removing es at the end of the word
      testword = word[:-2] +'xx' # adding x's to help keep the timing
    elif word[len(word)-1:] == "e" : # removing the silant e at the end of the word
      testword = word[:-1] +'x'
    else:
      testword = word
        
    for x in range(0, len(testword)):
    
      if testword[x] in ('a', 'e', 'i', 'o', 'u', 'y' ) and ison == False :
        #arduino.digitalWrite(13, Arduino.HIGH)
        mouth.moveTo(80) # move the servo to the open spot
        ison = True
        sleep(0.15)
        mouth.moveTo(15) # close the servo 
      elif testword[x] in ('.') :
        #arduino.digitalWrite(13, Arduino.LOW)
        
        ison = False
        sleep(.95)
      else: #sleep(0.5)  sleep half a second
        #arduino.digitalWrite(13, Arduino.LOW)
        
        ison = False
        sleep(0.06) # sleep half a second
  
    #arduino.digitalWrite(13, Arduino.LOW)
    
    sleep(0.08)
# end of talk function