def apply(self, cam): say(self.text) w = 30 # Screen width in chars text = " " * w + self.text for i in range(0, len(text) + 1): cam.change_text(text[i : i + w]) time.sleep(0.1)
def say_todos(ToDos): sortfirst = 1 sortsecond = 2 todosheet = getTodoItems(user, pw) s = sorted(todosheet.Run(ToDos),key=itemgetter(sortfirst)) todos = sorted(s,key=itemgetter(sortsecond)) todolist = [] lowprilist = [] for i in todos: if not i[3] in ('Done','done','donE','doNE','dONE','DONe','DOne','DONE'): if i[2] != '0' and i[2] != None: output = i[0] if i[1] != None: output += ' by '+d.strptime(i[1],'%m/%d/%Y').strftime('%A %d %B') output += ' ...' todolist.append(output) else: lowpri = i[0] if i[1] != None: lowpri += ' by '+d.strptime(i[1],'%m/%d/%Y').strftime('%A %d %B') lowpri += ' ...' lowprilist.append(lowpri) for i in todolist: festival.say(i) for i in lowprilist: tts.say(i) if len(todolist)+len(lowprilist) == 0: tts.say('No to do\'s for today ...')
def voiceid(): # NOTE: festival.say() blocks, but pygame sounds do not with PTT(): if VOICE_ID_ENABLED: festival.say(VOICE_ID_MESSAGE) if ANNOUNCE_TIME_ENABLED: saytime() courtesy_tone.play() pygame.time.delay(int((courtesy_tone.get_length() + HANGTIME) * 1000))
def sayRSS(url): try: f = feedparser.parse(url) except: festival.say('I failed to retrieve the required data ...') return 1 festival.say(f.feed.title) for i in f.entries: msg = unabriv(re.sub(brre,'\n',i.description).replace('/',' or '))+' ...' tts.say(msg)
def main(): saytodo = True todolist = HOMETODO now = datetime.date.today() today = now.strftime('%a') thisday = 'anyday' # the fist thing the computer says festival.say('good morning ... it\'s time to get up ...') for i in workdays: if today == i: thisday = 'wokday' for i in offdays: if today == i: thisday = 'offday' if thisday == 'workday': # make the computer say the weather and the date tts.say('Transit and Weather Information for '+d.now().strftime('%A %d %B %Y')+' ...') #print("It's "+today) tts.say('Weather for Kensington ...') get_weather('KIAD','washington_dulles_intl_airport','va') #print('got the weather for kensington') tts.say('Weather for Baltimore ...') get_weather('KBWI','baltimore-washington_intl_airport','md') #print('got the weather for baltimore') # make the computer read the Metro and MARC RSS data sayRSS(metrourl) sayRSS(marcurl) saytodo = True todolist = WORKTODO if thisday == 'offday': # same as above just for my home town instead of both home and school tts.say('Transit and Weather Information for '+d.now().strftime('%A %d %B %Y')+' ...') tts.say('Weather for Kensington ...') get_weather('KIAD','washington_dulles_intl_airport','va') saytodo = True if thisday in ('workday','offday'): #regardless fo the type of day say the weather warnings that apply say_warnings([warn_md004_url,warn_md003_url]) if saytodo == True: # say the google calendar appointments and the todo list from google docs spreadsheet tts.say('Your To Do List And Appointments For Today ...') say_todos(todolist) say_gcal('today')
def check_id_period(): global Last_ID_time global ID_wait_flag now = time.time() if (now - ID_PERIOD) >= Last_ID_time: if DEBUG: print "ID period exceeded, last ID was {0}".format(Last_ID_time) # ID period exceeded, we probably need to do it. # Assert PTT if needed old_PTT_state = PTT_state if PTT_state == False: ptt(True) # Has the repeater been used since the last ID? if ID_wait_flag: # Use a polite CW-id cw_id.play() # Wait for ID to play and release PTT if needed: if old_PTT_state: # Let caller handle courtesy tone and PTT pygame.time.set_timer(CW_ID_EVENT, (int(cw_id.get_length() + 1) * 1000)) else: # This is a tail ID: block for duration and stop TX pygame.time.delay(int(cw_id.get_length() + HANGTIME) * 1000) ptt(False) else: # Use a short voice ID This blocks so we can't interrupt it festival.say(CALLSIGN) # Maybe cache to .wav instead? # Release PTT if needed: if not old_PTT_state: ptt(False) # Reset ID flag and timestamp ID_wait_flag = False Last_ID_time = now return True return False
def check_id_period(): global Last_ID_time global ID_wait_flag now = time.time() if (now - ID_PERIOD) >= Last_ID_time: if DEBUG: print "ID period exceeded, last ID was {0}".format( Last_ID_time) # ID period exceeded, we probably need to do it. # Assert PTT if needed old_PTT_state = PTT_state if PTT_state == False: ptt(True) # Has the repeater been used since the last ID? if ID_wait_flag: # Use a polite CW-id cw_id.play() # Wait for ID to play and release PTT if needed: if old_PTT_state: # Let caller handle courtesy tone and PTT pygame.time.set_timer(CW_ID_EVENT, (int(cw_id.get_length()+1) * 1000)) else: # This is a tail ID: block for duration and stop TX pygame.time.delay(int(cw_id.get_length()+HANGTIME) * 1000) ptt(False) else: # Use a short voice ID This blocks so we can't interrupt it festival.say(CALLSIGN) # Maybe cache to .wav instead? # Release PTT if needed: if not old_PTT_state: ptt(False) # Reset ID flag and timestamp ID_wait_flag = False Last_ID_time = now return True return False
def saytime(): time_string = getTimeString() if DEBUG: print "TTS: " + time_string festival.say(time_string)
def main(): global PTT_timer global Repeater_enabled global PTT_state global PTT_timer global PTT_recovery_timer global ID_wait_flag global PTT_hanging global dtmf_queue setup_multimon() totp = pyotp.TOTP('5ZEAFI6HRJZOQ52T') print "Repeater started" courtesy_tone.play() # Event loop while True: for event in pygame.event.get(): if event.type == TIMEOUT_RECOVERY_EVENT: # Check that noone is transmitting if GPIO.input(COR_PIN) == 1: pygame.time.set_timer(TIMEOUT_RECOVERY_EVENT, 0) print "Timeout cleared" ptt(True) festival.say("Time out clear") if not check_id_period(): ptt(False) Repeater_enabled = True else: print "WARN: COR still active, skipping until fault is cleared" # Skip the rest of event processing if repeater is timed-out if not Repeater_enabled: continue # Events below here are repeater-only # and can be disabled under certain conditions. # ============================================ # Timing events fire once per second (1000 ms) if event.type == TIMEOUT_TIMER_EVENT: PTT_timer -= 1 if event.type == HANGTIME_RELEASE_PTT_EVENT: pygame.time.set_timer(HANGTIME_RELEASE_PTT_EVENT, 0) PTT_hanging = False ptt(False) if event.type == CW_ID_EVENT: if DEBUG: print "CW_ID_EVENT triggered" pygame.time.set_timer(CW_ID_EVENT, 0) # Only play courtesy tone and release if no RX if GPIO.input(COR_PIN) == 1: if DEBUG: print "COR is inactive, playing courtesy tone" courtesy_tone.play() pygame.time.delay(int(courtesy_tone.get_length()) * 1000) # Set hangtime and event to disable PTT: pygame.time.set_timer(HANGTIME_RELEASE_PTT_EVENT, HANGTIME * 1000) COR_State = GPIO.input(COR_PIN) if Repeater_enabled: if COR_State == 0 and not PTT_state: # Active low after JFET if DEBUG: print "RX active, start TOT timer" # Engage PTT ptt(True) PTT_hanging = False # Start TOT timer PTT_timer = TIMEOUT_TIMER pygame.time.set_timer(TIMEOUT_TIMER_EVENT, 1000) # Reset activity flag ID_wait_flag = True # User has stopped transmitting: if COR_State == 1 and PTT_state and not PTT_hanging: if DEBUG: print "RX release, TOT timer reset: {0}s was remaining".format( PTT_timer) PTT_hanging = True # Stop TOT timer event and reset timer pygame.time.set_timer(TIMEOUT_TIMER_EVENT, 0) PTT_timer = -1 # Polite CW-ID if needed ID_played = check_id_period() if not ID_played: # Play courtesy tone (otherwise set in CW_ID_EVENT) courtesy_tone.play() # Block for courtesy tone duration pygame.time.delay(int(courtesy_tone.get_length()) * 1000) # Set timer for hangtime duration and to release PTT pygame.time.set_timer(HANGTIME_RELEASE_PTT_EVENT, HANGTIME * 1000) if PTT_timer == 0: # Stop the TOT timer event and reset timer pygame.time.set_timer(TIMEOUT_TIMER_EVENT, 0) PTT_timer = -1 # Mute RX audio and play time-out message RX_audio_enable(False) festival.say("Time out") RX_audio_enable(True) # Release PTT ptt(False) # Start time-out recovery timer pygame.time.set_timer(TIMEOUT_RECOVERY_EVENT, TIMEOUT_DURATION * 1000) # Disable repeater Repeater_enabled = False if COR_State == 1 and not PTT_state and not PTT_hanging: check_id_period() #pygame.time.tick(30) dtmf_digits = process_dtmf() if dtmf_digits is not None: dtmf_queue.extend(dtmf_digits) if ''.join(dtmf_queue[-8:]) == '**{0}'.format(totp.now()): print "Access code entered correctly" dtmf_queue = [] # Toggle repeater state ptt(True) if Repeater_enabled: festival.say(CALLSIGN + " REPEATER DISABLED") repeater_down_tone.play() pygame.time.delay(int( (repeater_down_tone.get_length()) * 1000)) Repeater_enabled = False else: festival.say(CALLSIGN + " REPEATER ENABLED") repeater_up_tone.play() pygame.time.delay(int((repeater_up_tone.get_length()) * 1000)) Repeater_enabled = True ptt(False) print dtmf_queue pygame.time.delay(100)
#!/usr/bin/env python import festival festival.say("Hello World")
title = waep.Title()[0] print "-", title if not "input" in title.lower(): subpods = waep.Subpods() for subpod in subpods: waesp = wap.Subpod(subpod) # print ' =>',waesp.Title(), '=>', waesp.Plaintext(),type(waesp.Plaintext()[0]) == str if ( (type(waesp.Plaintext()[0]) == str or type(waesp.Plaintext()[0]) == unicode) and waesp.Plaintext()[0].strip() != "" and not processed ): string_to_speech = waesp.Plaintext()[0].strip().encode("iso-8859-2") string_to_speech = string_to_speech.replace("=", "") string_to_speech = string_to_speech.replace("<", "") string_to_speech = string_to_speech.replace(">", "") string_to_speech = string_to_speech.replace("|", ", ") string_to_speech = string_to_speech.replace("[", "") string_to_speech = string_to_speech.replace("]", "") string_to_speech = string_to_speech.replace("\\n2", "") string_to_speech = string_to_speech.replace("\n", ". . ") print string_to_speech festival.say(string_to_speech) processed = True # festival.say(response_obj['hypotheses'][0]['utterance'].encode('iso-8859-2')) print "cleanup" os.unlink(record_file) os.unlink(record_file + ".flac")
def main(): global PTT_timer global Repeater_enabled global PTT_state global PTT_timer global PTT_recovery_timer global ID_wait_flag global PTT_hanging global dtmf_queue setup_multimon() totp = pyotp.TOTP('5ZEAFI6HRJZOQ52T') print "Repeater started" courtesy_tone.play() # Event loop while True: for event in pygame.event.get(): if event.type == TIMEOUT_RECOVERY_EVENT: # Check that noone is transmitting if GPIO.input(COR_PIN) == 1: pygame.time.set_timer(TIMEOUT_RECOVERY_EVENT, 0) print "Timeout cleared" ptt(True) festival.say("Time out clear") if not check_id_period(): ptt(False) Repeater_enabled = True else: print "WARN: COR still active, skipping until fault is cleared" # Skip the rest of event processing if repeater is timed-out if not Repeater_enabled: continue # Events below here are repeater-only # and can be disabled under certain conditions. # ============================================ # Timing events fire once per second (1000 ms) if event.type == TIMEOUT_TIMER_EVENT: PTT_timer -= 1 if event.type == HANGTIME_RELEASE_PTT_EVENT: pygame.time.set_timer(HANGTIME_RELEASE_PTT_EVENT, 0) PTT_hanging = False ptt(False) if event.type == CW_ID_EVENT: if DEBUG: print "CW_ID_EVENT triggered" pygame.time.set_timer(CW_ID_EVENT, 0) # Only play courtesy tone and release if no RX if GPIO.input(COR_PIN) == 1: if DEBUG: print "COR is inactive, playing courtesy tone" courtesy_tone.play() pygame.time.delay(int(courtesy_tone.get_length()) * 1000) # Set hangtime and event to disable PTT: pygame.time.set_timer(HANGTIME_RELEASE_PTT_EVENT, HANGTIME*1000) COR_State = GPIO.input(COR_PIN) if Repeater_enabled: if COR_State == 0 and not PTT_state: # Active low after JFET if DEBUG: print "RX active, start TOT timer" # Engage PTT ptt(True) PTT_hanging = False # Start TOT timer PTT_timer = TIMEOUT_TIMER pygame.time.set_timer(TIMEOUT_TIMER_EVENT, 1000) # Reset activity flag ID_wait_flag = True # User has stopped transmitting: if COR_State == 1 and PTT_state and not PTT_hanging: if DEBUG: print "RX release, TOT timer reset: {0}s was remaining".format(PTT_timer) PTT_hanging = True # Stop TOT timer event and reset timer pygame.time.set_timer(TIMEOUT_TIMER_EVENT, 0) PTT_timer = -1 # Polite CW-ID if needed ID_played = check_id_period() if not ID_played: # Play courtesy tone (otherwise set in CW_ID_EVENT) courtesy_tone.play() # Block for courtesy tone duration pygame.time.delay(int(courtesy_tone.get_length()) * 1000) # Set timer for hangtime duration and to release PTT pygame.time.set_timer(HANGTIME_RELEASE_PTT_EVENT, HANGTIME*1000) if PTT_timer == 0: # Stop the TOT timer event and reset timer pygame.time.set_timer(TIMEOUT_TIMER_EVENT, 0) PTT_timer = -1 # Mute RX audio and play time-out message RX_audio_enable(False) festival.say("Time out") RX_audio_enable(True) # Release PTT ptt(False) # Start time-out recovery timer pygame.time.set_timer(TIMEOUT_RECOVERY_EVENT, TIMEOUT_DURATION*1000) # Disable repeater Repeater_enabled = False if COR_State == 1 and not PTT_state and not PTT_hanging: check_id_period() #pygame.time.tick(30) dtmf_digits = process_dtmf() if dtmf_digits is not None: dtmf_queue.extend(dtmf_digits) if ''.join(dtmf_queue[-8:]) == '**{0}'.format(totp.now()): print "Access code entered correctly" dtmf_queue = [] # Toggle repeater state ptt(True) if Repeater_enabled: festival.say(CALLSIGN + " REPEATER DISABLED") repeater_down_tone.play() pygame.time.delay(int((repeater_down_tone.get_length()) * 1000)) Repeater_enabled = False else: festival.say(CALLSIGN + " REPEATER ENABLED") repeater_up_tone.play() pygame.time.delay(int((repeater_up_tone.get_length()) * 1000)) Repeater_enabled = True ptt(False) print dtmf_queue pygame.time.delay(100)
#import commands import festival import aiml k = aiml.Kernel() #k.loadBrain("alice.brn") k.learn("startup.xml") k.respond("load aiml b") #commands.getoutput("espeak -k20 -s150 -ven+15 Hello User") k.saveBrain("alice.brn") while True: len0 = k.respond(raw_input("Me:>")) #len1="espeak -k20 -s150 -ven+10" #len0 = " \""+len0+"\"" #len2=len1+len0 #commands.getoutput(len2) festival.say(len0) print len0
k.setBotPredicate("kindmusic","all") k.setBotPredicate("location","here") k.setBotPredicate("looklike","you") k.setBotPredicate("question","What?") k.setBotPredicate("sign","none") k.setBotPredicate("talkabout","anything") k.setBotPredicate("wear","nothing") k.setBotPredicate("website","http://serveramd.dyndns.org") k.setBotPredicate("email","*****@*****.**") k.setBotPredicate("language","any") k.setBotPredicate("msagent","no") #saludo inicial y muestra la entrada de órdenes print("Escribe quit o salir para cerrar el programa\n") print("¿Soy Aigor que puedo hacer por tí?") say("soy Aigor que puedo hacer por t'i?") #bucle principal #como Festival no entiende utf-8 he usado latin1 while True: user_input = raw_input("Pregunta > ") if user_input == "quit" or user_input == "salir": break else: #Traduce la entrada a ingles para que la entienda el bot trans = translate(user_input, lang_to="en").encode('latin1') #busca la respuesta answer = k.respond(trans) #Traduce la respuesta a español(o cualquier otro soportado por Google) traans = translate(answer, lang_to="es").encode('latin1') #Imprime/dice la respuesta print(traans).decode('latin1')
def say(self, text): if self.festival: #self.f = festival.open() festival.say(text) elif self.espeak: espeakTTS.say(text)
#import commands import festival import aiml k=aiml.Kernel() #k.loadBrain("alice.brn") k.learn("startup.xml") k.respond("load aiml b") #commands.getoutput("espeak -k20 -s150 -ven+15 Hello User") k.saveBrain("alice.brn") while True : len0=k.respond(raw_input("Me:>")) #len1="espeak -k20 -s150 -ven+10" #len0 = " \""+len0+"\"" #len2=len1+len0 #commands.getoutput(len2) festival.say(len0) print len0
import festival festival.say("Hello World")