streaming_client.py
Go to the documentation of this file.
00001 #!-*- coding: utf-8 -*-
00002 
00003 # python libraries
00004 import threading
00005 
00006 # local libraries
00007 from rospeex_core import logging_util
00008 from rospeex_core.sr.base import Session
00009 from sync_client import SyncClient
00010 from state import InitState
00011 
00012 
00013 logger = logging_util.get_logger(__name__)
00014 
00015 
00016 class StreamingClient(SyncClient):
00017     """ Audio Processor class """
00018 
00019     def __init__(self, google_api_key=None, language='ja', *args, **kwargs):
00020         super(StreamingClient, self).__init__(google_api_key, *args, **kwargs)
00021         self._streaming_cb_lock = threading.Lock()
00022         self._streaming_cb_list = []
00023 
00024         self._language = language
00025 
00026         # start session
00027         self._session = Session(
00028             InitState(self._api_key, self._language)
00029         )
00030         self._session.start()
00031         self._streaming_state = self._session.state()
00032 
00033     def support_streaming(self):
00034         """
00035         check support streaming
00036         @returns: True for support streaming / False for NOT support streaming
00037         """
00038         return True
00039 
00040     def set_streaming_config(self, language):
00041         """ set streaming config
00042 
00043         @param language:
00044         """
00045         state = InitState(self._api_key, language)
00046         self._session.set_next_state(state)
00047 
00048     def add_streaming_packet(self, packet_type, packet_data):
00049         """ add streaming packet
00050         @param packet_type:
00051         @type  packet_type: int
00052         @param packet_data:
00053         @param packet_data: str
00054         """
00055         self._session.add_packet(packet_type, packet_data)
00056 
00057     def register_streaming_cb(self, cb):
00058         """
00059         register streaming result callback
00060         @param cb:
00061         @type cb:
00062         """
00063         self._session.register_result_cb(cb)
00064 
00065     def unregister_streaming_cb(self, cb):
00066         """
00067         unregister streaming result callback
00068         @param cb:
00069         @type cb:
00070         """
00071         self._session.register_unresult_cb(cb)
00072 
00073     def join(self, timeout=None):
00074         """
00075         join streaming client
00076         @param timeout:
00077         @type timeout:
00078         """
00079         self._session.join(timeout)


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