def playSound(strFilename, bWait=True, bDirectPlay=False, nSoundVolume=100): "Play a sound, return True if ok" "bDirectPlay: play it Now! (could fragilise system and video drivers" "nSoundVolume: if bDirectPlay is on, will play the sound with a specific volume (ndev)" print( "playSound( '%s', bWait = %s, bDirectPlay = %s, nSoundVolume = %d )" % (strFilename, str(bWait), str(bDirectPlay), nSoundVolume)) if (config.bRemoveDirectPlay): print( "WRN: DISABLING_DIRECTPLAY SETTINGS for testing/temporary purpose") bDirectPlay = False try: # If strFilename has an absolute path, go ahead with this path ! if strFilename.startswith(pathtools.getDirectorySeparator()): strSoundFile = strFilename else: strSoundFile = pathtools.getApplicationSharedPath( ) + "wav/0_work_free/" + strFilename if (not filetools.isFileExists(strSoundFile)): # then try another path strSoundFile = pathtools.getApplicationSharedPath( ) + "wav/1_validated/" + strFilename if (not filetools.isFileExists(strSoundFile)): # and another path strSoundFile = pathtools.getApplicationSharedPath( ) + "wav/0_work_copyright/" + strFilename if (not filetools.isFileExists(strSoundFile)): # and another path strSoundFile = pathtools.getApplicationSharedPath( ) + "wav/" + strFilename if (not filetools.isFileExists(strSoundFile)): # and another path strSoundFile = pathtools.getNaoqiPath( ) + "/share/naoqi/wav/" + strFilename if (not filetools.isFileExists(strSoundFile)): print("ERR: appu.playSound: can't find file '%s'" % strFilename) return False analyseSound_pause(bWait) if (bDirectPlay): system.mySystemCall("aplay -q " + strSoundFile, bWait) else: global_proxyAudioPlayer = naoqitools.myGetProxy("ALAudioPlayer") if (global_proxyAudioPlayer == None): print( "ERR: sound.playSound: can't find module 'ALAudioPlayer'") else: if (bWait): global_proxyAudioPlayer.playFile(strSoundFile) else: global_proxyAudioPlayer.post.playFile(strSoundFile) analyseSound_resume(bWait) except BaseException, err: debug.debug("playSound: ERR: " + str(err)) print("errr: " + str(err))
def setMasterMute( bMute ): "mute nao sound volume" if( bMute ): strVal = "off"; else: strVal = "on"; debug.debug( "setMasterMute: %s" % strVal ); system.mySystemCall( "amixer -q sset Master " + strVal );
def setMasterMute(bMute): "mute nao sound volume" if (bMute): strVal = "off" else: strVal = "on" debug.debug("setMasterMute: %s" % strVal) system.mySystemCall("amixer -q sset Master " + strVal)
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( ) + "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 playSound( strFilename, bWait = True, bDirectPlay = False, nSoundVolume = 100 ): "Play a sound, return True if ok" "bDirectPlay: play it Now! (could fragilise system and video drivers" "nSoundVolume: if bDirectPlay is on, will play the sound with a specific volume (ndev)" print( "playSound( '%s', bWait = %s, bDirectPlay = %s, nSoundVolume = %d )" % ( strFilename, str( bWait ), str( bDirectPlay ), nSoundVolume ) ); if( config.bRemoveDirectPlay ): print( "WRN: DISABLING_DIRECTPLAY SETTINGS for testing/temporary purpose" ); bDirectPlay = False; try: # If strFilename has an absolute path, go ahead with this path ! if strFilename.startswith( pathtools.getDirectorySeparator() ): strSoundFile = strFilename else: strSoundFile = pathtools.getApplicationSharedPath() + "wav/0_work_free/" + strFilename; if( not filetools.isFileExists( strSoundFile ) ): # then try another path strSoundFile = pathtools.getApplicationSharedPath() + "wav/1_validated/" + strFilename; if( not filetools.isFileExists( strSoundFile ) ): # and another path strSoundFile = pathtools.getApplicationSharedPath() + "wav/0_work_copyright/" + strFilename; if( not filetools.isFileExists( strSoundFile ) ): # and another path strSoundFile = pathtools.getApplicationSharedPath() + "wav/" + strFilename; if( not filetools.isFileExists( strSoundFile ) ): # and another path strSoundFile = pathtools.getNaoqiPath() + "/share/naoqi/wav/" + strFilename; if( not filetools.isFileExists( strSoundFile ) ): print( "ERR: appu.playSound: can't find file '%s'" % strFilename ); return False; analyseSound_pause( bWait ); if( bDirectPlay ): system.mySystemCall( "aplay -q " + strSoundFile, bWait ); else: global_proxyAudioPlayer = naoqitools.myGetProxy( "ALAudioPlayer" ); if( global_proxyAudioPlayer == None ): print( "ERR: sound.playSound: can't find module 'ALAudioPlayer'" ); else: if( bWait ): global_proxyAudioPlayer.playFile( strSoundFile ); else: global_proxyAudioPlayer.post.playFile( strSoundFile ); analyseSound_resume( bWait ); except BaseException, err: debug.debug( "playSound: ERR: " + str( err ) ); print( "errr: " + str( err ) );
def setMasterPanning(nPanning=0): "change the sound master panning: 0: center -100: left +100: right" "current bug: currently volume is louder when at border, than at center, sorry" try: debug.debug("setMasterPanning to %d" % nPanning) nVol = getCurrentMasterVolume() nCoefR = nVol + nVol * nPanning / 100 nCoefL = nVol - nVol * nPanning / 100 nCoefR = nCoefR * 32 / 100 nCoefL = nCoefL * 32 / 100 system.mySystemCall("amixer -q sset Master %d,%d" % (nCoefL, nCoefR)) system.mySystemCall("amixer -q sset PCM 25") system.mySystemCall("amixer -q sset \"Master Mono\" 32") except BaseException, err: print("setMasterPanning: error '%s'" % str(err))
def setMasterPanning( nPanning = 0 ): "change the sound master panning: 0: center -100: left +100: right" "current bug: currently volume is louder when at border, than at center, sorry" try: debug.debug( "setMasterPanning to %d" % nPanning ); nVol = getCurrentMasterVolume(); nCoefR = nVol + nVol*nPanning/100; nCoefL = nVol - nVol*nPanning/100; nCoefR = nCoefR * 32 / 100; nCoefL = nCoefL * 32 / 100; system.mySystemCall( "amixer -q sset Master %d,%d" % ( nCoefL, nCoefR ) ); system.mySystemCall( "amixer -q sset PCM 25" ); system.mySystemCall( "amixer -q sset \"Master Mono\" 32" ); except BaseException, err: print( "setMasterPanning: error '%s'" % str( err ) );
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 ! if( isinstance( threadWGet, int ) ): # on est ici dans un post d'un systemCall thréadé sur un UsageRemoteTools try: usage = naoqitools.myGetProxy( 'UsageRemoteTools', True ); usage.wait( threadWGet, rTimeOutForAnswerInSec*1000 ); # On a très souvent cette erreur la: "'Function wait exists but parameters are wrong'" la tache est peut etre deja fini ? except BaseException, err:
if( not bJustPrepare ): # debug.debug( "speech::sayAndCache: launching sound now!" ); if( bWaitEnd ): sound.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 ! if( strUseVoice == None ): strUseVoice = getVoice(); if( 'Antoine16' in strUseVoice ): nFreq = 16000; system.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 ) ):
nVolPercent = 100; debug.debug( "setMasterVolume to %d%%" % nVolPercent ); try: ad = naoqitools.myGetProxy( 'ALAudioDevice' ); ad.setOutputVolume( nVolPercent ); return; except BaseException, err: print( "getCurrentMasterVolume: error '%s'" % str( err ) ); print( "WRN: => using old one using fork and shell!" ); strCommand = "amixer -q sset Master " + str( nVolPercent * 32 / 100 ); strCommand += "; amixer -q sset \"Master Mono\" 32"; strCommand += "; amixer -q sset PCM 25"; system.mySystemCall( strCommand ); # setMasterVolume - end def volumeFadeOut(): "Fade out master sound system" nVol = getCurrentMasterVolume(); print( "volumeFadeOut: %d -----> 0" % nVol ); nCpt = 0; while( nVol > 0 and nCpt < 30 ): # when concurrent calls are made with other fade type, it could go to a dead lock. because getCurrentMasterVolume take some time, we prefere to add some counter ++nCpt; # ramping if( nVol > 55 ): nVol -= 3; else: nVol -= 9;
def unPauseMusic(): debug.debug("unPauseMusic") system.mySystemCall("killall -CONT mpg321b")
def pauseMusic(): "pause the music player" debug.debug("pauseMusic") system.mySystemCall("killall -STOP mpg321b")
nVolPercent = 100 debug.debug("setMasterVolume to %d%%" % nVolPercent) try: ad = naoqitools.myGetProxy('ALAudioDevice') ad.setOutputVolume(nVolPercent) return except BaseException, err: print("getCurrentMasterVolume: error '%s'" % str(err)) print("WRN: => using old one using fork and shell!") strCommand = "amixer -q sset Master " + str(nVolPercent * 32 / 100) strCommand += "; amixer -q sset \"Master Mono\" 32" strCommand += "; amixer -q sset PCM 25" system.mySystemCall(strCommand) # setMasterVolume - end def volumeFadeOut(): "Fade out master sound system" nVol = getCurrentMasterVolume() print("volumeFadeOut: %d -----> 0" % nVol) nCpt = 0 while ( nVol > 0 and nCpt < 30 ): # when concurrent calls are made with other fade type, it could go to a dead lock. because getCurrentMasterVolume take some time, we prefere to add some counter ++nCpt # ramping
if (bWaitEnd): sound.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 ! if (strUseVoice == None): strUseVoice = getVoice() if ('Antoine16' in strUseVoice): nFreq = 16000 system.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"
def unPauseMusic(): debug.debug( "unPauseMusic" ); system.mySystemCall( "killall -CONT mpg321b" );
def pauseMusic(): "pause the music player" debug.debug( "pauseMusic" ); system.mySystemCall( "killall -STOP mpg321b" );