def handleInput(): global moving while True: picoh.say("Hello picoh here, what shall I look up on wolfram alpha?") text = input("Question:\n") picoh.say(text) picoh.setBaseColour(10, 5, 0) # Stop the random movement. moving = False # Look forward and up. picoh.move(picoh.HEADTURN, 5) picoh.move(picoh.EYETILT, 7) picoh.move(picoh.HEADNOD, 9) # get a random phrase from set 2 in the speech database. picoh.say(picoh.getPhrase(set=2)) # Try the call to a webservice to get a response from WolframAlpha. try: # Start random movement again moving = True res = wolfclient.query(text) ans = next(res.results).text # replace response text | with . ans = ans.replace("|", ".") picoh.say(ans) # set base to green. picoh.setBaseColour(0, 10, 0) # If no answer can be found then say answer not available and set base to red. except: print('Answer not available') picoh.say("Answer not available") picoh.setBaseColour(10, 0, 0) picoh.move(picoh.HEADTURN, 5)
def message_listener(client): global RECEIVED_MESSAGES pythoncom.CoInitialize() #fix to Picoh speech issue while True: message = client.receive_message() RECEIVED_MESSAGES += 1 print("Message received") # print( " Data: «{}»".format(message.data) ) # print( " Properties: {}".format(message.custom_properties)) # print( " Total calls received: {}".format(RECEIVED_MESSAGES)) print(message.data.decode('utf-8')) picoh.say(message.data.decode('utf-8')) picoh.setEyeShape("Heart") picoh.move(picoh.HEADTURN, randint(3, 7)) picoh.move(picoh.HEADNOD, randint(4, 7)) picoh.baseColour(random() * 10, random() * 10, random() * 10) picoh.wait(1) picoh.setEyeShape("Eyeball")
def handleInputWiki(): global moving while True: picoh.say( "Hello picoh here, what would you like the wiki definition for?") # Put up a text box and wait for user to type the word they want to define. text = input("Define:\n") # Say the word they have typed. picoh.say(text) picoh.setBaseColour(10, 5, 0) # Stop the random movement moving = False # Look forward and up. picoh.move(picoh.HEADTURN, 5) picoh.move(picoh.EYETILT, 7) picoh.move(picoh.HEADNOD, 9) # get a random phrase from set 2 in the speech database. picoh.say(picoh.getPhrase(set=2)) # Try the call to a webservice to get a response from Wikipedia. # Request the first sentence of the definition. try: # Start random movement again moving = True res = wikipedia.summary(text, sentences=1) picoh.say(res) picoh.setBaseColour(0, 10, 0) except: # If no answer can be found then say answer not available and set base to red. print('Answer not available') picoh.say("Answer not available") picoh.setBaseColour(10, 0, 0) picoh.move(picoh.HEADTURN, 5)
# Install pico2wave using sudo apt-get install libttspico-utils # Ensure you are running the latest version of the library by running sudo pip3 install picoh --upgrade from picoh import picoh picoh.reset() picoh.setSynthesizer("pico2wave") picoh.say("now I can speak using pico2wave text to speech as well") picoh.wait(1) picoh.close()
def cKey(event): picoh.say("Hello humans",untilDone = False) picoh.setBaseColour(3,10,3)
def bKey(event): picoh.playSound('spring',untilDone = True) picoh.say("What is going on ?",untilDone = False) picoh.setBaseColour(10,3,3)
def aKey(event): picoh.say("Hello I am Picoh",untilDone = False) picoh.setBaseColour(3,3,10)
from picoh import picoh import random picoh.reset() picoh.wait(0.2) picoh.say("Commencing hardware tests") picoh.say("Base to red") picoh.setBaseColour(10, 0, 0) picoh.say("Base to green") picoh.setBaseColour(0, 10, 0) picoh.say("Base to blue") picoh.setBaseColour(0, 0, 10) picoh.say("Matrix off") picoh.move(picoh.LIDBLINK, 0) picoh.setEyeShape("Full") picoh.say("Matrix on") picoh.move(picoh.LIDBLINK, 10) picoh.say("Eyes to angry") picoh.setEyeShape("Angry") picoh.say("Reset Eyes") picoh.setEyeShape("Eyeball")
# now that eyes are open start blinking on a different thread blinking = True t = threading.Thread(target=blinkLids, args=()) t.start() # turn the head to each side then back to centre sleep(0.5) picoh.move(picoh.HEADTURN, 10) sleep(0.5) picoh.move(picoh.HEADTURN, 0) sleep(0.5) picoh.move(picoh.HEADTURN, 5) # set hdmiAudio to True here if you are using hdmiAudio and speech is missing at beginning of each phrase picoh.say(say, untilDone=False, lipSync=True, hdmiAudio=False) # swivel eyes side to side 5 times for i in range(0, 5): picoh.move(picoh.EYETURN, 10, 10) sleep(0.1) picoh.move(picoh.EYETURN, 0, 10) sleep(0.1) # eye swivel back to centre picoh.move(picoh.EYETURN, 5, 10) # go to sleep position and turn eyes off sleep(3) blinking = False # wait a second for the thread to stop
# +croak or +whisper # -a for amplitude (0 to 200) # -s for speed 80 to 500 # -p for pitech 0 to 99 # ESPEAK-NG # supports some of the ESPEAK but some is missing # import the picoh module from picoh import picoh # Reset picoh picoh.reset() # Default synthesizer SAPI. Default Voice as set in Control Panel picoh.say("I. I just took a ride") # Quieter picoh.setVoice("-a82") picoh.say("In a silver machine.") # Faster picoh.setVoice("-r4") picoh.say("And I'm still feeling mean.") # Slower picoh.setVoice("-r-4") picoh.say("Do you wanna ride? See yourself going by.") # American picoh.setVoice("-vzira") picoh.say("The other side of the sky.") # Default voice picoh.setVoice("") picoh.say("I got a silver machine.")
#start up sequence resets to mid position, sets the eyes to blue then goes to sleep picoh.reset() picoh.baseColour(0, 0, 10) sleep(1.0) picoh.baseColour(0, 0, 0) # Start a thread for the blinking. blinking = True t = threading.Thread(target=blinkLids, args=()) t.start() sleep(2.0) picoh.say( "The picoh pi library now supports e speak meaning i can speak different languages and in different voices" ) picoh.move(picoh.HEADTURN, 4) picoh.wait(0.2) picoh.move(picoh.HEADTURN, 6) picoh.wait(0.2) # Set the voice to English female medium speed. picoh.setVoice("-ven+f2 -s150") picoh.baseColour(3, 10, 2) picoh.say("you can even change voice mid program") # Set the voice to French female.
from picoh import picoh import random # Run 'say -v?' in Terminal to list options for voices. speechSpeed is 90 +. picoh.reset() picoh.say("Hi it is great to be here, i am finally running on a mac, wow") picoh.wait(2) picoh.setVoice("Karen") picoh.setSpeechSpeed(150) picoh.move(picoh.HEADTURN, random.randint(3, 6)) picoh.say("hello i am Karen") picoh.setVoice("Alex") picoh.setSpeechSpeed(90) picoh.move(picoh.HEADTURN, random.randint(2, 6)) picoh.say("hello i am Alex slow") picoh.setVoice("Oliver") picoh.move(picoh.HEADTURN, random.randint(1, 6))
picoh.wait(1) picoh.setEyeShape("Eyeball") # initialize the client and wait to receive cloud-to-device message def iothub_client_sample_run(): try: client = iothub_client_init() message_listener_thread = threading.Thread(target=message_listener, args=(client, )) message_listener_thread.daemon = True message_listener_thread.start() while True: time.sleep(1000) except KeyboardInterrupt: print("IoTHubDeviceClient sample stopped") # main function if __name__ == '__main__': print("Starting the IoT Hub Python sample...") print("IoTHubDeviceClient waiting for commands, press Ctrl-C to exit") print("Reseting the PICOH") picoh.reset() picoh.say("The Picoh is alive") picoh.setEyeBrightness(5) iothub_client_sample_run()
''' The picoh.move() function needs at least 2 arguments: movement name and desired position. picoh.HEADTURN picoh.HEADNOD picoh.EYETURN picoh.EYETILT picoh.BOTTOMLIP picoh.LIDBLINK position can be any number 0-10. ''' # Move the HEADTURN motor to 2. picoh.move(picoh.HEADTURN, 2) picoh.say("head turn to 2") # Move the HEADTURN motor to 5. picoh.move(picoh.HEADTURN, 5) picoh.say("head turn to 5") # Move the HEADNOD motor to 9. picoh.move(picoh.HEADNOD, 9) picoh.say("head nod to 9") # Move the HEADNOD motor to 5. picoh.move(picoh.HEADNOD, 5) picoh.say("head nod to 5") ''' The picoh.move() function can also take an optional third arguement 'spd' to change the speed of the movement. If unspecified speed defaults to 5. '''
picoh.wait(1) picoh.setEyeShape(defaultEyeshape) # Set the moving and blinking global variables to True. moving = True blinking = True # Create a thread for blinking. t1 = threading.Thread(target=blinkLids, args=()) # Create a thread to make eyes look around randomly. t2 = threading.Thread(target=randomLook, args=()) # Create a thread for random head nod positions. t3 = threading.Thread(target=randomNod, args=()) # Create a thread for random head turn positions. t4 = threading.Thread(target=randomTurn, args=()) # Create a thread for random base colour. t5 = threading.Thread(target=baseCol, args=()) # Start the threads. t1.start() t2.start() t3.start() t4.start() t5.start() picoh.say("Hello my name is Picoh")
from picoh import picoh # Reset picoh's motors and wait a second for them to move to rest positions. picoh.reset() picoh.wait(1) # Set Picoh's eye shape. picoh.setEyeShape("Eyeball") # Say a phrase. picoh.say("Hello my name is Picoh. Good to meet you") # Move the HEADTURN and EYETURN to position 3. picoh.move(picoh.HEADTURN, 3) picoh.move(picoh.EYETURN, 3) picoh.wait(1) # Move the HEADTURN and EYETURN to position 7. picoh.move(picoh.HEADTURN, 7) picoh.move(picoh.EYETURN, 7) # Set the base to red:3/10 green: 4/10 and blue 2/10. picoh.setBaseColour(3, 4, 2) picoh.wait(1) # Change the base to orange picoh.setBaseColour(10, 3, 0) # Set the eyeshape to SunGlasses picoh.setEyeShape("SunGlasses")
from picoh import picoh # A list of voices can be found here: https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support#text-to-speech # You can register a free Azure account here: https://azure.microsoft.com/en-gb/free/ # Set up the Azure text to speech synth with your subscription key. picoh.setSynthesizer('Azure', ID="################################") # This will be spoken in the default Azure voice. picoh.say("Woo now my voice comes from Azure") # Change voice to MiaNeural picoh.setVoice("MiaNeural") picoh.say("My name is Mia") # Change voice to HeatherRus and region to Canada. picoh.setVoice("HeatherRUS", "en-CA") picoh.say("And I am Heather")