FluentNao and Events


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 = ""
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'

	if value == 'stand'

	if value == '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