Example #1
0
def say_with_google(word, autoremove=True, background=False, debug=False):
    """
    Say a word with Google.

    https://ubuntuincident.wordpress.com/2012/03/27/audio-pronunciation-of-words-from-google/
    The return value is a tuple: (found, mp3_file), where
    found is True if the word was retrieved successfully (False otherwise), and
    mp3_file is the path of the locally saved mp3 (or None if it was not saved).
    Set autoremove to False if you want to work with the mp3 later, when this
    function returned.
    The function stores the mp3 files in /tmp.
    """
    found = False  # Was the mp3 successfully found?
    mp3_file = None  # Is the locally saved mp3 file kept?
    url = template.format(word=word)
    content = web.get_page(url, user_agent=True)
    if content:
        found = True
        fname = "/tmp/{word}.mp3".format(word=word)
        fs.store_content_in_file(content, fname, overwrite=True)
        mp3_file = fname
        if not debug:
            play(fname, background=background)
        if autoremove:
            os.unlink(fname)
            mp3_file = None
    else:
        found = False
        mp3_file = None

    return (found, mp3_file)
Example #2
0
def say_with_google(word, autoremove=True, background=False, debug=False):
    """
    Say a word with Google.

    https://ubuntuincident.wordpress.com/2012/03/27/audio-pronunciation-of-words-from-google/
    The return value is a tuple: (found, mp3_file), where
    found is True if the word was retrieved successfully (False otherwise), and
    mp3_file is the path of the locally saved mp3 (or None if it was not saved).
    Set autoremove to False if you want to work with the mp3 later, when this
    function returned.
    The function stores the mp3 files in /tmp.
    """
    found = False  # Was the mp3 successfully found?
    mp3_file = None  # Is the locally saved mp3 file kept?
    url = template.format(word=word)
    content = web.get_page(url, user_agent=True)
    if content:
        found = True
        fname = '/tmp/{word}.mp3'.format(word=word)
        fs.store_content_in_file(content, fname, overwrite=True)
        mp3_file = fname
        if not debug:
            play(fname, background=background)
        if autoremove:
            os.unlink(fname)
            mp3_file = None
    else:
        found = False
        mp3_file = None

    return (found, mp3_file)
Example #3
0
def print_result(word, hyphen, mp3):
    """Print the result and play the audio file."""
    print "Word:          {word}".format(word=word)
    if hyphen:
        print "Hyphenation:   {hyphen}".format(hyphen=hyphen)
    if mp3:
        print "Pronunciation: {mp3}".format(mp3=mp3)
        #audio.play(mp3, background=True)
        play(mp3)
Example #4
0
def print_result(word, hyphen, mp3):
    """Print the result and play the audio file."""
    print "Word:          {word}".format(word=word)
    if hyphen:
        print "Hyphenation:   {hyphen}".format(hyphen=hyphen)
    if mp3:
        print "Pronunciation: {mp3}".format(mp3=mp3)
        #audio.play(mp3, background=True)
        play(mp3)
Example #5
0
def main():
    cnt = 0
    while True:
        cnt += 1
        print '# testing...' if cnt == 1 else '# test again...'
        if network.is_internet_on(method=2):
            print '# Whoa, your net is alive!'
            play(AUDIO)
            break
        else:
            print '# no connection, waiting...'
            sleep(10)
Example #6
0
def main():
    cnt = 0
    while True:
        cnt += 1
        print '# testing...' if cnt == 1 else '# test again...'
        if network.is_internet_on(method=2):
            print '# Whoa, your net is alive!'
            play(AUDIO)
            break
        else:
            print '# no connection, waiting...'
            sleep(10)