Example #1
0
def active_listen():
    r = speech_recognition.Recognizer()

    with speech_recognition.Microphone() as src:    # use the default microphone as the audio source
        r.adjust_for_ambient_noise(src)             # listen for 1 second to calibrate the energy threshold for ambient noise levels
        print("\n~ Active listening... ")
        tts.play_mp3("double-beep.mp3")
        audio = r.listen(src)                       # listen for the first phrase and extract it into audio data
    
    msg = ''
    try:
        msg = r.recognize_google(audio)             # recognize speech using Google Speech Recognition
        print("\n~ \""+msg+"\"")
    except LookupError:                             # speech is unintelligible
        msg = ""
        print("\n~ "+ERROR_MESSAGE+"\n")
        tts.speak(ERROR_MESSAGE)
    finally:
        return msg
Example #2
0
 def action(self, text):
     self.speak("Turning up...")
     response = input('Do you want to specify a directory? Y/N: ')
     if response == 'Y':
         music_dir = input('What is your music directory: ')
         shuffle = input('Do you want a specific song? Y/N: ')
         if shuffle == 'Y':
             song = input('What song do you want to be played?: ')
             play_mp3(song, music_dir) 
         else:
             songs = [f for f in listdir(music_dir) if isfile(join(music_dir, f))]
             while 1:
                 song = random.choice(songs)
                 while song.endswith(".mp3"):
                     play_mp3(song, music_dir)
                     song = random.choice(songs)
     else:
         play_mp3("limbo.mp3")