-
-
Save junjihashimoto/fff75f2053a4e7805581 to your computer and use it in GitHub Desktop.
| http://doc.aldebaran.com/2-1/dev/cpp/examples/core/helloworld/example.html#cpp-examples-helloworld |
try
{
/** Create a proxy to TTS./
ALTextToSpeechProxy tts(getParentBroker());
/* Call the say method. /
tts.say(phraseToSay);
/* Note: on the desktop you won't hear anything, but you should see
* some logs on the naoqi you are connected to.
*/
}
catch(const AL::ALError&) // no object name given to avoid warning
{
qiLogError("module.example") << "Could not get proxy to ALTextToSpeech" << std::endl;
}
class MyClass(GeneratedClass):
def init(self):
GeneratedClass.init(self, False)
try:
self.asr = ALProxy("ALSpeechRecognition")
except Exception as e:
self.asr = None
self.logger.error(e)
self.memory = ALProxy("ALMemory")
def onLoad(self):
from threading import Lock
self.bIsRunning = False
self.mutex = Lock()
self.hasPushed = False
self.hasSubscribed = False
self.BIND_PYTHON(self.getName(), "onWordRecognized")
def onUnload(self):
from threading import Lock
self.mutex.acquire()
try:
if (self.bIsRunning):
if (self.hasSubscribed):
self.memory.unsubscribeToEvent("WordRecognized", self.getName())
if (self.hasPushed and self.asr):
self.asr.popContexts()
except RuntimeError, e:
self.mutex.release()
raise e
self.bIsRunning = False;
self.mutex.release()
def onInput_onStart(self):
from threading import Lock
self.mutex.acquire()
if(self.bIsRunning):
self.mutex.release()
return
self.bIsRunning = True
try:
if self.asr:
self.asr.setVisualExpression(self.getParameter("Visual expression"))
self.asr.pushContexts()
self.hasPushed = True
if self.asr:
self.asr.setVocabulary( self.getParameter("Word list").split(';'), self.getParameter("Enable word spotting") )
self.memory.subscribeToEvent("WordRecognized", self.getName(), "onWordRecognized")
self.hasSubscribed = True
except RuntimeError, e:
self.mutex.release()
self.onUnload()
raise e
self.mutex.release()
def onInput_onStop(self):
if( self.bIsRunning ):
self.onUnload()
self.onStopped()
def onWordRecognized(self, key, value, message):
if(len(value) > 1 and value[1] >= self.getParameter("Confidence threshold (%)")/100.):
self.wordRecognized(value[0]) #~ activate output of the box
else:
self.onNothing()
class MyClass(GeneratedClass):
def onLoad(self):
self.frameManager = None
try:
self.frameManager = ALProxy("ALFrameManager")
except Exception as e:
self.logger.error(e)
def onUnload(self):
pass
def _getTabletService(self):
tabletService = None
try:
tabletService = self.session().service("ALTabletService")
except Exception as e:
self.logger.error(e)
return tabletService
def _getAppName(self):
import os
if self.frameManager:
behaviorPath = os.path.normpath(self.frameManager.getBehaviorPath(self.behaviorId))
appsFolderFragment = os.path.join("PackageManager", "apps")
if not (appsFolderFragment in behaviorPath):
self.logger.error("appsFolderFragment is not in behaviorPath")
fragment = behaviorPath.split(appsFolderFragment, 1)[1]
return fragment.lstrip("\\/")
else:
self.logger.warning("No ALFrameManager")
def _getAbsoluteUrl(self, partial_url):
import os
subPath = os.path.join(self._getAppName(), os.path.normpath(partial_url).lstrip("\\/"))
# We create TabletService here in order to avoid
# problems with connections and disconnections of the tablet during the life of the application
return "http://%s/apps/%s" %(self._getTabletService().robotIp(), subPath.replace(os.path.sep, "/"))
def onInput_onStart(self):
# We create TabletService here in order to avoid
# problems with connections and disconnections of the tablet during the life of the application
tabletService = self._getTabletService()
if tabletService:
try:
url = self.getParameter("ImageUrl")
if url == '':
self.logger.error("URL of the image is empty")
if not url.startswith('http'):
url = self._getAbsoluteUrl(url)
tabletService.showImage(url)
except Exception as err:
self.logger.error("Error during ShowImage : %s " % err)
self.onStopped()
else:
self.logger.warning("No ALTabletService, can't display the image.")
self.onStopped()
def onInput_onHideImage(self):
# We create TabletService here in order to avoid
# problems with connections and disconnections of the tablet during the life of the application
tabletService = self._getTabletService()
if tabletService:
try:
tabletService.hideImage()
except Exception as err:
self.logger.error("Error during HideImage : %s " % err)
self.onStopped()
else:
self.logger.warning("No ALTabletService, can't hide the image.")
self.onStopped()
def onInput_onPreLoadImage(self):
# We create TabletService here in order to avoid
# problems with connections and disconnections of the tablet during the life of the application
tabletService = self._getTabletService()
if tabletService:
try:
partialUrl = self.getParameter("ImageUrl")
fullUrl = self._getAbsoluteUrl(partialUrl)
tabletService.preLoadImage(fullUrl)
except Exception as err:
self.logger.warning("Error during preLoadImage : %s " % err)
self.onStopped()
else:
self.logger.warning("No ALTabletService, can't preload the image.")
self.onStopped()
def onInput_onStop(self):
self.onUnload()
self.onStopped()
import time
class MyClass(GeneratedClass):
def init(self):
GeneratedClass.init(self, False)
self.resolutionMap = {
'160 x 120': 0,
'320 x 240': 1,
'640 x 480': 2,
'1280 x 960': 3
}
self.cameraMap = {
'Top': 0,
'Bottom': 1
}
self.recordFolder = "/home/nao/recordings/cameras/"
def onLoad(self):
self.bIsRunning = False
try:
self.photoCapture = ALProxy( "ALPhotoCapture" )
except Exception as e:
self.photoCapture = None
self.logger.error(e)
def onUnload(self):
pass
def onInput_onStart(self):
if( self.bIsRunning ):
return
self.bIsRunning = True
resolution = self.resolutionMap[self.getParameter("Resolution")]
cameraID = self.cameraMap[self.getParameter("Camera")]
fileName = self.getParameter("File Name")
if self.photoCapture:
self.photoCapture.setResolution(resolution)
self.photoCapture.setCameraID(cameraID)
self.photoCapture.setPictureFormat("jpg")
self.photoCapture.takePicture( self.recordFolder, fileName )
self.bIsRunning = False
self.onStopped()
http://doc.aldebaran.com/2-1/dev/naoqi/index.html#naoqi-local-remote-modules