示例#1
0
def setup(robot_config):
    global type
    global tts_module
    global mute_anon
    global url_filter
    global hw_num

    type = robot_config.get('tts', 'type')
    mute_anon = not robot_config.getboolean('tts', 'anon_tts')
    url_filter = robot_config.getboolean('tts', 'filter_url_tts')

    # get playback device hardware num from name.
    audio_device = robot_config.get('tts', 'audio_device')

    # convert the device to hw num if not on windows
    if platform.system() != "Windows":
        if audio_device != '':
            temp_hw_num = audio_util.getSpeakerByName(
                audio_device.encode('utf-8'))
            if temp_hw_num != None:
                robot_config.set('tts', 'hw_num', str(temp_hw_num))

    hw_num = robot_config.get('tts', 'hw_num')

    if type != 'none':
        # set volume level

        # tested for 3.5mm audio jack
        #if robot_config.getint('tts', 'tts_volume') > 50:
        #os.system("amixer set PCM -- -100")

        # tested for USB audio device
        os.system("amixer -c %d cset numid=3 %d%%" % (robot_config.getint(
            'tts', 'hw_num'), robot_config.getint('tts', 'tts_volume')))

    #import the appropriate tts handler module.
    log.debug("loading module tts/%s", type)
    if robot_config.getboolean('misc', 'custom_tts'):
        if os.path.exists('tts/tts_custom.py'):
            if (sys.version_info > (3, 0)):
                tts_module = importlib.import_module('tts.tts_custom')
            else:
                tts_module = __import__('tts.tts_custom',
                                        fromlist=['tts_custom'])
        else:
            log.info("Unable to find tts/tts_custom.py")
            if (sys.version_info > (3, 0)):
                tts_module = importlib.import_module('tts.' + type)
            else:
                tts_module = __import__("tts." + type, fromlist=[type])
    else:
        if (sys.version_info > (3, 0)):
            tts_module = importlib.import_module('tts.' + type)
        else:
            tts_module = __import__("tts." + type, fromlist=[type])

    #call the tts handlers setup function
    tts_module.setup(robot_config)
示例#2
0
def setup(robot_config):
    global type
    global tts_module
    global mute_anon
    global url_filter
    global hw_num
    global delay_tts
    global delay
    global tts_volume

    type = robot_config.get('tts', 'type')
    mute_anon = not robot_config.getboolean('tts', 'anon_tts')
    url_filter = robot_config.getboolean('tts', 'filter_url_tts')

    if robot_config.has_option('tts', 'delay_tts') and robot_config.has_option(
            'tts', 'delay'):
        delay_tts = robot_config.getboolean('tts', 'delay_tts')
        delay = robot_config.getint('tts', 'delay')

    if robot_config.has_option('tts', 'tts_volume'):
        tts_volume = robot_config.getint('tts', 'tts_volume')


# TODO: Delay TTS may not currently be via, and messenger no longer exist
#       and sending messages to chat cannot currently be disabled.
#    if delay_tts and not robot_config.getboolean('messenger', 'enable'):
#        log.error("Warning! delayed TTS requires messenger.")
#        log.error("delayed TTS disabled.")
#        delay_tts = False

# get playback device hardware num from name.
    if robot_config.has_option('tts', 'speaker_device'):
        audio_device = robot_config.get('tts', 'speaker_device')
    else:
        log.warn("controller.conf is out of date. Consider updating.")
        audio_device = robot_config.get('tts', 'audio_device')

    # convert the device to hw num if not on windows
    if platform.system() != "Windows":
        if audio_device != '':
            temp_hw_num = audio_util.getSpeakerByName(
                audio_device.encode('utf-8'))
            if temp_hw_num != None:
                if robot_config.has_option('tts', 'speaker_num'):
                    robot_config.set('tts', 'speaker_num', str(temp_hw_num))
                else:
                    log.warn(
                        "controller.conf is out of date. Consider updating.")
                    robot_config.set('tts', 'hw_num', str(temp_hw_num))

    if robot_config.has_option('tts', 'speaker_num'):
        hw_num = robot_config.get('tts', 'speaker_num')
    else:
        log.warn("controller.conf is out of date. Consider updating.")
        hw_num = robot_config.get('tts', 'hw_num')

    if platform.system() != "Windows":
        volume(tts_volume)

    #import the appropriate tts handler module.
    log.debug("loading module tts/%s", type)
    if robot_config.getboolean('misc', 'custom_tts'):
        if os.path.exists('tts/tts_custom.py'):
            if (sys.version_info > (3, 0)):
                tts_module = importlib.import_module('tts.tts_custom')
            else:
                tts_module = __import__('tts.tts_custom',
                                        fromlist=['tts_custom'])
        else:
            log.info("Unable to find tts/tts_custom.py")
            if (sys.version_info > (3, 0)):
                tts_module = importlib.import_module('tts.' + type)
            else:
                tts_module = __import__("tts." + type, fromlist=[type])
    else:
        if (sys.version_info > (3, 0)):
            tts_module = importlib.import_module('tts.' + type)
        else:
            tts_module = __import__("tts." + type, fromlist=[type])

    #call the tts handlers setup function
    tts_module.setup(robot_config)
示例#3
0
def setup(robot_config):
    global type
    global tts_module
    global mute_anon
    global url_filter
    global hw_num
    global delay_tts
    global delay

    type = robot_config.get('tts', 'type')
    mute_anon = not robot_config.getboolean('tts', 'anon_tts')
    url_filter = robot_config.getboolean('tts', 'filter_url_tts')

    if robot_config.has_option('tts', 'delay_tts') and robot_config.has_option(
            'tts', 'delay'):
        delay_tts = robot_config.getboolean('tts', 'delay_tts')
        delay = robot_config.getint('tts', 'delay')

    if delay_tts and not robot_config.getboolean('messenger', 'enable'):
        log.error("Warning! delayed TTS requires messenger.")
        log.error("delayed TTS disabled.")
        delay_tts = False

    # get playback device hardware num from name.
    if robot_config.has_option('tts', 'speaker_device'):
        audio_device = robot_config.get('tts', 'speaker_device')
    else:
        log.warn("letsrobot.conf is out of date. Consider updating.")
        audio_device = robot_config.get('tts', 'audio_device')

    # convert the device to hw num if not on windows
    if platform.system() != "Windows":
        if audio_device != '':
            temp_hw_num = audio_util.getSpeakerByName(
                audio_device.encode('utf-8'))
            if temp_hw_num != None:
                if robot_config.has_option('tts', 'speaker_num'):
                    robot_config.set('tts', 'speaker_num', str(temp_hw_num))
                else:
                    log.warn(
                        "letsrobot.conf is out of date. Consider updating.")
                    robot_config.set('tts', 'hw_num', str(temp_hw_num))

    if robot_config.has_option('tts', 'speaker_num'):
        hw_num = robot_config.get('tts', 'speaker_num')
    else:
        log.warn("letsrobot.conf is out of date. Consider updating.")
        hw_num = robot_config.get('tts', 'hw_num')

    if type != 'none':
        # set volume level

        # tested for 3.5mm audio jack
        #if robot_config.getint('tts', 'tts_volume') > 50:
        #os.system("amixer set PCM -- -100")

        # tested for USB audio device
        os.system("amixer -c %s cset numid=3 %d%%" %
                  (hw_num, robot_config.getint('tts', 'tts_volume')))

    #import the appropriate tts handler module.
    log.debug("loading module tts/%s", type)
    if robot_config.getboolean('misc', 'custom_tts'):
        if os.path.exists('tts/tts_custom.py'):
            if (sys.version_info > (3, 0)):
                tts_module = importlib.import_module('tts.tts_custom')
            else:
                tts_module = __import__('tts.tts_custom',
                                        fromlist=['tts_custom'])
        else:
            log.info("Unable to find tts/tts_custom.py")
            if (sys.version_info > (3, 0)):
                tts_module = importlib.import_module('tts.' + type)
            else:
                tts_module = __import__("tts." + type, fromlist=[type])
    else:
        if (sys.version_info > (3, 0)):
            tts_module = importlib.import_module('tts.' + type)
        else:
            tts_module = __import__("tts." + type, fromlist=[type])

    #call the tts handlers setup function
    tts_module.setup(robot_config)