huangmingming
2023-01-29 15fd6cdf1ac6737d92ae88a9147c0f6f7044e0ad
fix client, add pb file
1个文件已修改
5个文件已添加
116 ■■■■■ 已修改文件
funasr/runtime/python/grpc/__pycache__/grpc_client.cpython-37.pyc 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/python/grpc/__pycache__/paraformer_pb2.cpython-37.pyc 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/python/grpc/__pycache__/paraformer_pb2_grpc.cpython-37.pyc 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/python/grpc/grpc_main_client_mic.py 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/python/grpc/paraformer_pb2.py 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/python/grpc/paraformer_pb2_grpc.py 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
funasr/runtime/python/grpc/__pycache__/grpc_client.cpython-37.pyc
Binary files differ
funasr/runtime/python/grpc/__pycache__/paraformer_pb2.cpython-37.pyc
Binary files differ
funasr/runtime/python/grpc/__pycache__/paraformer_pb2_grpc.cpython-37.pyc
Binary files differ
funasr/runtime/python/grpc/grpc_main_client_mic.py
@@ -10,15 +10,16 @@
import time
import asyncio
import datetime
import argparse
SPEAKING = False
stub = None
asr_user = None
language = None
#SPEAKING = False
#stub = None
#asr_user = None
#language = None
async def deal_chunk(sig_mic):
    
    global stub,SPEAKING,asr_user,language
    global stub,SPEAKING,asr_user,language,sample_rate
    sig = np.frombuffer(sig_mic, 'int16')
    if vad.is_speech(sig.tobytes(), sample_rate): #speaking
        SPEAKING = True
@@ -38,6 +39,7 @@
                resp = response.next() #TODO, blocking operation may leads to miss some audio clips. C++ multi-threading is preferred.
                if "finish" == resp.action:        
                    end_time = int(round(time.time() * 1000))
                    print(resp.action)
                    print (json.loads(resp.sentence))
                    #print ("silence, end_time: %d " % end_time)
                    print ("delay in ms: %d " % (end_time - begin_time))
@@ -97,10 +99,12 @@
    args = parser.parse_args()
    
    global SPEAKING,asr_user,language
    SPEAKING = False
    asr_user = args.asr_user
    asr_user = args.user_allowed
    sample_rate = args.sample_rate
    language = 'zh-CN'  
    vad = webrtcvad.Vad()
    vad.set_mode(1)
@@ -116,7 +120,7 @@
                frames_per_buffer=args.mic_chunk)
                
    print("* recording")
    asyncio.run(record(args.host,args.port,args.sample_rate,args.mic_chunk,args.record_seconds,args.asr_user,args.language))
    asyncio.run(record(args.host,args.port,args.sample_rate,args.mic_chunk,args.record_seconds,args.user_allowed,language))
    stream.stop_stream()
    stream.close()
    p.terminate()
funasr/runtime/python/grpc/paraformer_pb2.py
New file
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# source: paraformer.proto
"""Generated protocol buffer code."""
from google.protobuf.internal import builder as _builder
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10paraformer.proto\x12\nparaformer\"^\n\x07Request\x12\x12\n\naudio_data\x18\x01 \x01(\x0c\x12\x0c\n\x04user\x18\x02 \x01(\t\x12\x10\n\x08language\x18\x03 \x01(\t\x12\x10\n\x08speaking\x18\x04 \x01(\x08\x12\r\n\x05isEnd\x18\x05 \x01(\x08\"L\n\x08Response\x12\x10\n\x08sentence\x18\x01 \x01(\t\x12\x0c\n\x04user\x18\x02 \x01(\t\x12\x10\n\x08language\x18\x03 \x01(\t\x12\x0e\n\x06\x61\x63tion\x18\x04 \x01(\t2C\n\x03\x41SR\x12<\n\tRecognize\x12\x13.paraformer.Request\x1a\x14.paraformer.Response\"\x00(\x01\x30\x01\x42\x16\n\x07\x65x.grpc\xa2\x02\nparaformerb\x06proto3')
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'paraformer_pb2', globals())
if _descriptor._USE_C_DESCRIPTORS == False:
  DESCRIPTOR._options = None
  DESCRIPTOR._serialized_options = b'\n\007ex.grpc\242\002\nparaformer'
  _REQUEST._serialized_start=32
  _REQUEST._serialized_end=126
  _RESPONSE._serialized_start=128
  _RESPONSE._serialized_end=204
  _ASR._serialized_start=206
  _ASR._serialized_end=273
# @@protoc_insertion_point(module_scope)
funasr/runtime/python/grpc/paraformer_pb2_grpc.py
New file
@@ -0,0 +1,66 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import paraformer_pb2 as paraformer__pb2
class ASRStub(object):
    """Missing associated documentation comment in .proto file."""
    def __init__(self, channel):
        """Constructor.
        Args:
            channel: A grpc.Channel.
        """
        self.Recognize = channel.stream_stream(
                '/paraformer.ASR/Recognize',
                request_serializer=paraformer__pb2.Request.SerializeToString,
                response_deserializer=paraformer__pb2.Response.FromString,
                )
class ASRServicer(object):
    """Missing associated documentation comment in .proto file."""
    def Recognize(self, request_iterator, context):
        """Missing associated documentation comment in .proto file."""
        context.set_code(grpc.StatusCode.UNIMPLEMENTED)
        context.set_details('Method not implemented!')
        raise NotImplementedError('Method not implemented!')
def add_ASRServicer_to_server(servicer, server):
    rpc_method_handlers = {
            'Recognize': grpc.stream_stream_rpc_method_handler(
                    servicer.Recognize,
                    request_deserializer=paraformer__pb2.Request.FromString,
                    response_serializer=paraformer__pb2.Response.SerializeToString,
            ),
    }
    generic_handler = grpc.method_handlers_generic_handler(
            'paraformer.ASR', rpc_method_handlers)
    server.add_generic_rpc_handlers((generic_handler,))
 # This class is part of an EXPERIMENTAL API.
class ASR(object):
    """Missing associated documentation comment in .proto file."""
    @staticmethod
    def Recognize(request_iterator,
            target,
            options=(),
            channel_credentials=None,
            call_credentials=None,
            insecure=False,
            compression=None,
            wait_for_ready=None,
            timeout=None,
            metadata=None):
        return grpc.experimental.stream_stream(request_iterator, target, '/paraformer.ASR/Recognize',
            paraformer__pb2.Request.SerializeToString,
            paraformer__pb2.Response.FromString,
            options, channel_credentials,
            insecure, call_credentials, compression, wait_for_ready, timeout, metadata)