From 15fd6cdf1ac6737d92ae88a9147c0f6f7044e0ad Mon Sep 17 00:00:00 2001
From: huangmingming <huangmingming@deepscience.cn>
Date: 星期日, 29 一月 2023 19:01:36 +0800
Subject: [PATCH] fix client, add pb file
---
funasr/runtime/python/grpc/grpc_main_client_mic.py | 20 ++++++----
funasr/runtime/python/grpc/paraformer_pb2_grpc.py | 66 +++++++++++++++++++++++++++++++++
funasr/runtime/python/grpc/__pycache__/grpc_client.cpython-37.pyc | 0
funasr/runtime/python/grpc/__pycache__/paraformer_pb2_grpc.cpython-37.pyc | 0
funasr/runtime/python/grpc/__pycache__/paraformer_pb2.cpython-37.pyc | 0
funasr/runtime/python/grpc/paraformer_pb2.py | 30 +++++++++++++++
6 files changed, 108 insertions(+), 8 deletions(-)
diff --git a/funasr/runtime/python/grpc/__pycache__/grpc_client.cpython-37.pyc b/funasr/runtime/python/grpc/__pycache__/grpc_client.cpython-37.pyc
new file mode 100644
index 0000000..0377704
--- /dev/null
+++ b/funasr/runtime/python/grpc/__pycache__/grpc_client.cpython-37.pyc
Binary files differ
diff --git a/funasr/runtime/python/grpc/__pycache__/paraformer_pb2.cpython-37.pyc b/funasr/runtime/python/grpc/__pycache__/paraformer_pb2.cpython-37.pyc
new file mode 100644
index 0000000..2f03349
--- /dev/null
+++ b/funasr/runtime/python/grpc/__pycache__/paraformer_pb2.cpython-37.pyc
Binary files differ
diff --git a/funasr/runtime/python/grpc/__pycache__/paraformer_pb2_grpc.cpython-37.pyc b/funasr/runtime/python/grpc/__pycache__/paraformer_pb2_grpc.cpython-37.pyc
new file mode 100644
index 0000000..081d326
--- /dev/null
+++ b/funasr/runtime/python/grpc/__pycache__/paraformer_pb2_grpc.cpython-37.pyc
Binary files differ
diff --git a/funasr/runtime/python/grpc/grpc_main_client_mic.py b/funasr/runtime/python/grpc/grpc_main_client_mic.py
index de2cded..c393d4a 100644
--- a/funasr/runtime/python/grpc/grpc_main_client_mic.py
+++ b/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()
diff --git a/funasr/runtime/python/grpc/paraformer_pb2.py b/funasr/runtime/python/grpc/paraformer_pb2.py
new file mode 100644
index 0000000..05e05ff
--- /dev/null
+++ b/funasr/runtime/python/grpc/paraformer_pb2.py
@@ -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)
diff --git a/funasr/runtime/python/grpc/paraformer_pb2_grpc.py b/funasr/runtime/python/grpc/paraformer_pb2_grpc.py
new file mode 100644
index 0000000..035563e
--- /dev/null
+++ b/funasr/runtime/python/grpc/paraformer_pb2_grpc.py
@@ -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)
--
Gitblit v1.9.1