def exportToKML( self, strFilename = None ): if( strFilename == None ): strFilename = pathtools.getVolatilePath() + 'pos.kml'; strOut = """<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Folder>"""; for k, v in self.aListPos.iteritems(): pos = v[0]; rLon = pos[0]; rLat = pos[1]; rAlt = 0; if( len( pos ) > 2 ): rAlt = pos[2]; strDesc = ""; if( len( v ) > 1 ): strDesc = "<description>%s</description>" % v[1]; strOut += """ <Placemark> <name>%s</name> %s <Point> <coordinates>%f,%f,%f</coordinates> </Point> </Placemark>""" % ( k, strDesc, rLon, rLat, rAlt ); strOut += "\n </Folder>\n</kml>"; file = open( strFilename, "wt" ); file.write( strOut ); file.close(); print( "INF: exportToKML: exported to '%s': %d position(s)" % (strFilename, len( self.aListPos ) ) );
def sayAndCache_internal( strTextToSay, bJustPrepare, bStoreToNonVolatilePath, bDirectPlay, nUseLang, bWaitEnd, bCalledFromSayAndCacheFromLight, strUseVoice ): "generate a text in a file, then read it, next time it will be directly played from that file" "bJustPrepare: render the text to a file, but don't play it now" "bStoreToNonVolatilePath: copy the generated file to a non volatile path (/usr/generatedvoices)" "nUseLang: if different of -1: speak with a specific languages (useful, when text are already generated: doesn't need to swap languages for nothing!" "strUseVoice: if different of None or default: use specific voice" "return the length of the text in seconds, or None if impossible" print( "sayAndCache_internal( '%s', bJustPrepare: %s, bStoreToNonVolatilePath: %s, bDirectPlay: %s, nUseLang: %d, bWaitEnd: %s, bCalledFromSayAndCacheFromLight: %s, strUseVoice: '%s' )" % ( strTextToSay, str( bJustPrepare ), str( bStoreToNonVolatilePath ), str( bDirectPlay ), nUseLang, str( bWaitEnd ), str( bCalledFromSayAndCacheFromLight ), str( strUseVoice ) ) ); if( not config.bPrecomputeText ): print( "sayAndCache: disabled by configuration: bPrecomputeText is false" ); if( bJustPrepare ): return None; # do nothing tts = naoqitools.myGetProxy( "ALTextToSpeech" ); tts.say( strTextToSay ); return None; print( "sayAndCache: FORCING DIRECT_PLAY CAR SINON C'EST BUGGE DANS LA VERSION COURANTE!"); bDirectPlay = True; if( strUseVoice == "default" ): strUseVoice = None; if( config.bRemoveDirectPlay ): print( "WRN: DISABLING DIRECT_PLAY SETTINGS for testing/temporary purpose" ); bDirectPlay = False; strTextToSay = assumeTextHasDefaultSettings( strTextToSay, nUseLang ); szFilename = sayAndCache_getFilename( strTextToSay, nUseLang, strUseVoice ); szPathVolatile = pathtools.getVolatilePath() + "generatedvoices" + pathtools.getDirectorySeparator(); try: os.mkdir( szPathVolatile ); except BaseException, err: pass
def sayAndCacheAndLight( strTextToSay, bJustPrepare = False, bStoreToNonVolatilePath = False, nEyesColor = 0, nUseLang = -1 ): "say a cached text with light animation" "nEyesColor: 0: white, 1: blue, 2: green; 3: red" "nUseLang: if different of -1: speak with a specific languages (useful, when text are already generated: doesn't need to swap languages for nothing!" "return the length of the text in seconds, or None if impossible" print( "sayAndCacheAndLight( '%s', bJustPrepare: %s, bStoreToNonVolatilePath: %s, nEyesColor: %s, nUseLang: %s )" % ( strTextToSay, str( bJustPrepare ), str( bStoreToNonVolatilePath ), str( nEyesColor ), str( nUseLang ) ) ); if( not config.bPrecomputeText ): print( "sayAndCacheAndLight: disabled by configuration: bPrecomputeText is false" ); if( bJustPrepare ): return None; # do nothing tts = naoqitools.myGetProxy( "ALTextToSpeech" ); tts.say( strTextToSay ); return None; rLength = sayAndCache( strTextToSay, bJustPrepare = True, bStoreToNonVolatilePath = bStoreToNonVolatilePath, nUseLang = nUseLang, bCalledFromSayAndCacheFromLight = True ); # we store it to disk, only if we must do it # this two lines are done too in sayAndCache... strTextToSay = assumeTextHasDefaultSettings( strTextToSay, nUseLang ); szFilename = sayAndCache_getFilename( strTextToSay, nUseLang ); szPathVolatile = pathtools.getVolatilePath(); rSampleLenSec = 0.05; # szPathFilenamePeak = szPathVolatile + szFilename + ("_%5.3f.egy" % rSampleLenSec); szPathFilenamePeak = szFilename + ("_%5.3f.egy" % rSampleLenSec); szPathFilenamePeakCache = pathtools.getCachePath() + "generatedvoices" + pathtools.getDirectorySeparator() + szPathFilenamePeak; szPathFilenamePeak = szPathVolatile + szPathFilenamePeak; anLedsColorSequency = []; aBufFile = ""; bFileGenerated = False; if( not filetools.isFileExists( szPathFilenamePeak ) ): if( filetools.isFileExists( szPathFilenamePeakCache ) ): copyFile( szPathFilenamePeakCache, szPathFilenamePeak ); if( not filetools.isFileExists( szPathFilenamePeak ) ): # generate peak file timeBegin = time.time(); print( "sayAndCacheAndLight: generating peak light - begin\n" ); szPathFilename = szPathVolatile + szFilename + ".raw"; anLedsColorSequency = []; try: une = naoqitools.myGetProxy( 'UsageNoiseExtractor' ); anLedsColorSequency = une.analyseSpeakSound( szPathFilename, int( rSampleLenSec * 1000 ), False ); except BaseException, err: print( "ERR: sayAndCacheAndLight( '%s' ): err: %s" % ( strTextToSay, str( err ) ) ); print( "ERR: sayAndCacheAndLight => trying old cpp version" ); anLedsColorSequency = analyseSpeakSound( szPathFilename, rSampleLenSec * 1000 ); print( "sayAndCacheAndLight: analyseSpeakSound - end - time: %fs\n" % float( time.time() - timeBegin ) ); # print( "anLedsColorSequency: %d samples: %s\n" % ( len( anLedsColorSequency ), str( anLedsColorSequency ) ) ); print( "Writing file with %d peak samples (time: %d)\n" % ( len( anLedsColorSequency ), int( time.time() ) ) ); # struct.pack_into( "f"*len( anLedsColorSequency ), aBufFile, anLedsColorSequency[:] ); for peakValue in anLedsColorSequency: aBufFile += struct.pack( "f", peakValue ); try: file = open( szPathFilenamePeak, "wb" ); file.write( aBufFile ); except RuntimeError, err: print( "ERR: sayAndCacheAndLight( '%s' ): err: %s" % ( strTextToSay, str( err ) ) );
def sayMumbled( strText ): sayAndCache( strText, bJustPrepare = True ); strText = assumeTextHasDefaultSettings( strText ); szFilename = sayAndCache_getFilename( strText ); szPathFilename = pathtools.getVolatilePath() + "generatedvoices" + pathtools.getDirectorySeparator() + szFilename + ".raw"; szProcessed = szPathFilename + "_mumbled.raw"; if( not processSoundMumbled( szPathFilename, szProcessed ) ): return False; nFreq = 22050; system.mySystemCall( "aplay -c1 -r%d -fS16_LE -q %s" % ( nFreq, szProcessed ) ); return True;
def sayMumbled(strText): sayAndCache(strText, bJustPrepare=True) strText = assumeTextHasDefaultSettings(strText) szFilename = sayAndCache_getFilename(strText) szPathFilename = pathtools.getVolatilePath() + szFilename + ".raw" szProcessed = szPathFilename + "_mumbled.raw" if (not processSoundMumbled(szPathFilename, szProcessed)): return False nFreq = 22050 mySystemCall("aplay -c1 -r%d -fS16_LE -q %s" % (nFreq, szProcessed)) return True
def executeAndGrabOutput( strCommand, bLimitToFirstLine = False ): "execute a command in system shell and return grabbed output" "WARNING: it's a 'not efficient' function!" strTimeStamp = filetools.getFilenameFromTime(); strOutputFilename = pathtools.getVolatilePath() + "grab_output_" + strTimeStamp+ ".tmp"; # generate a different file each call for multithreading capabilities mySystemCall( strCommand + " > " + strOutputFilename ); if( bLimitToFirstLine ): strBufferRead = filetools.getFileFirstLine( strOutputFilename ); else: strBufferRead = filetools.getFileContents( strOutputFilename ); try: os.unlink( strOutputFilename ); except: pass debug.debug( "executeAndGrabOutput: '%s'" % strBufferRead ); return strBufferRead;
def sayAndCache_internal(strTextToSay, bJustPrepare, bStoreToNonVolatilePath, bDirectPlay, nUseLang, bWaitEnd, bCalledFromSayAndCacheFromLight, strUseVoice): "generate a text in a file, then read it, next time it will be directly played from that file" "bJustPrepare: render the text to a file, but don't play it now" "bStoreToNonVolatilePath: copy the generated file to a non volatile path (/usr/generatedvoices)" "nUseLang: if different of -1: speak with a specific languages (useful, when text are already generated: doesn't need to swap languages for nothing!" "strUseVoice: if different of None or default: use specific voice" "return the length of the text in seconds, or None if impossible" print( "sayAndCache_internal( '%s', bJustPrepare: %s, bStoreToNonVolatilePath: %s, bDirectPlay: %s, nUseLang: %d, bWaitEnd: %s, bCalledFromSayAndCacheFromLight: %s, strUseVoice: '%s' )" % (strTextToSay, str(bJustPrepare), str(bStoreToNonVolatilePath), str(bDirectPlay), nUseLang, str(bWaitEnd), str(bCalledFromSayAndCacheFromLight), str(strUseVoice))) if (not config.bPrecomputeText): print( "sayAndCache: disabled by configuration: bPrecomputeText is false") if (bJustPrepare): return None # do nothing tts = naoqitools.myGetProxy("ALTextToSpeech") tts.say(strTextToSay) return None print( "sayAndCache: FORCING DIRECT_PLAY CAR SINON C'EST BUGGE DANS LA VERSION COURANTE!" ) bDirectPlay = True if (strUseVoice == "default"): strUseVoice = None if (config.bRemoveDirectPlay): print( "WRN: DISABLING DIRECT_PLAY SETTINGS for testing/temporary purpose" ) bDirectPlay = False strTextToSay = assumeTextHasDefaultSettings(strTextToSay, nUseLang) szFilename = sayAndCache_getFilename(strTextToSay, nUseLang, strUseVoice) szPathVolatile = pathtools.getVolatilePath( ) + "generatedvoices" + pathtools.getDirectorySeparator() try: os.mkdir(szPathVolatile) except BaseException, err: pass
def sayAndCacheAndLight(strTextToSay, bJustPrepare=False, bStoreToNonVolatilePath=False, nEyesColor=0, nUseLang=-1): "say a cached text with light animation" "nEyesColor: 0: white, 1: blue, 2: green; 3: red" "nUseLang: if different of -1: speak with a specific languages (useful, when text are already generated: doesn't need to swap languages for nothing!" "return the length of the text in seconds, or None if impossible" print( "sayAndCacheAndLight( '%s', bJustPrepare: %s, bStoreToNonVolatilePath: %s, nEyesColor: %s, nUseLang: %s )" % (strTextToSay, str(bJustPrepare), str(bStoreToNonVolatilePath), str(nEyesColor), str(nUseLang))) if (not config.bPrecomputeText): print( "sayAndCacheAndLight: disabled by configuration: bPrecomputeText is false" ) if (bJustPrepare): return None # do nothing tts = naoqitools.myGetProxy("ALTextToSpeech") tts.say(strTextToSay) return None rLength = sayAndCache(strTextToSay, bJustPrepare=True, bStoreToNonVolatilePath=bStoreToNonVolatilePath, nUseLang=nUseLang, bCalledFromSayAndCacheFromLight=True) # we store it to disk, only if we must do it # this two lines are done too in sayAndCache... strTextToSay = assumeTextHasDefaultSettings(strTextToSay, nUseLang) szFilename = sayAndCache_getFilename(strTextToSay, nUseLang) szPathVolatile = pathtools.getVolatilePath() rSampleLenSec = 0.05 # szPathFilenamePeak = szPathVolatile + szFilename + ("_%5.3f.egy" % rSampleLenSec); szPathFilenamePeak = szFilename + ("_%5.3f.egy" % rSampleLenSec) szPathFilenamePeakCache = pathtools.getCachePath( ) + "generatedvoices" + pathtools.getDirectorySeparator( ) + szPathFilenamePeak szPathFilenamePeak = szPathVolatile + szPathFilenamePeak anLedsColorSequency = [] aBufFile = "" bFileGenerated = False if (not filetools.isFileExists(szPathFilenamePeak)): if (filetools.isFileExists(szPathFilenamePeakCache)): copyFile(szPathFilenamePeakCache, szPathFilenamePeak) if (not filetools.isFileExists(szPathFilenamePeak)): # generate peak file timeBegin = time.time() print("sayAndCacheAndLight: generating peak light - begin\n") szPathFilename = szPathVolatile + szFilename + ".raw" anLedsColorSequency = [] try: une = naoqitools.myGetProxy('UsageNoiseExtractor') anLedsColorSequency = une.analyseSpeakSound( szPathFilename, int(rSampleLenSec * 1000), False) except BaseException, err: print("ERR: sayAndCacheAndLight( '%s' ): err: %s" % (strTextToSay, str(err))) print("ERR: sayAndCacheAndLight => trying old cpp version") anLedsColorSequency = analyseSpeakSound(szPathFilename, rSampleLenSec * 1000) print("sayAndCacheAndLight: analyseSpeakSound - end - time: %fs\n" % float(time.time() - timeBegin)) # print( "anLedsColorSequency: %d samples: %s\n" % ( len( anLedsColorSequency ), str( anLedsColorSequency ) ) ); print("Writing file with %d peak samples (time: %d)\n" % (len(anLedsColorSequency), int(time.time()))) # struct.pack_into( "f"*len( anLedsColorSequency ), aBufFile, anLedsColorSequency[:] ); for peakValue in anLedsColorSequency: aBufFile += struct.pack("f", peakValue) try: file = open(szPathFilenamePeak, "wb") file.write(aBufFile) except RuntimeError, err: print("ERR: sayAndCacheAndLight( '%s' ): err: %s" % (strTextToSay, str(err)))
def sayAndCache(strTextToSay, bJustPrepare=False, bStoreToNonVolatilePath=False, bDirectPlay=False, nUseLang=-1, bWaitEnd=True, bCalledFromSayAndCacheFromLight=False): "generate a text in a file, then read it, next time it will be directly played from that file" "bJustPrepare: render the text to a file, but don't play it now" "bStoreToNonVolatilePath: copy the generated file to a non volatile path (/usr/generatedvoices)" "nUseLang: if different of -1: speak with a specific languages (useful, when text are already generated: doesn't need to swap languages for nothing!" "return the length of the text in seconds, or None if impossible" print( "sayAndCache( '%s', bJustPrepare: %s, bStoreToNonVolatilePath: %s, bDirectPlay: %s, nUseLang: %d, bWaitEnd: %s, bCalledFromSayAndCacheFromLight: %s )" % (strTextToSay, str(bJustPrepare), str(bStoreToNonVolatilePath), str(bDirectPlay), nUseLang, str(bWaitEnd), str(bCalledFromSayAndCacheFromLight))) if (not config.bPrecomputeText): print( "sayAndCache: disabled by configuration: bPrecomputeText is false") if (bJustPrepare): return None # do nothing tts = naoqitools.myGetProxy("ALTextToSpeech") tts.say(strTextToSay) return None print( "sayAndCache: FORCING DIRECT_PLAY CAR SINON C'EST BUGGE DANS LA VERSION COURANTE!" ) bDirectPlay = True if (config.bRemoveDirectPlay): print( "WRN: DISABLING DIRECT_PLAY SETTINGS for testing/temporary purpose" ) bDirectPlay = False strTextToSay = assumeTextHasDefaultSettings(strTextToSay, nUseLang) szFilename = sayAndCache_getFilename(strTextToSay, nUseLang) szPathVolatile = pathtools.getVolatilePath() # if( not szFilename.isalnum() ): # the underscore is not an alphanumeric, but is valid there # debug( "WRN: sayAndCache: some chars are not alphanumeric in filename '%s'" % szFilename ); szPathFilename = szPathVolatile + szFilename + ".raw" bGenerate = not filetools.isFileExists(szPathFilename) if (bGenerate): szAlternatePathFilename = pathtools.getCachePath( ) + "generatedvoices" + pathtools.getDirectorySeparator( ) + szFilename + ".raw" # look in a non volatile path if (filetools.isFileExists(szAlternatePathFilename)): debug("sayAndCache: get static precomputed text for '%s'" % (strTextToSay)) copyFile(szAlternatePathFilename, szPathFilename) bGenerate = not filetools.isFileExists(szPathFilename) #update this variable # if alternate # if bGenerate if (bGenerate): # generate it! debug("sayAndCache: generating '%s' to file '%s'" % (strTextToSay, szPathFilename)) sayAndCache_InformProcess() timeBegin = time.time() tts = naoqitools.myGetProxy("ALTextToSpeech") if (nUseLang != -1): # change the language to the wanted one setSpeakLanguage(nUseLang) if (len(strTextToSay) > 150 and (not bJustPrepare or bCalledFromSayAndCacheFromLight)): # if it's a long text, we had a blabla to tell the user we will wait (if it's a just prepare from inner, we don't use it) sayAndCache_InformPrepare() print("TTS TO FILE 1 - BEGIN") tts.sayToFile(strTextToSay, szPathFilename) print("TTS TO FILE 1 - END") sayAndCache_InformProcess_end() debug("sayAndCache: generating text to file - end (tts) - time: %fs" % (time.time() - timeBegin)) timeBegin = time.time() removeBlankFromFile(szPathFilename) debug( "sayAndCache: generating text to file - end (post-process1) - time: %fs" % (time.time() - timeBegin)) timeBegin = time.time() if (bStoreToNonVolatilePath): try: os.makedirs(pathtools.getCachePath() + "generatedvoices" + pathtools.getDirectorySeparator()) except: pass szAlternatePathFilename = pathtools.getCachePath( ) + "generatedvoices" + pathtools.getDirectorySeparator( ) + szFilename + ".raw" # a non volatile path copyFile(szPathFilename, szAlternatePathFilename) time.sleep(0.1) # pour laisser la synthese souffler un peu (dans les scripts je mettais 300ms) debug( "sayAndCache: generating text to file - end (post-process2) - time: %fs" % (time.time() - timeBegin)) statinfo = os.stat(szPathFilename) rLength = statinfo.st_size / float(22050 * 1 * 2) # sizefile => secondes if (not bJustPrepare): # debug( "speech::sayAndCache: launching sound now!" ); if (bWaitEnd): analyseSound_pause(True) if (bDirectPlay): nLang = nUseLang if (nLang == -1): nLang = getSpeakLanguage() nFreq = 22050 if (nLang == constants.LANG_CH or nLang == constants.LANG_KO): nFreq = 17000 # parce que c'est beau, (ca fait a peu pres du speed a 72%) # todo: ca désynchronise les yeux qui se lisent trop vite ! argh ! mySystemCall("aplay -c1 -r%d -fS16_LE -q %s" % (nFreq, szPathFilename), bWaitEnd=bWaitEnd) else: leds = naoqitools.myGetProxy("ALLeds", True) leds.post.fadeRGB("RightFootLeds", 0xFF0000, 0.7) # right in red (skip) audioProxy = naoqitools.myGetProxy("ALAudioPlayer", True) # read it in background and check if someone press the right feet a long times => skip text playing id = audioProxy.post.playFile(szPathFilename) if (not bWaitEnd): # attention: no unpause of analyse dans ce cas la! return rLength nbrFramesBumpersPushed = 0 nbrFramesBumpersPushedMinToSkip = 2 strTemplateKeyName = "Device/SubDeviceList/%sFoot/Bumper/%s/Sensor/Value" stm = naoqitools.myGetProxy("ALMemory") while (audioProxy.isRunning(id)): time.sleep(0.1) # time for user to release precedent push listRightFeetBumpers = stm.getListData([ strTemplateKeyName % ("R", "Left"), strTemplateKeyName % ("R", "Right") ]) if (listRightFeetBumpers[0] > 0.0 or listRightFeetBumpers[1] > 0.0): nbrFramesBumpersPushed += 1 if (nbrFramesBumpersPushed >= nbrFramesBumpersPushedMinToSkip): print( "sayAndCache: skipping current text reading because users press on right bumpers" ) audioProxy.stop(id) leds.post.fadeRGB("RightFootLeds", 0x000000, 0.2) # turn off it # while - end #if( bDirectPlay ) - end analyseSound_resume(True) # if( not bJustPrepare ) - end print("sayAndCache: End !!!") return rLength
def sayAndCache( strTextToSay, bJustPrepare = False, bStoreToNonVolatilePath = False, bDirectPlay = False, nUseLang = -1, bWaitEnd = True, bCalledFromSayAndCacheFromLight = False ): "generate a text in a file, then read it, next time it will be directly played from that file" "bJustPrepare: render the text to a file, but don't play it now" "bStoreToNonVolatilePath: copy the generated file to a non volatile path (/usr/generatedvoices)" "nUseLang: if different of -1: speak with a specific languages (useful, when text are already generated: doesn't need to swap languages for nothing!" "return the length of the text in seconds, or None if impossible" print( "sayAndCache( '%s', bJustPrepare: %s, bStoreToNonVolatilePath: %s, bDirectPlay: %s, nUseLang: %d, bWaitEnd: %s, bCalledFromSayAndCacheFromLight: %s )" % ( strTextToSay, str( bJustPrepare ), str( bStoreToNonVolatilePath ), str( bDirectPlay ), nUseLang, str( bWaitEnd ), str( bCalledFromSayAndCacheFromLight ) ) ); if( not config.bPrecomputeText ): print( "sayAndCache: disabled by configuration: bPrecomputeText is false" ); if( bJustPrepare ): return None; # do nothing tts = naoqitools.myGetProxy( "ALTextToSpeech" ); tts.say( strTextToSay ); return None; print( "sayAndCache: FORCING DIRECT_PLAY CAR SINON C'EST BUGGE DANS LA VERSION COURANTE!"); bDirectPlay = True; if( config.bRemoveDirectPlay ): print( "WRN: DISABLING DIRECT_PLAY SETTINGS for testing/temporary purpose" ); bDirectPlay = False; strTextToSay = assumeTextHasDefaultSettings( strTextToSay, nUseLang ); szFilename = sayAndCache_getFilename( strTextToSay, nUseLang ); szPathVolatile = pathtools.getVolatilePath(); # if( not szFilename.isalnum() ): # the underscore is not an alphanumeric, but is valid there # debug( "WRN: sayAndCache: some chars are not alphanumeric in filename '%s'" % szFilename ); szPathFilename = szPathVolatile + szFilename + ".raw"; bGenerate = not filetools.isFileExists( szPathFilename ); if( bGenerate ): szAlternatePathFilename = pathtools.getCachePath() + "generatedvoices" + pathtools.getDirectorySeparator() + szFilename + ".raw"; # look in a non volatile path if( filetools.isFileExists( szAlternatePathFilename ) ): debug( "sayAndCache: get static precomputed text for '%s'" % ( strTextToSay ) ); copyFile( szAlternatePathFilename, szPathFilename ); bGenerate = not filetools.isFileExists( szPathFilename ); #update this variable # if alternate # if bGenerate if( bGenerate ): # generate it! debug( "sayAndCache: generating '%s' to file '%s'" % ( strTextToSay, szPathFilename ) ); sayAndCache_InformProcess(); timeBegin = time.time(); tts = naoqitools.myGetProxy( "ALTextToSpeech" ); if( nUseLang != -1 ): # change the language to the wanted one setSpeakLanguage( nUseLang ); if( len( strTextToSay ) > 150 and ( not bJustPrepare or bCalledFromSayAndCacheFromLight ) ): # if it's a long text, we had a blabla to tell the user we will wait (if it's a just prepare from inner, we don't use it) sayAndCache_InformPrepare(); print( "TTS TO FILE 1 - BEGIN" ); tts.sayToFile( strTextToSay, szPathFilename ); print( "TTS TO FILE 1 - END" ); sayAndCache_InformProcess_end(); debug( "sayAndCache: generating text to file - end (tts) - time: %fs" % ( time.time() - timeBegin ) ); timeBegin = time.time(); removeBlankFromFile( szPathFilename ); debug( "sayAndCache: generating text to file - end (post-process1) - time: %fs" % ( time.time() - timeBegin ) ); timeBegin = time.time(); if( bStoreToNonVolatilePath ): try: os.makedirs( pathtools.getCachePath() + "generatedvoices" + pathtools.getDirectorySeparator()); except: pass szAlternatePathFilename = pathtools.getCachePath() + "generatedvoices" + pathtools.getDirectorySeparator() + szFilename + ".raw"; # a non volatile path copyFile( szPathFilename, szAlternatePathFilename ); time.sleep( 0.1 ); # pour laisser la synthese souffler un peu (dans les scripts je mettais 300ms) debug( "sayAndCache: generating text to file - end (post-process2) - time: %fs" % ( time.time() - timeBegin ) ); statinfo = os.stat( szPathFilename ); rLength = statinfo.st_size / float(22050*1*2); # sizefile => secondes if( not bJustPrepare ): # debug( "speech::sayAndCache: launching sound now!" ); if( bWaitEnd ): analyseSound_pause( True ); if( bDirectPlay ): nLang = nUseLang; if( nLang == -1 ): nLang = getSpeakLanguage(); nFreq = 22050; if( nLang == constants.LANG_CH or nLang == constants.LANG_KO ): nFreq = 17000; # parce que c'est beau, (ca fait a peu pres du speed a 72%) # todo: ca désynchronise les yeux qui se lisent trop vite ! argh ! mySystemCall( "aplay -c1 -r%d -fS16_LE -q %s" % ( nFreq, szPathFilename ), bWaitEnd = bWaitEnd ); else: leds = naoqitools.myGetProxy( "ALLeds", True ); leds.post.fadeRGB( "RightFootLeds", 0xFF0000, 0.7 ); # right in red (skip) audioProxy = naoqitools.myGetProxy( "ALAudioPlayer", True ); # read it in background and check if someone press the right feet a long times => skip text playing id = audioProxy.post.playFile(szPathFilename); if( not bWaitEnd ): # attention: no unpause of analyse dans ce cas la! return rLength; nbrFramesBumpersPushed = 0; nbrFramesBumpersPushedMinToSkip = 2; strTemplateKeyName = "Device/SubDeviceList/%sFoot/Bumper/%s/Sensor/Value"; stm = naoqitools.myGetProxy( "ALMemory" ); while( audioProxy.isRunning( id ) ): time.sleep( 0.1 ); # time for user to release precedent push listRightFeetBumpers = stm.getListData( [strTemplateKeyName % ( "R", "Left" ), strTemplateKeyName % ( "R", "Right" )] ); if( listRightFeetBumpers[0] > 0.0 or listRightFeetBumpers[1] > 0.0 ): nbrFramesBumpersPushed += 1; if( nbrFramesBumpersPushed >= nbrFramesBumpersPushedMinToSkip ): print( "sayAndCache: skipping current text reading because users press on right bumpers" ); audioProxy.stop( id ); leds.post.fadeRGB( "RightFootLeds", 0x000000, 0.2 ); # turn off it # while - end #if( bDirectPlay ) - end analyseSound_resume( True ); # if( not bJustPrepare ) - end print( "sayAndCache: End !!!"); return rLength;
bRet = usage.post.getWebFile( strHost, strFolder + strPageName, strSaveAs, rTimeOutForAnswerInSec ); return ""; strPageContents = usage.getWebPage( strHost, strFolder + strPageName, rTimeOutForAnswerInSec ); if( strPageContents != "error" or ( rTimeOutForAnswerInSec > 0. and rTimeOutForAnswerInSec < 10.0 ) ): # if we put a short timeout, that's possible to have an empty response! return strPageContents; # else, we will use the normal method else: print( "WRN: getHtmlPage: CPP method error: return empty, trying other method" ); except BaseException, err: print( "WRN: getHtmlPage: CPP method error: %s" % str( err ) ); pass # use oldies version print( "WRN: nettools.getHtmlPage: using old one using fork and shell!" ); # not very efficient: should store it in var/volatile (but less os independent) debug.debug( "getHtmlPage( %s, bWaitAnswer = %d, rTimeOutForAnswerInSec = %d )" % ( strHtmlAdress, bWaitAnswer, rTimeOutForAnswerInSec ) ); strRandomFilename = pathtools.getVolatilePath() + "getHtmlPage_%s.html" % filetools.getFilenameFromTime(); # sous windows wget peut geler, donc on va l'appeller avec un timeout (qui ne fonctionne pas, c'est drole...) # threadWGet = system.mySystemCall( "wget %s --output-document=%s --tries=16 --timeout=60 --cache=off -q" % ( strHtmlAdress, strRandomFilename ), False, True ); # commenter cette ligne pour avoir toujours le meme fichier # en fait plein d'options n'existe pas sur Nao, donc on ne laisse que celle ci: if( strSaveAs != None ): strRandomFilename = strSaveAs; threadWGet = system.mySystemCall( "wget \"%s\" --output-document=%s -q" % ( strHtmlAdress, strRandomFilename ), bWaitEnd = False, bStoppable = True ); # commenter cette ligne pour avoir toujours le meme fichier if( not bWaitAnswer ): debug.debug( "getHtmlPage( %s, %d ) - direct return" % ( strHtmlAdress, bWaitAnswer ) ); return ""; timeBegin = time.time(); timeElapsed = 0.0; time.sleep( 1.0 ); # time for the process to be created !