mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
call api
call rapidasr api
This commit is contained in:
parent
9100825c06
commit
6de8dfea1c
@ -46,6 +46,13 @@ add_custom_command(
|
||||
# Include generated *.pb.h files
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
include_directories(../onnxruntime/include/)
|
||||
link_directories(../onnxruntime/build/src/)
|
||||
link_directories(../onnxruntime/build/third_party/webrtc/)
|
||||
|
||||
link_directories(${ONNXRUNTIME_DIR}/lib)
|
||||
add_subdirectory("../onnxruntime/src" onnx_src)
|
||||
|
||||
# rg_grpc_proto
|
||||
add_library(rg_grpc_proto
|
||||
${rg_grpc_srcs}
|
||||
@ -54,6 +61,7 @@ add_library(rg_grpc_proto
|
||||
${rg_proto_hdrs})
|
||||
|
||||
|
||||
|
||||
target_link_libraries(rg_grpc_proto
|
||||
${_REFLECTION}
|
||||
${_GRPC_GRPCPP}
|
||||
@ -66,6 +74,8 @@ foreach(_target
|
||||
"${_target}.cc")
|
||||
target_link_libraries(${_target}
|
||||
rg_grpc_proto
|
||||
rapidasr
|
||||
webrtcvad
|
||||
${EXTRA_LIBS}
|
||||
${_REFLECTION}
|
||||
${_GRPC_GRPCPP}
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
## paraformer grpc onnx server
|
||||
|
||||
|
||||
#### build ../onnxruntime as it's document
|
||||
```
|
||||
#put onnx lib and model into /data/asrmodel
|
||||
ls /data/asrmodel/
|
||||
onnxruntime-linux-x64-1.14.0 speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch
|
||||
```
|
||||
|
||||
#### Step 1. Compile and install grpc v1.52.0 in case of grpc bugs
|
||||
#### 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
|
||||
@ -24,26 +30,20 @@ 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
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Step 2. Compile grpc onnx paraformer server
|
||||
#### compile grpc onnx paraformer server
|
||||
```
|
||||
#depends on ../onnxruntime
|
||||
#file vocab.txt : UTF-8 Unicode text
|
||||
|
||||
./rebuild.sh
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Step 3. Start grpc python paraformer client on PC with MIC
|
||||
#### start grpc python paraformer client on PC with MIC
|
||||
```
|
||||
cd ../python/grpc
|
||||
python grpc_main_client_mic.py --host 127.0.0.1 --port 10108
|
||||
python grpc_main_client_mic.py --host $server_ip --port 10108
|
||||
```
|
||||
|
||||
|
||||
|
||||
@ -1,9 +1,34 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <grpc/grpc.h>
|
||||
#include <grpcpp/server.h>
|
||||
#include <grpcpp/server_builder.h>
|
||||
#include <grpcpp/server_context.h>
|
||||
#include <grpcpp/security/server_credentials.h>
|
||||
|
||||
#include "paraformer.grpc.pb.h"
|
||||
#include "paraformer_server.h"
|
||||
|
||||
|
||||
using grpc::Server;
|
||||
using grpc::ServerBuilder;
|
||||
using grpc::ServerContext;
|
||||
using grpc::ServerReader;
|
||||
using grpc::ServerReaderWriter;
|
||||
using grpc::ServerWriter;
|
||||
using grpc::Status;
|
||||
|
||||
|
||||
using paraformer::Request;
|
||||
using paraformer::Response;
|
||||
using paraformer::ASR;
|
||||
|
||||
ASRServicer::ASRServicer() {
|
||||
std::cout << "ASRServicer init" << std::endl;
|
||||
init_flag = 0;
|
||||
@ -80,7 +105,8 @@ grpc::Status ASRServicer::Recognize(
|
||||
res.set_sentence(
|
||||
R"({"success": true, "detail": "decoding data: " + std::to_string(tmp_data.length()) + " bytes"})"
|
||||
);
|
||||
std::string data_len = std::to_string(tmp_data.length());
|
||||
int data_len_int = tmp_data.length();
|
||||
std::string data_len = std::to_string(data_len_int);
|
||||
std::stringstream ss;
|
||||
ss << R"({"success": true, "detail": "decoding data: )" << data_len << R"( bytes")" << R"("})";
|
||||
std::string result = ss.str();
|
||||
@ -108,15 +134,7 @@ grpc::Status ASRServicer::Recognize(
|
||||
stream->Write(res);
|
||||
}
|
||||
else {
|
||||
|
||||
// asr_result = onnx.infer(tmp_data)
|
||||
/* if (asr_result.find("text") != asr_result.end()) {
|
||||
asr_result = asr_result["text"];
|
||||
}
|
||||
else {
|
||||
asr_result = "";
|
||||
} */
|
||||
|
||||
RPASR_RESULT Result= RapidAsrRecogPCMBuffer(AsrHanlde, tmp_data.c_str(), data_len_int, RASR_NONE, NULL);
|
||||
std::string asr_result = "你好你好,我是asr识别结果。static";
|
||||
|
||||
auto end_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
||||
@ -4,9 +4,6 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
|
||||
#include <grpc/grpc.h>
|
||||
#include <grpcpp/server.h>
|
||||
@ -14,8 +11,11 @@
|
||||
#include <grpcpp/server_context.h>
|
||||
#include <grpcpp/security/server_credentials.h>
|
||||
|
||||
#include "paraformer.grpc.pb.h"
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
|
||||
#include "paraformer.grpc.pb.h"
|
||||
#include "librapidasrapi.h"
|
||||
|
||||
|
||||
using grpc::Server;
|
||||
@ -45,5 +45,7 @@ class ASRServicer final : public ASR::Service {
|
||||
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);
|
||||
|
||||
};
|
||||
|
||||
@ -5,9 +5,8 @@ mkdir -p cmake/build
|
||||
|
||||
cd cmake/build
|
||||
|
||||
cmake ../..
|
||||
cmake -DCMAKE_BUILD_TYPE=release ../.. -DONNXRUNTIME_DIR=/data/asrmodel/onnxruntime-linux-x64-1.14.0
|
||||
make
|
||||
|
||||
|
||||
echo "Build cmake/build/paraformer_server successfully!"
|
||||
echo "Let's start the server: cd cmake/build/ && ./paraformer_server"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user