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 rospeex_core.sr.base import ThreadPool
00010 from sync_client import SyncClient
00011 from state import InitState
00012 
00013 
00014 logger = logging_util.get_logger(__name__)
00015 
00016 
00017 class StreamingClient(SyncClient):
00018     """ Audio Processor class """
00019     BASE_URL = 'http://rospeex.nict.go.jp/nauth/SocketServlet'
00020     SEND_THREAD_NUM = 2
00021 
00022     def __init__(self, language='ja', *args, **kwargs):
00023         super(StreamingClient, self).__init__()
00024         self._streaming_cb_lock = threading.Lock()
00025         self._streaming_cb_list = []
00026 
00027         # start session
00028         self._pool = ThreadPool(self.SEND_THREAD_NUM)
00029         self._session = Session(
00030             InitState(
00031                 self.BASE_URL,
00032                 language,
00033                 self._pool
00034             )
00035         )
00036         self._session.start()
00037         self._streaming_state = self._session.state()
00038 
00039     def support_streaming(self):
00040         """
00041         check support streaming
00042         @returns: True for support streaming / False for NOT support streaming
00043         """
00044         return True
00045 
00046     def set_streaming_config(self, language):
00047         """ set streaming config
00048         @param language:
00049         """
00050         state = InitState(self.BASE_URL, language, self._pool)
00051         self._session.set_next_state(state)
00052 
00053     def add_streaming_packet(self, packet_type, packet_data):
00054         """ add streaming packet
00055         @param packet_type:
00056         @type  packet_type: int
00057         @param packet_data:
00058         @param packet_data: str
00059         """
00060         self._session.add_packet(packet_type, packet_data)
00061 
00062     def register_streaming_cb(self, cb):
00063         """
00064         register streaming result callback
00065         @param cb:
00066         @type cb:
00067         """
00068         self._session.register_result_cb(cb)
00069 
00070     def unregister_streaming_cb(self, cb):
00071         """
00072         unregister streaming result callback
00073         @param cb:
00074         @type cb:
00075         """
00076         self._session.register_unresult_cb(cb)
00077 
00078     def join(self, timeout=None):
00079         """
00080         join streaming client
00081         @param timeout:
00082         @type timeout:
00083         """
00084         self._pool.end()
00085         self._session.join(timeout)


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