FunASR/funasr/runtime/grpc
2023-04-18 13:04:51 +08:00
..
CMakeLists.txt c++ grpc&onnxruntime support multi threads 2023-04-11 19:53:34 +08:00
common.cmake grpc onnx cpp first commit 2023-03-06 22:50:44 +08:00
paraformer_server.cc fix bug: paraformer_server FunASRRecogPCMBuffer 2023-04-14 17:53:05 +08:00
paraformer_server.h c++ grpc&onnxruntime support multi threads 2023-04-11 19:53:34 +08:00
Readme.md docs 2023-04-18 13:04:51 +08:00
rebuild.sh fix c++ grpc onnx server 2023-03-16 17:06:19 +08:00

Using funasr with grpc-cpp

For the Server

Build onnxruntime as it's document

#put onnx-lib & onnx-asr-model into /path/to/asrmodel(eg: /data/asrmodel)
ls /data/asrmodel/
onnxruntime-linux-x64-1.14.0  speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch

#make sure you have config.yaml, am.mvn, model.onnx(or model_quant.onnx) under speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch

Compile and install grpc v1.52.0 in case of grpc bugs

export GRPC_INSTALL_DIR=/data/soft/grpc
export PKG_CONFIG_PATH=$GRPC_INSTALL_DIR/lib/pkgconfig

git clone -b v1.52.0 --depth=1  https://github.com/grpc/grpc.git
cd grpc
git submodule update --init --recursive

mkdir -p cmake/build
pushd cmake/build
cmake -DgRPC_INSTALL=ON \
      -DgRPC_BUILD_TESTS=OFF \
      -DCMAKE_INSTALL_PREFIX=$GRPC_INSTALL_DIR \
      ../..
make
make install
popd

echo "export GRPC_INSTALL_DIR=/data/soft/grpc" >> ~/.bashrc
echo "export PKG_CONFIG_PATH=\$GRPC_INSTALL_DIR/lib/pkgconfig" >> ~/.bashrc
echo "export PATH=\$GRPC_INSTALL_DIR/bin/:\$PKG_CONFIG_PATH:\$PATH" >> ~/.bashrc
source ~/.bashrc

Compile and start grpc onnx paraformer server

# set -DONNXRUNTIME_DIR=/path/to/asrmodel/onnxruntime-linux-x64-1.14.0
./rebuild.sh

Start grpc paraformer server

Usage: ./cmake/build/paraformer_server port thread_num /path/to/model_file quantize(true or false)
./cmake/build/paraformer_server 10108 4 /data/asrmodel/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch false

For the client

Install the requirements as in grpc-python

git clone https://github.com/alibaba/FunASR.git && cd FunASR
cd funasr/runtime/python/grpc
pip install -r requirements_client.txt

Generate protobuf file

Run on server, the two generated pb files are both used for server and client

# paraformer_pb2.py and paraformer_pb2_grpc.py are already generated, 
# regenerate it only when you make changes to ./proto/paraformer.proto file.
python -m grpc_tools.protoc  --proto_path=./proto -I ./proto    --python_out=. --grpc_python_out=./ ./proto/paraformer.proto

Start grpc client

# Start client.
python grpc_main_client_mic.py --host 127.0.0.1 --port 10095

Acknowledge

  1. This project is maintained by FunASR community.
  2. We acknowledge DeepScience for contributing the grpc service.