Example #1
0
def calibrate(gopro):
  calibration_photos = []
  for i in range(NUM_CALIBRATION_PHOTOS):
    time.sleep(1)
    _, _, photo = gopro.take_raw_photo()
    calibration_photos.append(photo)
    play_audio(AudioKeys.CONFIRM_CALIBRATION_STEP)
  
  save_calibration(calibration_photos[0], 'calibration_info.pickle')
Example #2
0
def main(text):
    mp3_file = "alarm_clock"
    print("Writing to {}.mp3 file..".format(mp3_file))

    radio_nm, radio_link = audio.random_radio()

    text += "\nFinally, " + radio_nm + " radio.."
    audio.make_mp3(text, mp3_file)

    audio.play_audio("%s.mp3" % mp3_file)
    audio.play_audio(radio_link)
Example #3
0
def audio_rec_callback(fname):
    audioplayed = audio.play_audio(beep_audio)
    audioplayed = audio.play_audio(fname)  # todo: erase this

    #if audioplayed:
    print("publish to topic")
    #************* mqtt *************
    local_data = open(fname, 'rb').read()
    client.publish(topic, payload=local_data, qos=0, retain=False)
    #************* mqtt *************

    print('\n\nListening... Press Ctrl+C to exit')
Example #4
0
def initspeech():
    with sr.Microphone() as source:
        print("Listening...")
        audio.play_audio(
            "E:/PROGRAMMING/python programming/sounds/clearly.wav")
        user_audio = r.listen(source)
    command = ""
    try:
        command = r.recognize_google(user_audio)
        audio.play_audio("E:/PROGRAMMING/python programming/sounds/when.wav")
        print("Your command : " + command)
        initiate()
    except:
        print("Could'nt Understand the command : " + command)
        audio.play_audio(
            "E:/PROGRAMMING/python programming/sounds/deduction.wav")
        initiate()
Example #5
0
    def receive(self, text, get_next_text):
        if self.state == States.LISTENING:
            if Commands.INIATE in text:
                play_audio(AudioKeys.COMMAND_PROMPT)
                self.state = States.TAKING_COMMAND
            else:
                play_audio(AudioKeys.MISUNDERSTOOD)
                self.state = States.LISTENING
        elif self.state == States.TAKING_COMMAND:
            if Commands.RESET_BEGIN in text:
                play_audio(AudioKeys.CONFIRM_RESET_BEGIN)
                self.state = States.RESETING
                threading.Thread(target=begin_reset,
                                 args=(self.gopro, )).start()
            elif Commands.TAKE_CHECKPOINT in text:
                play_audio(AudioKeys.CONFIRM_CHECKPOINT)
                self.state = States.LISTENING
                save_checkpoint(self.gopro)
            elif Commands.NEVERMIND in text:
                play_audio(AudioKeys.OK)
                self.state = States.LISTENING
            elif Commands.SHOW_SHOT in text:
                play_audio(AudioKeys.OK)
                self.state = States.LISTENING
                send_command(UiCommands.SHOW_SHOT_AIM)
            elif Commands.SHOW_BOARD in text:
                play_audio(AudioKeys.OK)
                self.state = States.LISTENING
                send_command(UiCommands.SHOW_POOL_TABLE)
            elif Commands.SHOW_RESETTER in text:
                play_audio(AudioKeys.OK)
                self.state = States.LISTENING
                send_command(UiCommands.SHOW_RESET_FRAME)
            elif Commands.CALIBRATE in text:
                self.state = States.CALIBRATING
                play_audio(AudioKeys.CONFIRM_CALIBRATING_BEGIN)
                calibrate(self.gopro)
                play_audio(AudioKeys.CONFIRM_CALIBRATION_END)
                self.state = States.LISTENING
            elif Commands.PRACTICE in text:
                play_audio(AudioKeys.CONFIRM_PRACTICE)

                play_audio(AudioKeys.PROMPT_PRACTICE_TYPE)
                practice_type = get_next_text(
                    re.compile('(random|spot|learning)'))

                include_walls = None
                num_practice_balls = None
                practice_type_num = -1

                if practice_type == 'random':
                    practice_type_num = 0
                    self.num_practice_balls = int(
                        get_next_text(re.compile('\\d')))
                elif practice_type == 'spot':
                    practice_type_num = 1
                    include_walls = bool(
                        get_next_text(re.compile('(true|false)')))
                    self.num_practice_balls = int(
                        get_next_text(re.compile('\\d')))
                elif practice_type == 'learning':
                    practice_type_num = 2
                else:
                    raise Exception('This should not be possible.')

                self.state = States.PRACTICE
            elif Commands.QUIT in text:
                play_audio(AudioKeys.CONFIRM_QUIT)
                self.state = States.LISTENING
                return False
            else:
                play_audio(AudioKeys.MISUNDERSTOOD)
                self.state = States.LISTENING
        elif self.state == States.RESETING:
            if Commands.RESET_END in text:
                play_audio(AudioKeys.CONFIRM_RESET_END)
                self.state = States.LISTENING
                stop_resetting()
            else:
                play_audio(AudioKeys.MISUNDERSTOOD)
                # self.state = States.LISTENING
        elif self.state == States.PRACTICING:
            if Commands.SELECT_SHOT in text:
                play_audio(AudioKeys.CONFIRM_SELECT_SHOT)
                ballNumber = int(get_next_text(re.compile('\\d')))
                pocketNumber = int(get_next_text(re.compile('\\d')))
                send_shot_selection(ballNumber, pocketNumber)
            elif Commands.SET_RESULT in text:
                play_audio(AudioKeys.CONFIRM_SET_RESULT)
                result = get_next_text("(" + "|".join([
                    cmdText
                    for cmd, cmdText, numBalls in ShotResult.POSSIBLE_RESULTS
                    if numBalls == self.num_practice_balls
                ]) + ")")
                shotResultNums = [
                    cmd
                    for cmd, cmdText, numBalls in ShotResult.POSSIBLE_RESULTS
                    if numBalls == self.num_practice_balls
                    and cmdText == result.group()
                ]
                if len(shotResultNums) != 1:
                    raise Exception("This should not happen")
                send_shot_result(shotResultNums[0])
            elif Commands.SET_TRY_AGAIN_OFF in text:
                play_audio(AudioKeys.CONFIRM_TRY_AGAIN_OFF)
                send_command(UiCommands.TURN_OFF_TRY_AGAIN)
            elif Commands.SET_TRY_AGAIN_ON in text:
                play_audio(AudioKeys.CONFIRM_TRY_AGAIN_ON)
                send_command(UiCommands.TURN_ON_TRY_AGAIN)
            elif Commands.QUIT_PRACTICE in text:
                play_audio(AudioKeys.CONFIRM_END_PRACTICE)
                send_command(UiCommands.END_PRACTICE)
                self.state = States.LISTENING
            else:
                play_audio(AudioKeys.MISUNDERSTOOD)
        else:
            raise Exception('Illegal state.')
        return True
Example #6
0
def detected_callback():
    audio.play_audio(beep_audio)
Example #7
0
sys.path.append("./utils/alist_api")
import alist_api

SOUND_INPUT_FILE = "s2t.wav"
SOUND_INPUT_CNV_FILE = "s2t_cnv.wav"
SOUND_OUTPUT_FILE = "t2s.wav"
SOUND_OUTPUT_CNV_FILE = "t2s_cnv.wav"

if __name__ == "__main__":
    # reset gpio
    gpio.reset_gpio()
    while True:
        while not GPIO.input(gpio.GPIO_REGISTER["voice"]):
            time.sleep(1)
        # record audio
        audio.record_audio(filename=SOUND_INPUT_FILE,
                           channel=gpio.GPIO_REGISTER["voice"])
        # get text
        text = alist_api.API_LIST["sound2text"](src=SOUND_INPUT_FILE,
                                                dst=SOUND_INPUT_CNV_FILE)
        print(text)
        # analysis text
        text = analysis.analysis(text=text)
        print(text)
        # get sound
        alist_api.API_LIST["text2sound"](text=text,
                                         src=SOUND_OUTPUT_FILE,
                                         dst=SOUND_OUTPUT_CNV_FILE)
        # play audio
        audio.play_audio(filename=SOUND_OUTPUT_CNV_FILE)
Example #8
0
i = 0

isFirstDetection = False
isWelcomePlayed = False
welcome_audio = "./audio/resources/welcome.wav"

while run:
    print(i)

    if i > 50:
        print('Face DETECTED!')

        if not isFirstDetection:
            print("First detection...")
            isFirstDetection = True
            isWelcomePlayed = audio.play_audio(welcome_audio)
            print(isWelcomePlayed)
            # while not isWelcomePlaying:
            # 	isWelcomePlaying = audio.play_audio(welcome_audio)

        # if the face was detected for the first time but for some reason the welcome audio
        # was not played then try to play it again
        elif isFirstDetection and not isWelcomePlayed:
            isWelcomePlayed = audio.play_audio(welcome_audio)

        time.sleep(3)
    else:
        isFirstDetection = False

    i += 1
    if i > 53: