factory.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 
00003 # import library
00004 from rospeex_core import exceptions as ext
00005 from rospeex_core import logging_util
00006 from rospeex_core.sr import nict
00007 from rospeex_core.sr import google
00008 from rospeex_core.sr import microsoft
00009 
00010 # create logger
00011 logger = logging_util.get_logger(__name__)
00012 
00013 
00014 class SREngine(object):
00015     """ Engine class """
00016     NICT = 'nict'
00017     GOOGLE = 'google'
00018     MICROSOFT = 'microsoft'
00019 
00020 
00021 class SpeechRecognitionFactory(object):
00022     """
00023     SpeechRecognitionFactory class
00024     """
00025     ENGINE_FACTORY = {
00026         'google': google.Client,
00027         'nict': nict.Client,
00028         'microsoft': microsoft.Client,
00029     }
00030 
00031     @classmethod
00032     def create(cls, engine, *args, **kwargs):
00033         """
00034         create speech recognition client
00035         @param engine: speech recognition engine name (NICT|GOOGLE|MICROSOFT)
00036         @type  engine: str
00037         @param args:
00038         @param kwargs:
00039         @raise SpeechRecognitionException:
00040         """
00041         if engine in cls.ENGINE_FACTORY.keys():
00042             return cls.ENGINE_FACTORY[engine](*args, **kwargs)
00043 
00044         else:
00045             msg = 'target client [{engine}] is not found.'\
00046                   'Except: {engine_list}'.format(
00047                         engine=engine,
00048                         engine_list=cls.ENGINE_FACTORY.keys()
00049                     )
00050             raise ext.SpeechRecognitionException(msg)


rospeex_core
Author(s): Komei Sugiura
autogenerated on Thu Jun 6 2019 18:53:10