Exemple #1
0
def handle(text, mic, profile):
    """
    Change the voice I use
    """

    logging.info('Changing voice')
    mic.say('Let\'s change my voice')

    answer = get_answer(mic)

    if answer == 'ONE':
        new_tts_engine = tts.get_engine_by_slug('espeak-tts')
    elif answer == 'TWO':
        new_tts_engine = tts.get_engine_by_slug('festival-tts')
    elif answer == 'THREE':
        new_tts_engine = tts.get_engine_by_slug('pico-tts')
    else:
        new_tts_engine = tts.get_engine_by_slug('flite-tts')

    new_tts = new_tts_engine.get_instance()

    if answer == 'FOUR':
        new_tts.voice = 'awb'
    elif answer == 'FIVE':
        new_tts.voice = 'rms'
    elif answer == 'SIX':
        new_tts.voice = 'slt'
    elif answer == 'SEVEN':
        new_tts.voice = 'kal'
    elif answer == 'EIGHT':
        new_tts.voice = 'kal16'

    mic.say('Switching to voice {}'.format(answer.lower()))
    mic.setSpeaker(new_tts)
    mic.say('Okay, now I talk like this')
Exemple #2
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)
        # Read config
        config_file = os.path.abspath(os.path.join(jasperpath.LIB_PATH, 'profile.yml'))
        self._logger.debug("Trying to read config file: '%s'", config_file)
        with open(config_file, "r") as f:
            self.config = yaml.safe_load(f)

        try:
            api_key = self.config['keys']['GOOGLE_SPEECH']
        except KeyError:
            api_key = None

        try:
            stt_engine_type = self.config['stt_engine']
        except KeyError:
            stt_engine_type = "sphinx"
            self._logger.warning("stt_engine not specified in profile, defaulting to '%s'", stt_engine_type)

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning("tts_engine not specified in profile, defaulting to '%s'", tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Compile dictionary
        sentences, dictionary, languagemodel = [os.path.abspath(os.path.join(jasperpath.LIB_PATH, filename)) for filename in ("sentences.txt", "dictionary.dic", "languagemodel.lm")]
        vocabcompiler.compile(sentences, dictionary, languagemodel)

        # Initialize Mic
        self.mic = Mic(tts_engine_class(), stt.PocketSphinxSTT(), stt.newSTTEngine(stt_engine_type, api_key=api_key))
Exemple #3
0
    def __init__(self):

        self._logger = logging.getLogger(__name__)

	stt_engine_slug = client.jasperprofile.profile.get('stt_engine', 'sphinx')
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

	stt_passive_engine_slug = client.jasperprofile.profile.get('stt_passive_engine', stt_engine_slug)
        stt_passive_engine_class = stt.get_engine_by_slug(stt_passive_engine_slug)

        tts_engine_slug = client.jasperprofile.profile.get('tts_engine', tts.get_default_engine_slug())
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        active_stt_engine_instance = stt_engine_class.get_active_instance()
        if active_stt_engine_instance.has_mic()==True:
                passive_stt_engine_instance = active_stt_engine_instance
        else:
                passive_stt_engine_instance = stt_passive_engine_class.get_passive_instance()

        # Initialize Mic
        self.mic = Mic(tts_engine_class.get_instance(),
                       passive_stt_engine_instance,
                       active_stt_engine_instance)
                       #stt_passive_engine_class.get_passive_instance(),
                       #stt_engine_class.get_active_instance())

	if tts_engine_slug == 'festival-tts':	
		tts_engine_default_voice = client.jasperprofile.profile.get('tts_default_voice','')
		if tts_engine_default_voice:
			self.mic.set_tts_default_voice(tts_engine_default_voice)
		else:
			self._logger.warning("Profile does not contain a default voice for Festival." +
					     " Will use the Festival installation default")
Exemple #4
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)
        self.config = config.profile

        try:
            stt_engine_slug = self.config['stt_engine']
        except KeyError:
            stt_engine_slug = 'snowboy-stt'
            logger.warning(
                "stt_engine not specified in profile, defaulting " + "to '%s'",
                stt_engine_slug)
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        try:
            slug = self.config['stt_passive_engine']
            stt_passive_engine_class = stt.get_engine_by_slug(slug)
        except KeyError:
            stt_passive_engine_class = stt_engine_class

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning(
                "tts_engine not specified in profile, defaulting " + "to '%s'",
                tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(self.config, tts_engine_class.get_instance(),
                       stt_passive_engine_class.get_passive_instance(),
                       stt_engine_class.get_active_instance())
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        # Create config dir if it does not exist yet
        #ender: should create config file for the first run
        if not os.path.exists(dingdangpath.CONFIG_PATH):
            try:
                os.makedirs(dingdangpath.CONFIG_PATH)
            except OSError:
                self._logger.error("Could not create config dir: '%s'",
                                   dingdangpath.CONFIG_PATH,
                                   exc_info=True)
                raise

        # Check if config dir is writable
        if not os.access(dingdangpath.CONFIG_PATH, os.W_OK):
            self._logger.critical(
                "Config dir %s is not writable. Dingdang " +
                "won't work correctly.", dingdangpath.CONFIG_PATH)

        config_file = dingdangpath.config('profile.yml')
        #ender: Read config, get config informations
        self._logger.debug("Trying to read config file: '%s'", config_file)
        try:
            with open(config_file, "r") as f:
                self.config = yaml.safe_load(f)
        except OSError:
            self._logger.error("Can't open config file: '%s'", config_file)
            raise

        #ender: prepare STT. if not setup, use default sphinx
        try:
            stt_engine_slug = self.config['stt_engine']
        except KeyError:
            stt_engine_slug = 'sphinx'
            logger.warning(
                "stt_engine not specified in profile, defaulting " + "to '%s'",
                stt_engine_slug)
        #ender: create STT instance
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        try:
            slug = self.config['stt_passive_engine']
            stt_passive_engine_class = stt.get_engine_by_slug(slug)
        except KeyError:
            stt_passive_engine_class = stt_engine_class

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning(
                "tts_engine not specified in profile, defaulting " + "to '%s'",
                tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(self.config, tts_engine_class.get_instance(),
                       stt_passive_engine_class.get_passive_instance(),
                       stt_engine_class.get_active_instance())
Exemple #6
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        # Create config dir if it does not exist yet
        if not os.path.exists(jasperpath.CONFIG_PATH):
            try:
                os.makedirs(jasperpath.CONFIG_PATH)
            except OSError:
                self._logger.error("Could not create config dir: '%s'",
                                   jasperpath.CONFIG_PATH,
                                   exc_info=True)
                raise

        # Check if config dir is writable
        if not os.access(jasperpath.CONFIG_PATH, os.W_OK):
            self._logger.critical(
                "Config dir %s is not writable. Pocket companion " +
                "won't work correctly.", jasperpath.CONFIG_PATH)

        new_configfile = jasperpath.config('profile.yml')

        # Read config
        self._logger.debug("Trying to read config file: '%s'", new_configfile)
        try:
            with open(new_configfile, "r") as f:
                self.config = yaml.safe_load(f)
        except OSError:
            self._logger.error("Can't open config file: '%s'", new_configfile)
            raise

        try:
            stt_engine_slug = self.config['stt_engine']
        except KeyError:
            stt_engine_slug = 'sphinx'
            logger.warning(
                "stt_engine not specified in profile, defaulting " + "to '%s'",
                stt_engine_slug)
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        try:
            slug = self.config['stt_passive_engine']
            stt_passive_engine_class = stt.get_engine_by_slug(slug)
        except KeyError:
            stt_passive_engine_class = stt_engine_class

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning(
                "tts_engine not specified in profile, defaulting " + "to '%s'",
                tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(tts_engine_class.get_instance(), None,
                       stt_engine_class.get_active_instance())
Exemple #7
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        # Create config dir if it does not exist yet
        if not os.path.exists(dingdangpath.CONFIG_PATH):
            try:
                os.makedirs(dingdangpath.CONFIG_PATH)
            except OSError:
                self._logger.error("Could not create config dir: '%s'",
                                   dingdangpath.CONFIG_PATH, exc_info=True)
                raise

        # Check if config dir is writable
        if not os.access(dingdangpath.CONFIG_PATH, os.W_OK):
            self._logger.critical("Config dir %s is not writable. Dingdang " +
                                  "won't work correctly.",
                                  dingdangpath.CONFIG_PATH)

        config_file = dingdangpath.config('profile.yml')
        # Read config
        self._logger.debug("Trying to read config file: '%s'", config_file)
        try:
            with open(config_file, "r") as f:
                self.config = yaml.safe_load(f)
        except OSError:
            self._logger.error("Can't open config file: '%s'", config_file)
            raise

        try:
            stt_engine_slug = self.config['stt_engine']
        except KeyError:
            stt_engine_slug = 'sphinx'
            logger.warning("stt_engine not specified in profile, defaulting " +
                           "to '%s'", stt_engine_slug)
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        try:
            slug = self.config['stt_passive_engine']
            stt_passive_engine_class = stt.get_engine_by_slug(slug)
        except KeyError:
            stt_passive_engine_class = stt_engine_class

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning("tts_engine not specified in profile, defaulting " +
                           "to '%s'", tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(
            self.config,
            tts_engine_class.get_instance(),
            stt_passive_engine_class.get_passive_instance(),
            stt_engine_class.get_active_instance())
Exemple #8
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)
        config.init()

        stt_engine_slug = config.get('stt_engine', 'sphinx')
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        slug = config.get('stt_passive_engine', stt_engine_slug)
        stt_passive_engine_class = stt.get_engine_by_slug(slug)

        tts_engine_slug = config.get('tts_engine',
                                     tts.get_default_engine_slug())
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(tts_engine_class.get_instance(),
                       stt_passive_engine_class.get_passive_instance(),
                       stt_engine_class.get_active_instance())
Exemple #9
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)
        config.init()

        stt_engine_slug = config.get('stt_engine', 'sphinx')
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        slug = config.get('stt_passive_engine', stt_engine_slug)
        stt_passive_engine_class = stt.get_engine_by_slug(slug)

        tts_engine_slug = config.get('tts_engine',
                                     tts.get_default_engine_slug())
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(
            tts_engine_class.get_instance(),
            stt_passive_engine_class.get_passive_instance(),
            stt_engine_class.get_active_instance())
Exemple #10
0
    def __init__(self):

        self._logger = logging.getLogger(__name__)

        stt_engine_slug = client.jasperprofile.profile.get(
            'stt_engine', 'sphinx')
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        stt_passive_engine_slug = client.jasperprofile.profile.get(
            'stt_passive_engine', stt_engine_slug)
        stt_passive_engine_class = stt.get_engine_by_slug(
            stt_passive_engine_slug)

        tts_engine_slug = client.jasperprofile.profile.get(
            'tts_engine', tts.get_default_engine_slug())
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        active_stt_engine_instance = stt_engine_class.get_active_instance()
        if active_stt_engine_instance.has_mic() == True:
            passive_stt_engine_instance = active_stt_engine_instance
        else:
            passive_stt_engine_instance = stt_passive_engine_class.get_passive_instance(
            )

        # Initialize Mic
        self.mic = Mic(tts_engine_class.get_instance(),
                       passive_stt_engine_instance, active_stt_engine_instance)
        #stt_passive_engine_class.get_passive_instance(),
        #stt_engine_class.get_active_instance())

        if tts_engine_slug == 'festival-tts':
            tts_engine_default_voice = client.jasperprofile.profile.get(
                'tts_default_voice', '')
            if tts_engine_default_voice:
                self.mic.set_tts_default_voice(tts_engine_default_voice)
            else:
                self._logger.warning(
                    "Profile does not contain a default voice for Festival." +
                    " Will use the Festival installation default")
Exemple #11
0
 def testTTS(self):
     tts_engine = tts.get_engine_by_slug('dummy-tts')
     tts_instance = tts_engine()
     tts_instance.say('This is a test.')
Exemple #12
0
#!/usr/bin/env python2
Exemple #13
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        # Create config dir if it does not exist yet
        if not os.path.exists(nikitapath.CONFIG_PATH):
            try:
                os.makedirs(nikitapath.CONFIG_PATH)
            except OSError:
                self._logger.error("Could not create config dir: '%s'",
                                   nikitapath.CONFIG_PATH, exc_info=True)
                raise

        # Check if config dir is writable
        if not os.access(nikitapath.CONFIG_PATH, os.W_OK):
            self._logger.critical("Config dir %s is not writable. Nikita " +
                                  "won't work correctly.",
                                  nikitapath.CONFIG_PATH)

        # FIXME: For backwards compatibility, move old config file to newly
        #        created config dir
        old_configfile = os.path.join(nikitapath.LIB_PATH, 'profile.yml')
        new_configfile = nikitapath.config('profile.yml')
        if os.path.exists(old_configfile):
            if os.path.exists(new_configfile):
                self._logger.warning("Deprecated profile file found: '%s'. " +
                                     "Please remove it.", old_configfile)
            else:
                self._logger.warning("Deprecated profile file found: '%s'. " +
                                     "Trying to copy it to new location '%s'.",
                                     old_configfile, new_configfile)
                try:
                    shutil.copy2(old_configfile, new_configfile)
                except shutil.Error:
                    self._logger.error("Unable to copy config file. " +
                                       "Please copy it manually.",
                                       exc_info=True)
                    raise

        # Read config
        self._logger.debug("Trying to read config file: '%s'", new_configfile)
        try:
            with open(new_configfile, "r") as f:
                self.config = yaml.safe_load(f)
        except OSError:
            self._logger.error("Can't open config file: '%s'", new_configfile)
            raise

        # Reset the log level to what is configured in the profile
        try:
            logLevel = self.config['logging']
        except KeyError:
            logLevel = 'TRANSCRIPT'
        if not args.debug:
            logger.setLevel(logLevel)

        try:
            stt_engine_slug = self.config['stt_engine']
        except KeyError:
            stt_engine_slug = 'sphinx'
            logger.warning("stt_engine not specified in profile, defaulting " +
                           "to '%s'", stt_engine_slug)
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        try:
            slug = self.config['stt_passive_engine']
            stt_passive_engine_class = stt.get_engine_by_slug(slug)
        except KeyError:
            stt_passive_engine_class = stt_engine_class

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning("tts_engine not specified in profile, defaulting " +
                           "to '%s'", tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # connect to MySQL server
        db = MySQLdb.connect(host=self.config['MySQL']['server'],
                             port=3306, user=self.config['MySQL']['user'],
                             passwd=self.config['MySQL']['password'],
                             db="NIKITA")

        # Initialize Mic
        self.mic = Mic(tts_engine_class.get_instance(),
                       stt_passive_engine_class.get_passive_instance(),
                       stt_engine_class.get_active_instance(), db, self.config)
Exemple #14
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)
        
        # Create config dir if it does not exist yet
        if not os.path.exists(jasperpath.CONFIG_PATH):
            try:
                os.makedirs(jasperpath.CONFIG_PATH)
            except OSError:
                self._logger.error("Could not create config dir: '%s'", jasperpath.CONFIG_PATH, exc_info=True)
                raise

        # Check if config dir is writable
        if not os.access(jasperpath.CONFIG_PATH, os.W_OK):
            self._logger.critical("Config dir %s is not writable. Jasper won't work correctly.")

        # FIXME: For backwards compatibility, move old config file to newly created config dir
        old_configfile = os.path.join(jasperpath.LIB_PATH, 'profile.yml')
        new_configfile = jasperpath.config('profile.yml')
        if os.path.exists(old_configfile):
            if os.path.exists(new_configfile):
                self._logger.warning("Deprecated profile file found: '%s'. Please remove it.", old_configfile)
            else:
                self._logger.warning("Deprecated profile file found: '%s'. Trying to copy it to new location '%s'.", old_configfile, new_configfile)
                try:
                    shutil.copy2(old_configfile, new_configfile)
                except shutil.Error:
                    self._logger.error("Unable to copy config file. Please copy it manually.", exc_info=True)
                    raise

        # Read config
        self._logger.debug("Trying to read config file: '%s'", new_configfile)
        try:
            with open(new_configfile, "r") as f:
                self.config = yaml.safe_load(f)
        except OSError:
            self._logger.error("Can't open config file: '%s'", new_configfile)
            raise

        try:
            api_key = self.config['keys']['GOOGLE_SPEECH']
        except KeyError:
            api_key = None

        try:
            stt_engine_type = self.config['stt_engine']
        except KeyError:
            stt_engine_type = "sphinx"
            self._logger.warning("stt_engine not specified in profile, defaulting to '%s'", stt_engine_type)

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning("tts_engine not specified in profile, defaulting to '%s'", tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Compile dictionary
        sentences, dictionary, languagemodel = [jasperpath.config(filename) for filename in ("sentences.txt", "dictionary.dic", "languagemodel.lm")]
        vocabcompiler.compile(sentences, dictionary, languagemodel)

        # Initialize Mic
        self.mic = Mic(tts_engine_class(), stt.PocketSphinxSTT(), stt.newSTTEngine(stt_engine_type, api_key=api_key))
def getNewProfile(mic, profile):
	
	#This line bug !
	mic.say('Who are you?')
	input = raw_input("Your name : ")
	
	if input=='':
		profile_file='profile.yml'
	else:
		profile_file='profile-'+input+'.yml'
	
	mic.say('Hello '+input+" . You're the new user now" )
	
	#TODO replace by directly reading the config file and changing the var profile 
	#argument = list()
	#argument.append(sys.argv[0])
	#for arg in sys.argv[1:]:
#		argument.append(arg)
	
	logger = logging.getLogger(__name__)

	# FIXME: For backwards compatibility, move old config file to newly
	#        created config dir
	old_configfile = os.path.join(jasperpath.LIB_PATH, profile_file)
	new_configfile = jasperpath.config(profile_file)
	if os.path.exists(old_configfile):
		if os.path.exists(new_configfile):
			logger.warning("Deprecated profile file found: '%s'. " +
									"Please remove it.", old_configfile)
		else:
			logger.warning("Deprecated profile file found: '%s'. " +
									"Trying to copy it to new location '%s'.",
									old_configfile, new_configfile)
			try:
				shutil.copy2(old_configfile, new_configfile)
			except shutil.Error:
				logger.error("Unable to copy config file. " +
									"Please copy it manually.",
									exc_info=True)
				raise

	# Read config
	logger.debug("Trying to read config file: '%s'", new_configfile)
	try:
		with open(new_configfile, "r") as f:
			#Where the magic is. Clear the dict and then update it
			profile.clear()
			profile.update(yaml.safe_load(f))
	except OSError:
		logger.error("Can't open config file: '%s'", new_configfile)
		raise


	try:
		api_key = profile['keys']['GOOGLE_SPEECH']
	except KeyError:
		api_key = None

	try:
		stt_engine_type = profile['stt_engine']
	except KeyError:
		stt_engine_type = "sphinx"
		logger.warning("stt_engine not specified in profile, " +
								"defaulting to '%s'", stt_engine_type)

	try:
		tts_engine_slug = profile['tts_engine']
	except KeyError:
		tts_engine_slug = tts.get_default_engine_slug()
		logger.warning("tts_engine not specified in profile, defaulting " +
						"to '%s'", tts_engine_slug)
	tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

	#TODO To test !
	flag=0
	for arg in sys.argv[1:]:
		if(arg == '--local'):
			from client.local_mic import Mic
			flag=1
	if flag==0:
		from client.mic import Mic

	# Initialize Mic
	mic = Mic(tts_engine_class(),
					stt.PocketSphinxSTT(**stt.PocketSphinxSTT.get_config()),
					stt.newSTTEngine(stt_engine_type, api_key=api_key))
Exemple #16
0
    ENVIRON["api_url"] = getConfig(cfg_general,
                                   "General_api_url")  #API root entry point
    ENVIRON["api_token"] = getConfig(cfg_general,
                                     "General_api_token")  #token for access
    ENVIRON["api_login"] = getConfig(cfg_general,
                                     "General_api_login")  #subscriber login
    ENVIRON["devicename"] = getConfig(
        cfg_general, "General_devicename"
    )  #Identity of this device (eg. Doorbell, Home Assistant, etc.)

    #setup queue shared across functions
    SENSORQ = Queue()

    # Setup Text to Speech instance based on config
    if isConfig:
        tts_engine_class = tts.get_engine_by_slug(
            cfg_general["General_tts_api"])
    else:
        tts_engine_class = tts.get_engine_by_slug(
            tts.get_default_engine_slug())

    # Setup Speech to Text and MIC based on config and internet availability
    if isConfig and isWWWeb:
        stt_engine = stt.robotAI_stt(ENVIRON)
        MIC = mic.Mic(tts_engine_class.get_instance(), stt_engine, ENVIRON)
    else:
        MIC = mic.Mic(tts_engine_class.get_instance(), None, ENVIRON)

    # Brain is used to handle jobs that are taken from the SENSORQ
    BRAIN = brain.brain(MIC, ENVIRON)

    # Check if a valid licence exists for the roboAT online APIs
Exemple #17
0
import os
import sys
import shutil
import logging
import Pyro4
import time
import cercaIP
import yaml
import argparse
from client import tts, stt, jasperpath, diagnose
from client.conversation import Conversation
from client.mic import Mic

stt_engine_class = stt.get_engine_by_slug('sphinx')
tts_engine_class = tts.get_engine_by_slug('espeak-tts')

stt_engine_class0 = stt.get_engine_by_slug('witaiE')
stt_engine_class1 = stt.get_engine_by_slug('witaiC')
stt_engine_class2 = stt.get_engine_by_slug('googleE')
stt_engine_class3 = stt.get_engine_by_slug('googleC')
stt_engine_class4 = stt.get_engine_by_slug('attE')
stt_engine_class5 = stt.get_engine_by_slug('attC')

mic0 = Mic(tts_engine_class.get_instance(),stt_engine_class.get_passive_instance(),stt_engine_class0.get_active_instance())
mic1 = Mic(tts_engine_class.get_instance(),stt_engine_class.get_passive_instance(),stt_engine_class1.get_active_instance())
mic2 = Mic(tts_engine_class.get_instance(),stt_engine_class.get_passive_instance(),stt_engine_class2.get_active_instance())
mic3 = Mic(tts_engine_class.get_instance(),stt_engine_class.get_passive_instance(),stt_engine_class3.get_active_instance())
mic4 = Mic(tts_engine_class.get_instance(),stt_engine_class.get_passive_instance(),stt_engine_class4.get_active_instance())
mic5 = Mic(tts_engine_class.get_instance(),stt_engine_class.get_passive_instance(),stt_engine_class5.get_active_instance())

class mic_remot():
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        # Create config dir if it does not exist yet
        if not os.path.exists(jasperpath.CONFIG_PATH):
            try:
                os.makedirs(jasperpath.CONFIG_PATH)
            except OSError:
                self._logger.error("Could not create config dir: '%s'",
                                   jasperpath.CONFIG_PATH, exc_info=True)
                raise

        # Check if config dir is writable
        if not os.access(jasperpath.CONFIG_PATH, os.W_OK):
            self._logger.critical("Config dir %s is not writable. Jasper " +
                                  "won't work correctly.",
                                  jasperpath.CONFIG_PATH)

        # FIXME: For backwards compatibility, move old config file to newly
        #        created config dir
        old_configfile = os.path.join(jasperpath.LIB_PATH, 'profile.yml')
        new_configfile = jasperpath.config('profile.yml')
        if os.path.exists(old_configfile):
            if os.path.exists(new_configfile):
                self._logger.warning("Deprecated profile file found: '%s'. " +
                                     "Please remove it.", old_configfile)
            else:
                self._logger.warning("Deprecated profile file found: '%s'. " +
                                     "Trying to copy it to new location '%s'.",
                                     old_configfile, new_configfile)
                try:
                    shutil.copy2(old_configfile, new_configfile)
                except shutil.Error:
                    self._logger.error("Unable to copy config file. " +
                                       "Please copy it manually.",
                                       exc_info=True)
                    raise

        # Read config
        self._logger.debug("Trying to read config file: '%s'", new_configfile)
        try:
            with open(new_configfile, "r") as f:
                self.config = yaml.safe_load(f)
        except OSError:
            self._logger.error("Can't open config file: '%s'", new_configfile)
            raise

        try:
            stt_engine_slug = self.config['stt_engine']
        except KeyError:
            stt_engine_slug = 'sphinx'
            logger.warning("stt_engine not specified in profile, defaulting " +
                           "to '%s'", stt_engine_slug)
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        try:
            slug = self.config['stt_passive_engine']
            stt_passive_engine_class = stt.get_engine_by_slug(slug)
        except KeyError:
            stt_passive_engine_class = stt_engine_class

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning("tts_engine not specified in profile, defaulting " +
                           "to '%s'", tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(tts_engine_class.get_instance(),
                       stt_passive_engine_class.get_passive_instance(),
                       stt_engine_class.get_active_instance())
Exemple #19
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        # Create config dir if it does not exist yet
        if not os.path.exists(jasperpath.CONFIG_PATH):
            try:
                os.makedirs(jasperpath.CONFIG_PATH)
            except OSError:
                self._logger.error("Could not create config dir: '%s'",
                                   jasperpath.CONFIG_PATH, exc_info=True)
                raise

        # Check if config dir is writable
        if not os.access(jasperpath.CONFIG_PATH, os.W_OK):
            self._logger.critical("Config dir %s is not writable. Jasper " +
                                  "won't work correctly.",
                                  jasperpath.CONFIG_PATH)

        # FIXME: For backwards compatibility, move old config file to newly
        #        created config dir
        old_configfile = os.path.join(jasperpath.LIB_PATH, 'profile.yml')
        new_configfile = jasperpath.config('profile.yml')
        if os.path.exists(old_configfile):
            if os.path.exists(new_configfile):
                self._logger.warning("Deprecated profile file found: '%s'. " +
                                     "Please remove it.", old_configfile)
            else:
                self._logger.warning("Deprecated profile file found: '%s'. " +
                                     "Trying to copy it to new location '%s'.",
                                     old_configfile, new_configfile)
                try:
                    shutil.copy2(old_configfile, new_configfile)
                except shutil.Error:
                    self._logger.error("Unable to copy config file. " +
                                       "Please copy it manually.",
                                       exc_info=True)
                    raise

        # Read config
        self._logger.debug("Trying to read config file: '%s'", new_configfile)
        try:
            with open(new_configfile, "r") as f:
                self.config = yaml.safe_load(f)
        except OSError:
            self._logger.error("Can't open config file: '%s'", new_configfile)
            raise

        try:
            stt_engine_slug = self.config['stt_engine']
        except KeyError:
            stt_engine_slug = 'sphinx'
            logger.warning("stt_engine not specified in profile, defaulting " +
                           "to '%s'", stt_engine_slug)
        stt_engine_class = stt.get_engine_by_slug(stt_engine_slug)

        try:
            slug = self.config['stt_passive_engine']
            stt_passive_engine_class = stt.get_engine_by_slug(slug)
        except KeyError:
            stt_passive_engine_class = stt_engine_class

        try:
            tts_engine_slug = self.config['tts_engine']
        except KeyError:
            tts_engine_slug = tts.get_default_engine_slug()
            logger.warning("tts_engine not specified in profile, defaulting " +
                           "to '%s'", tts_engine_slug)
        tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

        # Initialize Mic
        self.mic = Mic(tts_engine_class.get_instance(),
                       stt_passive_engine_class.get_passive_instance(),
                       stt_engine_class.get_active_instance())
Exemple #20
0
def getNewProfile(mic, profile):

    #This line bug !
    mic.say('Who are you?')
    input = raw_input("Your name : ")

    if input == '':
        profile_file = 'profile.yml'
    else:
        profile_file = 'profile-' + input + '.yml'

    mic.say('Hello ' + input + " . You're the new user now")

    #TODO replace by directly reading the config file and changing the var profile
    #argument = list()
    #argument.append(sys.argv[0])
    #for arg in sys.argv[1:]:
    #		argument.append(arg)

    logger = logging.getLogger(__name__)

    # FIXME: For backwards compatibility, move old config file to newly
    #        created config dir
    old_configfile = os.path.join(jasperpath.LIB_PATH, profile_file)
    new_configfile = jasperpath.config(profile_file)
    if os.path.exists(old_configfile):
        if os.path.exists(new_configfile):
            logger.warning(
                "Deprecated profile file found: '%s'. " + "Please remove it.",
                old_configfile)
        else:
            logger.warning(
                "Deprecated profile file found: '%s'. " +
                "Trying to copy it to new location '%s'.", old_configfile,
                new_configfile)
            try:
                shutil.copy2(old_configfile, new_configfile)
            except shutil.Error:
                logger.error("Unable to copy config file. " +
                             "Please copy it manually.",
                             exc_info=True)
                raise

    # Read config
    logger.debug("Trying to read config file: '%s'", new_configfile)
    try:
        with open(new_configfile, "r") as f:
            #Where the magic is. Clear the dict and then update it
            profile.clear()
            profile.update(yaml.safe_load(f))
    except OSError:
        logger.error("Can't open config file: '%s'", new_configfile)
        raise

    try:
        api_key = profile['keys']['GOOGLE_SPEECH']
    except KeyError:
        api_key = None

    try:
        stt_engine_type = profile['stt_engine']
    except KeyError:
        stt_engine_type = "sphinx"
        logger.warning(
            "stt_engine not specified in profile, " + "defaulting to '%s'",
            stt_engine_type)

    try:
        tts_engine_slug = profile['tts_engine']
    except KeyError:
        tts_engine_slug = tts.get_default_engine_slug()
        logger.warning(
            "tts_engine not specified in profile, defaulting " + "to '%s'",
            tts_engine_slug)
    tts_engine_class = tts.get_engine_by_slug(tts_engine_slug)

    #TODO To test !
    flag = 0
    for arg in sys.argv[1:]:
        if (arg == '--local'):
            from client.local_mic import Mic
            flag = 1
    if flag == 0:
        from client.mic import Mic

    # Initialize Mic
    mic = Mic(tts_engine_class(),
              stt.PocketSphinxSTT(**stt.PocketSphinxSTT.get_config()),
              stt.newSTTEngine(stt_engine_type, api_key=api_key))