Exemplo n.º 1
0
def play(fileName, audioOutput, loopCount, loopDelaySec):
    # Reference:
    # https://realpython.com/playing-and-recording-sound-python/#playing-audio-files
    # https://askubuntu.com/questions/115369/how-to-play-mp3-files-from-the-command-line
    # https://www.ffmpeg.org/ffplay.html
    # https://www.ffmpeg.org/ffmpeg-devices.html#Examples-8
    # Use aplay -L to find audio output device. e.g. HDMI is plughw

    playCommand = "ffmpeg -f alsa {outputdevice} -loglevel quiet -i {filename} 2>/dev/null".format(
        outputdevice=get_audio_output(audioOutput), filename=fileName)

    try:

        coutput.print_watcher("fileName")

        for loopIndex in range(0, loopCount):
            coutput.print_debug("Executing play")
            coutput.print_watcher("playCommand")
            os.system(playCommand)

            if loopIndex != (loopCount - 1):
                time.sleep(loopDelaySec)

    except:
        coutput.print_err("Unable to play audio from " + fileName)
        coutput.print_watcher("sys.exc_info()")
Exemplo n.º 2
0
 def pronounce_word(self):
     if self.activePronunciation == SB_EMPTY_STRING:
         coutput.print_err("Unable to lookup audio pronunciation")
     else:
         wordToken = re.sub('[^a-zA-Z]', SB_EMPTY_STRING, self.activeWord.lower())
         pronunciationToken = re.sub('[^a-zA-Z]', SB_EMPTY_STRING, self.activePronunciationWord.lower())
         if wordToken != pronunciationToken:
             coutput.print_warn("A different form of the word is being pronounced.")
         cfile.play(self.activePronunciation, SB_AUDIO_OUTPUT, SB_REPEAT_COUNT, SB_REPEAT_DELAY)
Exemplo n.º 3
0
    def print_word_definition(self):
        if len(self.activeDefinition) == 0:
            coutput.print_err("Unable to lookup dictionary definition")
        else:
            definitionIndex = 0
            for definition in self.activeDefinition:
                if definitionIndex >= SB_DEFINITION_COUNT:
                    break

                # Check for definitions that contain the word itself
                if SB_DEFINITION_HIDE_EXPLICIT:
                    formattedDefinition = re.sub(self.activeWord, '*' * len(self.activeWord), definition, flags=re.IGNORECASE)

                formattedDefinition = SB_LIST_BULLET + formattedDefinition
                print formattedDefinition
                definitionIndex += 1
Exemplo n.º 4
0
def play_legacy(fileName, audioOutput, loopCount, loopDelaySec):
    # Reference:
    # https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init
    # http://techqa.info/programming/question/27745134/how-can-i-extract-the-metadata-and-bitrate-info-from-a-audio/video-file-in-python

    try:
        #Enable for RaspberryPi
        coutput.print_debug("Executing set_audio_output")
        set_audio_output(audioOutput)

        coutput.print_debug("Executing mediainfo")
        fileInfo = mediainfo(fileName)

        coutput.print_watcher("fileName")
        coutput.print_watcher("fileInfo['sample_rate']")
        coutput.print_watcher("fileInfo['bits_per_sample']")
        coutput.print_watcher("fileInfo['channels']")

        for loopIndex in range(0, loopCount):
            # Syntax: init(frequency=22050, size=-16, channels=2, buffer=4096)
            pygame.mixer.init()
            #pygame.mixer.init(frequency=long(float(fileInfo['sample_rate'])), channels=int(fileInfo['channels']))

            coutput.print_debug("Executing pygame.mixer.music.load")
            pygame.mixer.music.load(fileName)

            coutput.print_debug("Executing pygame.mixer.music.play")
            pygame.mixer.music.play()
            while pygame.mixer.music.get_busy() == True:
                continue
            time.sleep(
                0.06
            )  # introduce delay to ensure that the end of the audio is not clipped during playback

            coutput.print_debug("Executing pygame.mixer.stop")
            pygame.mixer.stop()
            coutput.print_debug("Executing pygame.mixer.quit")
            pygame.mixer.quit()

            if loopIndex != (loopCount - 1):
                time.sleep(loopDelaySec)

        set_audio_output('auto')
    except:
        coutput.print_err("Unable to play audio from " + fileName)
        coutput.print_watcher("sys.exc_info()")
Exemplo n.º 5
0
def play_url(connectionPool, sourceURL, audioOutput, loopCount, loopDelay):

    try:
        coutput.print_debug("Executing set_audio_output")
        set_audio_output(audioOutput)

        if '.mp3' in sourceURL or '.wav' in sourceURL:
            tempFileName = "dlfile_ts{TIMESTAMP}_rnd{RAND}.tmp".format(
                TIMESTAMP=time.strftime("%Y%m%d%H%M%S"),
                RAND=str(uuid.uuid4()))
            download(connectionPool, sourceURL, tempFileName)
            play(tempFileName, audioOutput, loopCount, loopDelay)
            delete(tempFileName)
        else:
            coutput.print_err("Unable to play audio from " + sourceURL)

        set_audio_output('auto')
    except:
        coutput.print_err("Unable to play audio from " + sourceURL)
Exemplo n.º 6
0
        for menuItem in APP_NAVIGATE_MENU.split('>'):
            print("Navigating to menu item: {}".format(menuItem))
            browser.find_element_by_link_text(menuItem).click()
            time.sleep(APP_WAIT_DELAY)

        print("\nFetching module meta-info ...")
        print("Module URL: " + browser.current_url)
        moduleTitle = browser.find_element_by_xpath("//div[@class='panel-heading']").text
        moduleTableElement = browser.find_element_by_xpath("//div[@class='table-responsive']")

        # Break loop if try is successful
        break

    except Exception as e:
        # Displays the trace for the error
        coutput.print_err(traceback.format_exc())

        exceptionName = type(e).__name__
        if exceptionName == "TimeoutException":
            coutput.print_warn("Connection timeout. Waiting for {}s ...".format(APP_TIMEOUT_WAIT_DELAY))
            time.sleep(APP_TIMEOUT_WAIT_DELAY)
        else:
            exit_app(1)

# Retrieve sets from module
setRowElements = moduleTableElement.find_elements_by_xpath("//table/tbody/tr")

setCounter = 0
setEntries = []
processFlag = False