Esempio n. 1
0
def _GetHeadlinesFromFile(filename):
  try:
    f = open("%s/%s.txt" % (configuration.NEWS_DIR, filename))
  except IOError:
    speaker.Speak("Error. Cannot find headline list.")
    return []
  story_descriptions = [line for line in f]
  f.close()
  stories = []
  for descr in story_descriptions:
    location = "%s/%s.txt" % (configuration.NEWS_DIR, descr.split()[-1])
    headline = " ".join(descr.split()[:-1])
    stories.append(_Story(headline, location))
  return stories
Esempio n. 2
0
def SpeakTime():
    # Easter eggs!
    choice = random.random()
    if choice < 0.02:
        speaker.Speak("adventure time!")
        return
    elif choice < 0.04:
        speaker.Speak("shirtless o'clock!")
    else:
        # Actually give the time
        (h, m
         ) = _GetNumericalTime()  # 24 hour time, rounded to the nearest 5 min.
        minute_text = _FormatMinute(h, m)
        hour_text = _FormatHour(h, m)
        text = minute_text % hour_text

        # Special cases:
        if h == 12 and m == 0:
            text = "noon"
        if h == 0 and m == 0:
            text = "midnight"

        speaker.Speak(text)
Esempio n. 3
0
def _ReadNews(stories):
  speaker.Acknowledge()
  # We need a for loop over all the stories, except sometimes we want to go
  # backwards one. So, make it a while loop.
  i = 0
  while i < len(stories):
    story = stories[i]
    speaker.Speak(story.headline)
    cl.ClearCommands()
    cl.Listen()
    time.sleep(3)
    cl.Pause()
    if cl.HasCommand():
      cmd = cl.GetCommand()
      print "Got command: %s" % cmd
      if cmd == STOP:
        print "stopping..."
        speaker.Acknowledge()
        return
      elif cmd == READ:
        print "reading story..."
        speaker.Acknowledge()
        _ReadArticle(story)
      elif cmd == PREV:
        print "reading previous story..."
        if i > 0:
          speaker.Acknowledge()
          _ReadArticle(stories[i-1])
          i -= 1  # Maybe read the current one as well as the previous one...
        else:
          speaker.Speak("Warning. No previous article to read. Skipping.")
      else:
        print "unrecognized command: %s" % cmd
        speaker.Speak("Warning: unrecognized command (%s). Ignoring." % cmd)
    i += 1
  speaker.Speak("No more headlines.")
Esempio n. 4
0
def WakeUp():
    """
  This is a perpetual loop that waits for the phrase "oh computerbox" and then
  calls ExecuteCommand().
  """
    waker = MakeWaker()
    cl = MakeCommandListener()

    waker.Listen()
    while True:
        print "back in main while loop..."
        cmd = waker.BlockingGetCommand()
        if cmd == LISTEN:
            print "listening for command!"
            waker.Pause()
            ExecuteCommand(cl)
            time.sleep(1)  # Avoid a race condition in gst?
            waker.Listen()
        elif cmd == UNKNOWN:
            print "ingoring noise."
            pass  # Ignore it.
        else:
            speaker.Speak("Unexpected command! " +
                          "Something is very wrong in the main loop.")
Esempio n. 5
0
def WeatherForecast():
    f = open("%s/weather.txt" % configuration.NEWS_DIR)
    forecast = f.read()
    f.close()
    speaker.Speak(forecast)
Esempio n. 6
0
def Unimplemented():
    speaker.Speak("This command is not yet implemented in the github "
                  "version of this project. Ignoring command.")
    speaker.Acknowledge()
Esempio n. 7
0
def _ReadArticle(story):
  print story.location
  speaker.SpeakFile(story.location)
  time.sleep(1)  # Pause at the end of the article
  speaker.Speak("Resuming Headlines.")
  time.sleep(0.5)