示例#1
0
    def test2Array(self):
        try:
            if self.config.has_key("2array_mic_hat"):
                sys.path.append(self.config["2array_mic_hat"])
                from pixels import Pixels
                pixels = Pixels()
                pixels.wakeup()
                time.sleep(3)
                pixels.off()
                time.sleep(2)
                pixels.think()
                time.sleep(3)
                for i in range(0, 5):
                    pixels.speak()
                    time.sleep(1)

                pixels.off()
                time.sleep(1)
        except Exception as e:
            print e.message

#Thread for running music in the background
def musicThread():
    global stop_threads
    global player
    global Instance
    while True:
        playMusic(Instance, player)
        if stop_threads:
            break
    print("Music thread stopped")


#Indicate program startup
pixels.wakeup()
pixels.speak()

_thread.start_new_thread(musicThread, ())  #Start music playlist
print("Initializing music player")
while (player.get_state() != vlc.State.Playing):
    None  #Wait for player to be initialized
time.sleep(2)
player.pause()
print("Music paused")
pixels.off()

previous_time = time.perf_counter()  #Initialize music timer
while True:
    #Power off button pressed
    if GPIO.input(BUTTON_PIN) == 0:
示例#3
0
                if wait_time == 0:
                    break

            try:
                recognized_text = r.recognize_google(audio)
            except sr.UnknownValueError as e:
                pass
            except sr.RequestError as e:
                logger.error("service is down")
                pass
            os.remove(filename)
            return recognized_text


px = Pixels()  # Initializing the Pixel class for RE-SPEAKER PiHAT LED.
px.wakeup()
time.sleep(2)
px.off()

a = voice()  # Initializing the voice class.
"""
Infinite loop:
    1. Reading microphone for 3 sec and generation .wav file.
    2. Creating thread with voice_command_processor() method for converting speech to text.
    3. IF wake word is detected (in my case Gideon):

        a. Clearing recognized_text global variable.
        b. Turing on the LED.
        c. Audio reply with "how can i help you"
        d. Start reading from pyaudio stream for next 5 sec for question.
        e. Convert the audio to text using voice_command_processor().