Exemplo n.º 1
0
    def special_mode(self, name, phrases):
        plugin_info = self.plugins.get_plugin(self.special_stt_slug,
                                              category='stt')
        plugin_config = profile.get_profile()

        original_stt_engine = self.active_stt_engine

        # If the special_mode engine is not specifically set,
        # copy the settings from the active stt engine.
        try:
            mode_stt_engine = plugin_info.plugin_class(name, phrases,
                                                       plugin_info,
                                                       plugin_config)
            if (profile.check_profile_var_exists(['special_stt'])):
                if (profile.check_profile_var_exists(
                    ['special_stt', 'samplerate'])):
                    mode_stt_engine._samplerate = int(
                        profile.get_profile_var(['special_stt', 'samplerate']))
                if (profile.check_profile_var_exists(
                    ['special_stt', 'volume_normalization'])):
                    mode_stt_engine._volume_normalization = float(
                        profile.get_profile_var(
                            ['special_stt', 'volume_normalization']))
            else:
                mode_stt_engine._samplerate = original_stt_engine._samplerate
                mode_stt_engine._volume_normalization = original_stt_engine._volume_normalization
            self.active_stt_engine = mode_stt_engine
            yield
        finally:
            self.active_stt_engine = original_stt_engine
Exemplo n.º 2
0
class TestPatchedG2P(unittest.TestCase):
    def setUp(self):
        self.g2pconv = g2p.PhonetisaurusG2P(
            'phonetisaurus-g2pfst',
            'dummy_fst_model.fst',
            nbest=3
        )

    @unittest.skipIf(
        not profile.check_profile_var_exists(
            ['pocketsphinx']
        ),
        "Pocketsphinx not configured"
    )
    def testTranslateWord(self):
        with mock.patch(
            'subprocess.Popen',
            return_value=DummyProc()
        ):
            for word in WORDS:
                self.assertIn(word, self.g2pconv.translate(word).keys())

    def testTranslateWords(self):
        with mock.patch(
            'subprocess.Popen',
            return_value=DummyProc()
        ):
            results = self.g2pconv.translate(WORDS).keys()
            for word in WORDS:
                self.assertIn(word, results)
Exemplo n.º 3
0
    def setUp(self):
        self.naomi_clip = paths.data('audio', 'naomi.wav')
        self.time_clip = paths.data('audio', 'time.wav')

        # google_env_var = "GOOGLE_APPLICATION_CREDENTIALS"
        google_env_var = google.google_env_var
        if (google_env_var in os.environ):
            credentials_json = os.getenv(google_env_var)
        elif profile.check_profile_var_exists(["google", "credentials_json"]):
            credentials_json = profile.get_profile_var(
                ["google", "credentials_json"])
        else:
            self.skipTest("Please set " + google_env_var)
        if (not os.path.isfile(os.path.expanduser(credentials_json))):
            self.skiptest(
                "Credentials file {} does not exist".format(credentials_json))

        try:
            self.passive_stt_engine = testutils.get_plugin_instance(
                google.GoogleSTTPlugin, 'unittest-passive', ['NAOMI'])
            self.active_stt_engine = testutils.get_plugin_instance(
                google.GoogleSTTPlugin, 'unittest-active', ['TIME'])
        except ImportError:
            self.skipTest("Google STT not installed!")
Exemplo n.º 4
0
 def detect_plugins(self, category=None):
     # Set a flag to let ourselves know if we
     # detected any new plugins this launch,
     # so we can save the changes to the profile.
     save_profile = False
     for plugin_dir in self._plugin_dirs:
         for root, dirs, files in os.walk(plugin_dir, topdown=True):
             for name in files:
                 if name != self._info_fname:
                     continue
                 current_category = os.path.split(root[len(plugin_dir) +
                                                       1:])[0]
                 if current_category == (current_category
                                         if category is None else category):
                     cp = parse_info_file(os.path.join(root, name))
                     if not profile.check_profile_var_exists([
                             'plugins', current_category,
                             cp['Plugin']['name']
                     ]):
                         profile.set_profile_var([
                             'plugins', current_category,
                             cp['Plugin']['name']
                         ], 'Enabled')
                         save_profile = True
                     self._logger.debug(
                         "Found plugin candidate at: {}".format(root))
                     if (profile.get_profile_flag([
                             'plugins', current_category,
                             cp['Plugin']['name']
                     ], False)):
                         try:
                             plugin_info = self.parse_plugin(root)
                         except Exception as e:
                             reason = ''
                             if hasattr(e, 'strerror') and e.strerror:
                                 reason = e.strerror
                                 if hasattr(e, 'errno') and e.errno:
                                     reason += ' [Errno %d]' % e.errno
                             elif hasattr(e, 'message'):
                                 reason = e.message
                             elif hasattr(e, 'msg'):
                                 reason = e.msg
                             if not reason:
                                 reason = 'Unknown'
                             self._logger.warning(
                                 "Plugin at '{}' skipped! (Reason: {})".
                                 format(root, reason),
                                 exc_info=True)
                         else:
                             if plugin_info.name in self._plugins:
                                 self._logger.warning(
                                     "Duplicate plugin: {}".format(
                                         plugin_info.name))
                             else:
                                 self._plugins[
                                     plugin_info.name] = plugin_info
                                 self._logger.debug(
                                     "Found valid plugin: {} {}".format(
                                         plugin_info.name,
                                         plugin_info.version))
                     else:
                         self._logger.debug("{} plugin {} disabled".format(
                             current_category, cp['Plugin']['name']))
     if (save_profile):
         profile.save_profile()
Exemplo n.º 5
0
 def settings(self):
     self.get_location_data()
     _ = self.gettext
     return OrderedDict([
         (('wwis_weather', 'country'), {
             'type':
             'listbox',
             'title':
             _('Please select your country from the list'),
             'description':
             "".join([
                 _('This value is being used to help locate your Area ID, which will be used to provide weather information'
                   )
             ]),
             'options':
             self.get_countries
         }),
         (('wwis_weather', 'region'), {
             'type':
             'listbox',
             'title':
             _('Please select your region or city from the list'),
             'description':
             _('Please select your region or city from the list, which will be used to provide weather information'
               ),
             'options':
             self.get_regions,
             'active':
             lambda: True if profile.check_profile_var_exists([
                 'wwis_weather', 'country'
             ]) and len(profile.get_profile_var(["wwis_weather", "country"])
                        ) > 0 else False
         }),
         (
             ('wwis_weather', 'city'),
             {
                 'type':
                 'listbox',
                 'title':
                 _('Please select your city from the list'),
                 'description':
                 _('Please select your city from the list. This will be used as the default location when providing weather information'
                   ),
                 'options':
                 self.get_cities,
                 # This is only active if the currently selected region is a dictionary and not a city
                 # 'active': lambda: True if isinstance(self.locations[profile.get_profile_var(["wwis_weather", "country"])][profile.get_profile_var(["wwis_weather", "region"])], dict) else False
                 'active':
                 self.city_isactive
             }),
         (('wwis_weather', 'temperature'), {
             'type':
             'listbox',
             'title':
             _("Would you prefer weather in Celcius or Fahrenheit?"),
             'description':
             _("Allows you to receive your weather forecast in either Celcius or Fahrenheit"
               ),
             'options': ['Celcius', 'Fahrenheit'],
             'active':
             lambda: True if profile.check_profile_var_exists([
                 'wwis_weather', 'country'
             ]) and len(profile.get_profile_var(["wwis_weather", "country"])
                        ) > 0 else False,
             'default':
             'Fahrenheit'
         })
     ])