def say(message): ''' Speak a message. Runs a "say" program, passing the message on the command line. Because most systems are not set up for speech, it is not an error if the "say" program is missing or fails. It is often easy to add a "say" program to a system. For example, a linux system using festival for speech can use a one line script: festival --batch "(SayText \"$*\")" Depending on the underlying 'say' command's implementation, say() probably does not work unless user is in the 'audio' group. >>> say('test say') ''' enabled = True if enabled: try: # the words are unintelligible, and usually all we want is to know something happened # message = 'tick' # just a sound #DEBUG # os.system passes successive lines to sh message = message.split('\n')[0] sh.say(*message) except: pass
def say_finished(text='Work complete', additional_comment='', email_failed=True): ''' Uses the text-to-speech capabilities to indicate when something is finished. If say doesn't work, try to send an email instead. ''' try: import sh sh.say(text) except Exception: if email_failed: email_finished(text=additional_comment, subject=text)
def say_finished(text="Work complete", additional_comment="", email_failed=True): """ Uses the text-to-speech capabilities to indicate when something is finished. If say doesn't work, try to send an email instead. """ try: import sh sh.say(text) except ImportError: if email_failed: try: email_finished(text=additional_comment, subject=text) except socket_error as serr: if serr.errno != errno.ECONNREFUSED: # Not the error we are looking for, re-raise raise serr print text, additional_comment
def climate_control(self): u"""State machine for climate control / Stoßlüften.""" # Current temperature percent change sl_temp = self.df.temperature.pct_change(periods=180).iloc[-1] # Current humidity percent change sl_hum = self.df.humidity.pct_change(periods=90).iloc[-1] print("SLT {}".format(sl_temp)) print("SLH {}".format(sl_hum)) # Stoßlüften underway, wait for humidity change to return to 0 if self.sl_start is not None: if abs(sl_hum) < SL_HUM_THRESHOLD: td = (datetime.now() - self.sl_start).seconds / 60 self.sl_start = None print("Venting finished") say( "Achtung! Fenster schließen. {} minutes have passed.". format(int(td)), *VOICE_PARAMS) else: print("Current humchange target: {}".format(SL_HUM_THRESHOLD)) # Weiter lüften pass # Check for Stoßlüften threshold to be reached elif sl_temp < SL_THRESHOLD: say("Stoßlüften aktiviert", *VOICE_PARAMS) self.sl_start = datetime.now() self.target_temperature = self.df.temperature.iloc[-180] print("New target temperature {} C".format( self.target_temperature)) # Check for reaching the current target temperature if self.target_temperature is not None: print("Current target: {} C".format(self.target_temperature)) if self.df.temperature.iloc[-1] >= self.target_temperature: self.target_temperature = None print("Temperature target reached") say("Temperature restored. Ready for next Stoßlüften cycle.", *VOICE_PARAMS)
def serenaSay(msg, **params): sh.say(msg.format(**params))
def play_sound(words, rate=220): sh.say(words, '-r %d' % rate)