mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
Merge pull request #248 from alibaba-damo-academy/dev_grpc
fix c++ grpc onnx server
This commit is contained in:
commit
5cb70f0102
@ -3,7 +3,7 @@
|
||||
|
||||
#### Step 1. Build ../onnxruntime as it's document
|
||||
```
|
||||
#put onnx-lib & onnx-asr-model & vocab.txt into /data/asrmodel
|
||||
#put onnx-lib & onnx-asr-model & vocab.txt 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
|
||||
|
||||
@ -27,6 +27,7 @@ cmake -DgRPC_INSTALL=ON \
|
||||
-DCMAKE_INSTALL_PREFIX=$GRPC_INSTALL_DIR \
|
||||
../..
|
||||
make
|
||||
make install
|
||||
popd
|
||||
|
||||
echo "export GRPC_INSTALL_DIR=/data/soft/grpc" >> ~/.bashrc
|
||||
@ -37,12 +38,19 @@ source ~/.bashrc
|
||||
|
||||
#### Step 3. Compile and start grpc onnx paraformer server
|
||||
```
|
||||
# set -DONNXRUNTIME_DIR=/path/to/asrmodel/onnxruntime-linux-x64-1.14.0
|
||||
./rebuild.sh
|
||||
```
|
||||
|
||||
#### Step 4. Start grpc paraformer server
|
||||
```
|
||||
Usage: ./cmake/build/paraformer_server port thread_num /path/to/model_file
|
||||
./cmake/build/paraformer_server 10108 4 /data/asrmodel/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Step 4. Start grpc python paraformer client on PC with MIC
|
||||
#### Step 5. Start grpc python paraformer client on PC with MIC
|
||||
```
|
||||
cd ../python/grpc
|
||||
python grpc_main_client_mic.py --host $server_ip --port 10108
|
||||
|
||||
@ -29,7 +29,8 @@ using paraformer::Request;
|
||||
using paraformer::Response;
|
||||
using paraformer::ASR;
|
||||
|
||||
ASRServicer::ASRServicer() {
|
||||
ASRServicer::ASRServicer(const char* model_path, int thread_num) {
|
||||
AsrHanlde=RapidAsrInit(model_path, thread_num);
|
||||
std::cout << "ASRServicer init" << std::endl;
|
||||
init_flag = 0;
|
||||
}
|
||||
@ -135,7 +136,7 @@ grpc::Status ASRServicer::Recognize(
|
||||
}
|
||||
else {
|
||||
RPASR_RESULT Result= RapidAsrRecogPCMBuffer(AsrHanlde, tmp_data.c_str(), data_len_int, RASR_NONE, NULL);
|
||||
std::string asr_result = "你好你好,我是asr识别结果。static";
|
||||
std::string asr_result = ((RPASR_RECOG_RESULT*)Result)->msg;
|
||||
|
||||
auto end_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
std::string delay_str = std::to_string(end_time - begin_time);
|
||||
@ -169,19 +170,26 @@ grpc::Status ASRServicer::Recognize(
|
||||
}
|
||||
|
||||
|
||||
void RunServer() {
|
||||
std::string server_address("0.0.0.0:10108");
|
||||
ASRServicer service;
|
||||
void RunServer(const std::string& port, int thread_num, const char* model_path) {
|
||||
std::string server_address;
|
||||
server_address = "0.0.0.0:" + port;
|
||||
ASRServicer service(model_path, thread_num);
|
||||
|
||||
ServerBuilder builder;
|
||||
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
|
||||
builder.RegisterService(&service);
|
||||
std::unique_ptr<Server> server(builder.BuildAndStart());
|
||||
std::cout << "Server listening on " << server_address << std::endl;
|
||||
server->Wait();
|
||||
ServerBuilder builder;
|
||||
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
|
||||
builder.RegisterService(&service);
|
||||
std::unique_ptr<Server> server(builder.BuildAndStart());
|
||||
std::cout << "Server listening on " << server_address << std::endl;
|
||||
server->Wait();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
RunServer();
|
||||
return 0;
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 3)
|
||||
{
|
||||
printf("Usage: %s port thread_num /path/to/model_file\n", argv[0]);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
RunServer(argv[1], atoi(argv[2]), argv[3]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -31,6 +31,12 @@ using paraformer::Request;
|
||||
using paraformer::Response;
|
||||
using paraformer::ASR;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string msg;
|
||||
float snippet_time;
|
||||
}RPASR_RECOG_RESULT;
|
||||
|
||||
|
||||
class ASRServicer final : public ASR::Service {
|
||||
private:
|
||||
@ -39,13 +45,12 @@ class ASRServicer final : public ASR::Service {
|
||||
std::unordered_map<std::string, std::string> client_transcription;
|
||||
|
||||
public:
|
||||
ASRServicer();
|
||||
ASRServicer(const char* model_path, int thread_num);
|
||||
void clear_states(const std::string& user);
|
||||
void clear_buffers(const std::string& user);
|
||||
void clear_transcriptions(const std::string& user);
|
||||
void disconnect(const std::string& user);
|
||||
grpc::Status Recognize(grpc::ServerContext* context, grpc::ServerReaderWriter<Response, Request>* stream);
|
||||
int nThreadNum = 4;
|
||||
RPASR_HANDLE AsrHanlde=RapidAsrInit("/data/asrmodel/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch/", nThreadNum);
|
||||
RPASR_HANDLE AsrHanlde;
|
||||
|
||||
};
|
||||
|
||||
@ -10,7 +10,3 @@ make
|
||||
|
||||
|
||||
echo "Build cmake/build/paraformer_server successfully!"
|
||||
|
||||
echo "Start server"
|
||||
|
||||
./paraformer_server
|
||||
Loading…
Reference in New Issue
Block a user