FluentNao and Events

2014-05-17

I had a great time at the Bay Area Nao Dev's meetup and thought it might be fun to write up a post showing how to handle events like voice recognition with FluentNao. This post assumes you have setup fluent-nao first.

Create a Script

Since you already have FluentNao code on your machine, copy/rename the bootstrap.py file to create a very simple script

cp bootstrap.py my-script.py

Fluent Nao

Clear everything out of that file except the following code.


import math
import naoutil.naoenv as naoenv
import naoutil.memory as memory
import fluentnao.nao as nao
from datetime import datetime
from naoutil import broker

# naoutil broker & env
naoIp = "192.168.2.12"
broker.Broker('bootstrapBroker', naoIp=naoIp, naoPort=9559)
env = naoenv.make_environment(None) #using broker don't need ->, ipaddr="nao.local", port=9559)

# FluentNao
nao = nao.Nao(env, None)

Voice Recognition code

Add the following code to your script, which will…


# set VR Vocabulary
vocab = ['sit', 'stand', 'hands open']
nao.env.speechRecognition.setVocabulary(vocab, True)

# define VR callback
def speech_callback(dataName, value, message):
	print value

	if value == 'sit'
		nao.sit()

	if value == 'stand'
		nao.stand()

	if value == 'hands open'
		nao.hands.open()


# subscribe to VR
memory.subscribeToEvent('WordRecognized', speech_callback)

Run Your Script

Run your script and tell nao to "sit"

python my-script.py
back