def run(): header_adder_interceptor = header_manipulator_client_interceptor.header_adder_interceptor( 'one-time-password', '42') header_validator1 = header_manipulator_client_interceptor.header_adder_interceptor( 'one-time-password', '43') channel = grpc.insecure_channel('localhost:50051') channel = grpc.intercept_channel(channel, header_adder_interceptor, header_validator1) stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def get_result(self, file_path): """ 通过文件路径获取最终解码结果的迭代器 :param file_path: :return: response的迭代 """ header_adder_interceptor = header_manipulator_client_interceptor.header_adder_interceptor( 'audio_meta', base64.b64encode(self.request.SerializeToString())) # 添加ca认证 # with open( # '/path/of/xxx.crt', # 'rb') as f: # creds = grpc.ssl_channel_credentials(f.read()) # with grpc.secure_channel(self.host, creds) as channel: with grpc.insecure_channel(target=self.host, options=[ ('grpc.keepalive_timeout_ms', 1000000), ]) as channel: intercept_channel = grpc.intercept_channel( channel, header_adder_interceptor) stub = audio_streaming_pb2_grpc.AsrServiceStub(intercept_channel) responses = stub.send(self.generate_file_stream(file_path), timeout=100000) for response in responses: yield response
def get_result(self, file_path): header_adder_interceptor = header_manipulator_client_interceptor.header_adder_interceptor( 'audio_meta', base64.b64encode(self.request.SerializeToString())) with grpc.insecure_channel(self.host) as channel: intercept_channel = grpc.intercept_channel( channel, header_adder_interceptor) stub = audio_streaming_pb2_grpc.AsrServiceStub(intercept_channel) responses = stub.send(self.generate_file_stream(file_path)) for response in responses: yield response
def main(): # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. header_adder_interceptor = header_manipulator_client_interceptor.header_adder_interceptor( "api_key", "42" ) with grpc.insecure_channel("localhost:50051") as channel: intercept_channel = grpc.intercept_channel(channel, header_adder_interceptor) stub = authentication_example_pb2_grpc.HelloServiceStub(intercept_channel) print("-------------- SayHello --------------") say_hello(stub)
def run(): header_adder_interceptor = header_manipulator_client_interceptor.header_adder_interceptor( 'one-time-password', '42') # NOTE(gRPC Python Team): .close() is possible on a channel and should be # used in circumstances in which the with statement does not fit the needs # of the code. with grpc.insecure_channel('localhost:50051') as channel: intercept_channel = grpc.intercept_channel(channel, header_adder_interceptor) stub = helloworld_pb2_grpc.GreeterStub(intercept_channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='you')) print("Greeter client received: " + response.message)
def run(): init_request = get_init_request() header_adder_interceptor = header_manipulator_client_interceptor.header_adder_interceptor( 'audio_meta', base64.b64encode(init_request.SerializeToString())) with grpc.insecure_channel(basic_conf['server']) as channel: intercept_channel = grpc.intercept_channel(channel, header_adder_interceptor) stub = audio_streaming_pb2_grpc.AsrServiceStub(intercept_channel) responses = stub.send(generate_file_stream()) for response in responses: print("start_time\tend_time\tresult") print(response.start_time + "\t" + response.end_time + "\t" + response.result) print(response.start_time + "\t" + response.end_time + "\t" + response.result + "response end!")
def get_result_by_stream(self, file_steam): """ 通过音频流获取解码结果的迭代器 :param file_steam: 字节流 :return: response结果的迭代 """ header_adder_interceptor = header_manipulator_client_interceptor.header_adder_interceptor( 'audio_meta', base64.b64encode(self.request.SerializeToString())) with grpc.insecure_channel(self.host) as channel: intercept_channel = grpc.intercept_channel( channel, header_adder_interceptor) stub = audio_streaming_pb2_grpc.AsrServiceStub(intercept_channel) responses = stub.send(file_steam) for response in responses: yield response
def setUpClass(cls): channel = grpc.insecure_channel('localhost:50051') interceptor = header_adder_interceptor(METADATA) cls._intercept_channel = grpc.intercept_channel(channel, interceptor) cls._stub = TypesDemoServiceStub(cls._intercept_channel)