Exemple #1
0
 def generate_stream_request(self, file_stream):
     """
     通过音频流产生request对象
     :param file_stream: 字节流
     :return: request对象
     """
     return audio_streaming_pb2.AudioFragmentRequest(audio_data=file_stream)
Exemple #2
0
def generate_file_stream():
    file = open(
        basic_conf[
            'audio_file_path'],
        "r")
    content = file.read(1024)
    while len(content) > 0:
        yield audio_streaming_pb2.AudioFragmentRequest(audio_data=content)
        content = file.read(1024)
    file.close()
Exemple #3
0
 def generate_file_stream(self, file_path):
     if not os.path.exists(file_path):
         logging.info("%s file is not exist, please check it!", file_path)
         os._exit(-1)
         # raise IOError("%s file is not exist, please check it!" % file_path)
     file = open(file_path, "r")
     content = file.read(2560)
     while len(content) > 0:
         yield audio_streaming_pb2.AudioFragmentRequest(audio_data=content)
         content = file.read(2560)
     file.close()
Exemple #4
0
 def generate_file_stream(self, file_path):
     """
     从音频文件中读取流
     :param file_path: 音频文件路径
     :return: 文件流的迭代
     """
     if not os.path.exists(file_path):
         logging.info("%s file is not exist, please check it!", file_path)
         os._exit(-1)
     file = open(file_path, "r")
     content = file.read(self.send_package_size)
     while len(content) > 0:
         yield audio_streaming_pb2.AudioFragmentRequest(audio_data=content)
         content = file.read(self.send_package_size)
     file.close()