From 27ae3482d459c08f01f084cb6f21d1eb28bdf74d Mon Sep 17 00:00:00 2001 From: Hui Zhang Date: Wed, 8 Mar 2023 08:16:40 +0000 Subject: [PATCH] add vad jni; format code --- runtime/CMakeLists.txt | 25 +++++++- runtime/build.sh | 9 ++- runtime/cmake/fastdeploy.cmake | 6 +- runtime/cmake/summary.cmake | 1 + .../ctc_prefix_beam_search_decoder_main.cc | 8 +-- .../asr/decoder/ctc_tlg_decoder_main.cc | 2 +- runtime/engine/asr/nnet/nnet_producer.cc | 3 +- runtime/engine/asr/nnet/u2_nnet_main.cc | 8 +-- .../engine/asr/nnet/u2_nnet_thread_main.cc | 2 +- .../recognizer/u2_recognizer_batch_main.cc | 2 +- .../asr/recognizer/u2_recognizer_main.cc | 2 +- .../recognizer/u2_recognizer_thread_main.cc | 2 +- .../server/websocket/websocket_client_main.cc | 2 +- .../server/websocket/websocket_server_main.cc | 2 +- runtime/engine/cls/nnet/panns_interface.cc | 1 + runtime/engine/cls/nnet/panns_nnet_main.cc | 1 + runtime/engine/common/base/basic_types.h | 2 +- runtime/engine/common/base/config.h | 8 +-- runtime/engine/common/base/log_impl.h | 6 +- runtime/engine/common/frontend/assembler.cc | 3 +- runtime/engine/common/frontend/fftsg.c | 24 ++++---- runtime/engine/common/frontend/rfft.cc | 3 +- runtime/engine/common/frontend/wave-reader.cc | 10 ++-- runtime/engine/common/matrix/kaldi-matrix.h | 2 +- runtime/engine/common/matrix/kaldi-vector.cc | 2 + runtime/engine/common/matrix/matrix-common.h | 2 +- runtime/engine/vad/CMakeLists.txt | 6 +- runtime/engine/vad/frontend/wav.h | 1 + runtime/engine/vad/interface/CMakeLists.txt | 30 ++++------ runtime/engine/vad/interface/vad_interface.cc | 1 + .../vad/interface/vad_interface_main.cc | 3 +- runtime/engine/vad/jni/CMakeLists.txt | 11 ++++ runtime/engine/vad/jni/vad_jni_interface.cc | 50 ++++++++++++++++ runtime/engine/vad/jni/vad_jni_interface.h | 57 +++++++++++++++++++ runtime/engine/vad/nnet/CMakeLists.txt | 10 +++- runtime/engine/vad/nnet/vad.cc | 9 +-- runtime/engine/vad/nnet/vad.h | 3 +- 37 files changed, 236 insertions(+), 83 deletions(-) create mode 100644 runtime/engine/vad/jni/CMakeLists.txt create mode 100644 runtime/engine/vad/jni/vad_jni_interface.cc create mode 100644 runtime/engine/vad/jni/vad_jni_interface.h diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 3f3504732..1585f5674 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -18,6 +18,11 @@ endif() project(paddlespeech VERSION 0.1) +set(PPS_VERSION_MAJOR 1) +set(PPS_VERSION_MINOR 0) +set(PPS_VERSION_PATCH 0) +set(PPS_VERSION "${PPS_VERSION_MAJOR}.${PPS_VERSION_MINOR}.${PPS_VERSION_PATCH}") + include(FetchContent) include(ExternalProject) @@ -163,6 +168,22 @@ include(summary) ############################################################################### # Add local library ############################################################################### -set(ENGINE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/engine) +set(ENGINE_ROOT ${CMAKE_SOURCE_DIR}/engine) + +add_subdirectory(engine) + -add_subdirectory(engine) \ No newline at end of file +############################################################################### +# CPack library +############################################################################### +# build a CPack driven installer package +include (InstallRequiredSystemLibraries) +set(CPACK_PACKAGE_NAME "paddlespeech_library") +set(CPACK_PACKAGE_VENDOR "paddlespeech") +set(CPACK_PACKAGE_VERSION_MAJOR 1) +set(CPACK_PACKAGE_VERSION_MINOR 0) +set(CPACK_PACKAGE_VERSION_PATCH 0) +set(CPACK_PACKAGE_DESCRIPTION "paddlespeech library") +set(CPACK_PACKAGE_CONTACT "paddlespeech@baidu.com") +set(CPACK_SOURCE_GENERATOR "TGZ") +include (CPack) \ No newline at end of file diff --git a/runtime/build.sh b/runtime/build.sh index d7a4bbc7c..f2686c598 100755 --- a/runtime/build.sh +++ b/runtime/build.sh @@ -1,9 +1,14 @@ #!/usr/bin/env bash set -xe +BUILD_ROOT=build/Linux +BUILD_DIR=${BUILD_ROOT}/x86_64 + +mkdir -p ${BUILD_DIR} + # the build script had verified in the paddlepaddle docker image. # please follow the instruction below to install PaddlePaddle image. # https://www.paddlepaddle.org.cn/documentation/docs/zh/install/docker/linux-docker.html #cmake -B build -DBUILD_SHARED_LIBS=OFF -DWITH_ASR=OFF -DWITH_CLS=OFF -DWITH_VAD=ON -DFASTDEPLOY_INSTALL_DIR=/workspace/zhanghui/paddle/FastDeploy/build/Android/arm64-v8a-api-21/install -cmake -B build -DBUILD_SHARED_LIBS=OFF -DWITH_ASR=OFF -DWITH_CLS=OFF -DWITH_VAD=ON -DFASTDEPLOY_INSTALL_DIR=/workspace/zhanghui/paddle/FastDeploy/build/Linux/x86_64/install -cmake --build build -j +cmake -B ${BUILD_DIR} -DBUILD_SHARED_LIBS=OFF -DWITH_ASR=OFF -DWITH_CLS=OFF -DWITH_VAD=ON -DFASTDEPLOY_INSTALL_DIR=/workspace/zhanghui/paddle/FastDeploy/build/Linux/x86_64/install +cmake --build ${BUILD_DIR} -j diff --git a/runtime/cmake/fastdeploy.cmake b/runtime/cmake/fastdeploy.cmake index 00ce2d33e..fa72bafea 100644 --- a/runtime/cmake/fastdeploy.cmake +++ b/runtime/cmake/fastdeploy.cmake @@ -91,13 +91,13 @@ if(ENABLE_VISION) if(WIN32) file(GLOB OPENCV_DYN_LIBS ${OpenCV_DIR}/x64/vc15/bin/${DYN_LIB_SUFFIX}) - install(FILES ${OPENCV_DYN_LIBS} DESTINATION lib}) + install(FILES ${OPENCV_DYN_LIBS} DESTINATION lib) elseif(ANDROID AND (NOT WITH_ANDROID_OPENCV_STATIC)) file(GLOB OPENCV_DYN_LIBS ${OpenCV_NATIVE_DIR}/libs/${ANDROID_ABI}/${DYN_LIB_SUFFIX}) - install(FILES ${OPENCV_DYN_LIBS} DESTINATION lib}) + install(FILES ${OPENCV_DYN_LIBS} DESTINATION lib) else() # linux/mac file(GLOB OPENCV_DYN_LIBS ${OpenCV_DIR}/lib/${DYN_LIB_SUFFIX}) - install(FILES ${OPENCV_DYN_LIBS} DESTINATION lib}) + install(FILES ${OPENCV_DYN_LIBS} DESTINATION lib) endif() # FlyCV diff --git a/runtime/cmake/summary.cmake b/runtime/cmake/summary.cmake index 1d0ae6ec7..95ee324a1 100644 --- a/runtime/cmake/summary.cmake +++ b/runtime/cmake/summary.cmake @@ -15,6 +15,7 @@ function(pps_summary) message(STATUS "") message(STATUS "*************PaddleSpeech Building Summary**********") + message(STATUS " PPS_VERSION : ${PPS_VERSION}") message(STATUS " CMake version : ${CMAKE_VERSION}") message(STATUS " CMake command : ${CMAKE_COMMAND}") message(STATUS " UNIX : ${UNIX}") diff --git a/runtime/engine/asr/decoder/ctc_prefix_beam_search_decoder_main.cc b/runtime/engine/asr/decoder/ctc_prefix_beam_search_decoder_main.cc index bd73b3aca..1673bdad1 100644 --- a/runtime/engine/asr/decoder/ctc_prefix_beam_search_decoder_main.cc +++ b/runtime/engine/asr/decoder/ctc_prefix_beam_search_decoder_main.cc @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "decoder/ctc_prefix_beam_search_decoder.h" #include "base/common.h" +#include "decoder/ctc_prefix_beam_search_decoder.h" #include "frontend/data_cache.h" #include "fst/symbol-table.h" #include "kaldi/util/table-types.h" @@ -117,9 +117,9 @@ int main(int argc, char* argv[]) { ori_feature_len - chunk_idx * chunk_stride, chunk_size); } if (this_chunk_size < receptive_field_length) { - LOG(WARNING) << "utt: " << utt << " skip last " - << this_chunk_size << " frames, expect is " - << receptive_field_length; + LOG(WARNING) + << "utt: " << utt << " skip last " << this_chunk_size + << " frames, expect is " << receptive_field_length; break; } diff --git a/runtime/engine/asr/decoder/ctc_tlg_decoder_main.cc b/runtime/engine/asr/decoder/ctc_tlg_decoder_main.cc index 148ee15e3..410574dcb 100644 --- a/runtime/engine/asr/decoder/ctc_tlg_decoder_main.cc +++ b/runtime/engine/asr/decoder/ctc_tlg_decoder_main.cc @@ -14,8 +14,8 @@ // todo refactor, repalce with gtest -#include "decoder/ctc_tlg_decoder.h" #include "base/common.h" +#include "decoder/ctc_tlg_decoder.h" #include "decoder/param.h" #include "frontend/data_cache.h" #include "kaldi/util/table-types.h" diff --git a/runtime/engine/asr/nnet/nnet_producer.cc b/runtime/engine/asr/nnet/nnet_producer.cc index 29daa709d..1e481e306 100644 --- a/runtime/engine/asr/nnet/nnet_producer.cc +++ b/runtime/engine/asr/nnet/nnet_producer.cc @@ -13,12 +13,13 @@ // limitations under the License. #include "nnet/nnet_producer.h" + #include "matrix/kaldi-matrix.h" namespace ppspeech { -using std::vector; using kaldi::BaseFloat; +using std::vector; NnetProducer::NnetProducer(std::shared_ptr nnet, std::shared_ptr frontend) diff --git a/runtime/engine/asr/nnet/u2_nnet_main.cc b/runtime/engine/asr/nnet/u2_nnet_main.cc index 699f42586..e60ae7e80 100644 --- a/runtime/engine/asr/nnet/u2_nnet_main.cc +++ b/runtime/engine/asr/nnet/u2_nnet_main.cc @@ -13,13 +13,13 @@ // limitations under the License. -#include "nnet/u2_nnet.h" #include "base/common.h" #include "decoder/param.h" #include "frontend/assembler.h" #include "frontend/data_cache.h" #include "kaldi/util/table-types.h" #include "nnet/decodable.h" +#include "nnet/u2_nnet.h" DEFINE_string(feature_rspecifier, "", "test feature rspecifier"); @@ -93,9 +93,9 @@ int main(int argc, char* argv[]) { ori_feature_len - chunk_idx * chunk_stride, chunk_size); } if (this_chunk_size < receptive_field_length) { - LOG(WARNING) << "utt: " << utt << " skip last " - << this_chunk_size << " frames, expect is " - << receptive_field_length; + LOG(WARNING) + << "utt: " << utt << " skip last " << this_chunk_size + << " frames, expect is " << receptive_field_length; break; } diff --git a/runtime/engine/asr/nnet/u2_nnet_thread_main.cc b/runtime/engine/asr/nnet/u2_nnet_thread_main.cc index 4339bdbea..c3f291ced 100644 --- a/runtime/engine/asr/nnet/u2_nnet_thread_main.cc +++ b/runtime/engine/asr/nnet/u2_nnet_thread_main.cc @@ -13,7 +13,6 @@ // limitations under the License. -#include "nnet/u2_nnet.h" #include "base/common.h" #include "decoder/param.h" #include "frontend/feature_pipeline.h" @@ -21,6 +20,7 @@ #include "kaldi/util/table-types.h" #include "nnet/decodable.h" #include "nnet/nnet_producer.h" +#include "nnet/u2_nnet.h" DEFINE_string(wav_rspecifier, "", "test wav rspecifier"); DEFINE_string(nnet_prob_wspecifier, "", "nnet porb wspecifier"); diff --git a/runtime/engine/asr/recognizer/u2_recognizer_batch_main.cc b/runtime/engine/asr/recognizer/u2_recognizer_batch_main.cc index 709e5aa62..8d1532bd1 100644 --- a/runtime/engine/asr/recognizer/u2_recognizer_batch_main.cc +++ b/runtime/engine/asr/recognizer/u2_recognizer_batch_main.cc @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "recognizer/u2_recognizer.h" #include "common/base/thread_pool.h" #include "common/utils/file_utils.h" #include "common/utils/strings.h" @@ -20,6 +19,7 @@ #include "frontend/wave-reader.h" #include "kaldi/util/table-types.h" #include "nnet/u2_nnet.h" +#include "recognizer/u2_recognizer.h" DEFINE_string(wav_rspecifier, "", "test feature rspecifier"); DEFINE_string(result_wspecifier, "", "test result wspecifier"); diff --git a/runtime/engine/asr/recognizer/u2_recognizer_main.cc b/runtime/engine/asr/recognizer/u2_recognizer_main.cc index fb37d050f..178c91db1 100644 --- a/runtime/engine/asr/recognizer/u2_recognizer_main.cc +++ b/runtime/engine/asr/recognizer/u2_recognizer_main.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "recognizer/u2_recognizer.h" #include "decoder/param.h" #include "frontend/wave-reader.h" #include "kaldi/util/table-types.h" +#include "recognizer/u2_recognizer.h" DEFINE_string(wav_rspecifier, "", "test feature rspecifier"); DEFINE_string(result_wspecifier, "", "test result wspecifier"); diff --git a/runtime/engine/asr/recognizer/u2_recognizer_thread_main.cc b/runtime/engine/asr/recognizer/u2_recognizer_thread_main.cc index b86853fad..272defc60 100644 --- a/runtime/engine/asr/recognizer/u2_recognizer_thread_main.cc +++ b/runtime/engine/asr/recognizer/u2_recognizer_thread_main.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "recognizer/u2_recognizer.h" #include "decoder/param.h" #include "frontend/wave-reader.h" #include "kaldi/util/table-types.h" +#include "recognizer/u2_recognizer.h" DEFINE_string(wav_rspecifier, "", "test feature rspecifier"); DEFINE_string(result_wspecifier, "", "test result wspecifier"); diff --git a/runtime/engine/asr/server/websocket/websocket_client_main.cc b/runtime/engine/asr/server/websocket/websocket_client_main.cc index 7ad36e3a5..7c5a4f2f7 100644 --- a/runtime/engine/asr/server/websocket/websocket_client_main.cc +++ b/runtime/engine/asr/server/websocket/websocket_client_main.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "websocket/websocket_client.h" #include "kaldi/feat/wave-reader.h" #include "kaldi/util/kaldi-io.h" #include "kaldi/util/table-types.h" +#include "websocket/websocket_client.h" DEFINE_string(host, "127.0.0.1", "host of websocket server"); DEFINE_int32(port, 8082, "port of websocket server"); diff --git a/runtime/engine/asr/server/websocket/websocket_server_main.cc b/runtime/engine/asr/server/websocket/websocket_server_main.cc index 5f805ac9d..5c32caf27 100644 --- a/runtime/engine/asr/server/websocket/websocket_server_main.cc +++ b/runtime/engine/asr/server/websocket/websocket_server_main.cc @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "websocket/websocket_server.h" #include "decoder/param.h" +#include "websocket/websocket_server.h" DEFINE_int32(port, 8082, "websocket listening port"); diff --git a/runtime/engine/cls/nnet/panns_interface.cc b/runtime/engine/cls/nnet/panns_interface.cc index 257ee44f1..cfff3f92e 100644 --- a/runtime/engine/cls/nnet/panns_interface.cc +++ b/runtime/engine/cls/nnet/panns_interface.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "cls/nnet/panns_interface.h" + #include "cls/nnet/panns_nnet.h" #include "common/base/config.h" diff --git a/runtime/engine/cls/nnet/panns_nnet_main.cc b/runtime/engine/cls/nnet/panns_nnet_main.cc index 4280d14c2..14f91fc71 100644 --- a/runtime/engine/cls/nnet/panns_nnet_main.cc +++ b/runtime/engine/cls/nnet/panns_nnet_main.cc @@ -14,6 +14,7 @@ #include #include + #include "base/flags.h" #include "cls/nnet/panns_interface.h" diff --git a/runtime/engine/common/base/basic_types.h b/runtime/engine/common/base/basic_types.h index c7fdc9241..2b15a61fe 100644 --- a/runtime/engine/common/base/basic_types.h +++ b/runtime/engine/common/base/basic_types.h @@ -28,7 +28,7 @@ typedef int int32; // NOLINT #if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) typedef long int64; // NOLINT #else -typedef long long int64; // NOLINT +typedef long long int64; // NOLINT #endif typedef unsigned char uint8; // NOLINT diff --git a/runtime/engine/common/base/config.h b/runtime/engine/common/base/config.h index 0a0712778..c8eae5e28 100644 --- a/runtime/engine/common/base/config.h +++ b/runtime/engine/common/base/config.h @@ -15,9 +15,9 @@ using namespace std; #endif /* -* \brief Generic configuration Class -* -*/ + * \brief Generic configuration Class + * + */ class Config { // Data protected: @@ -35,7 +35,7 @@ class Config { std::string comment = "#"); Config(); template - T Read(const std::string& in_key) const; //! template diff --git a/runtime/engine/common/base/log_impl.h b/runtime/engine/common/base/log_impl.h index 935736205..535007b1a 100644 --- a/runtime/engine/common/base/log_impl.h +++ b/runtime/engine/common/base/log_impl.h @@ -18,6 +18,9 @@ #pragma once +#include +#include + #include #include #include @@ -25,9 +28,6 @@ #include #include -#include -#include - #include "base/common.h" #include "base/macros.h" #ifndef WITH_GLOG diff --git a/runtime/engine/common/frontend/assembler.cc b/runtime/engine/common/frontend/assembler.cc index 487951cdb..70e1a43ec 100644 --- a/runtime/engine/common/frontend/assembler.cc +++ b/runtime/engine/common/frontend/assembler.cc @@ -17,9 +17,8 @@ namespace ppspeech { using kaldi::BaseFloat; -using std::vector; -using std::vector; using std::unique_ptr; +using std::vector; Assembler::Assembler(AssemblerOptions opts, unique_ptr base_extractor) { diff --git a/runtime/engine/common/frontend/fftsg.c b/runtime/engine/common/frontend/fftsg.c index ec8217a2b..30b816049 100644 --- a/runtime/engine/common/frontend/fftsg.c +++ b/runtime/engine/common/frontend/fftsg.c @@ -821,12 +821,12 @@ void cftfsub(int n, double *a, int *ip, int nw, double *w) { } else #endif /* USE_CDFT_THREADS */ if (n > 512) { - cftrec4(n, a, nw, w); - } else if (n > 128) { - cftleaf(n, 1, a, nw, w); - } else { - cftfx41(n, a, nw, w); - } + cftrec4(n, a, nw, w); + } else if (n > 128) { + cftleaf(n, 1, a, nw, w); + } else { + cftfx41(n, a, nw, w); + } bitrv2(n, ip, a); } else if (n == 32) { cftf161(a, &w[nw - 8]); @@ -868,12 +868,12 @@ void cftbsub(int n, double *a, int *ip, int nw, double *w) { } else #endif /* USE_CDFT_THREADS */ if (n > 512) { - cftrec4(n, a, nw, w); - } else if (n > 128) { - cftleaf(n, 1, a, nw, w); - } else { - cftfx41(n, a, nw, w); - } + cftrec4(n, a, nw, w); + } else if (n > 128) { + cftleaf(n, 1, a, nw, w); + } else { + cftfx41(n, a, nw, w); + } bitrv2conj(n, ip, a); } else if (n == 32) { cftf161(a, &w[nw - 8]); diff --git a/runtime/engine/common/frontend/rfft.cc b/runtime/engine/common/frontend/rfft.cc index 8cdb634ff..9ce6a172a 100644 --- a/runtime/engine/common/frontend/rfft.cc +++ b/runtime/engine/common/frontend/rfft.cc @@ -17,12 +17,13 @@ */ #include "frontend/rfft.h" -#include "base/log.h" #include #include #include +#include "base/log.h" + // see fftsg.c #ifdef __cplusplus extern "C" void rdft(int n, int isgn, double *a, int *ip, double *w); diff --git a/runtime/engine/common/frontend/wave-reader.cc b/runtime/engine/common/frontend/wave-reader.cc index b64dcc9e3..e94aafef9 100644 --- a/runtime/engine/common/frontend/wave-reader.cc +++ b/runtime/engine/common/frontend/wave-reader.cc @@ -19,6 +19,8 @@ // See the Apache 2 License for the specific language governing permissions and // limitations under the License. +#include "frontend/wave-reader.h" + #include #include #include @@ -27,7 +29,6 @@ #include "base/kaldi-error.h" #include "base/kaldi-utils.h" -#include "frontend/wave-reader.h" namespace kaldi { @@ -243,10 +244,9 @@ void WaveInfo::Read(std::istream &is) { << ", data chunk size: " << data_chunk_size << ". Assume 'stream mode' (reading data to EOF)."; - if (!is_stream_mode && - std::abs(static_cast(riff_chunk_read) + - static_cast(data_chunk_size) - - static_cast(riff_chunk_size)) > 1) { + if (!is_stream_mode && std::abs(static_cast(riff_chunk_read) + + static_cast(data_chunk_size) - + static_cast(riff_chunk_size)) > 1) { // We allow the size to be off by one without warning, because there is // a // weirdness in the format of RIFF files that means that the input may diff --git a/runtime/engine/common/matrix/kaldi-matrix.h b/runtime/engine/common/matrix/kaldi-matrix.h index c082a731c..d614f36f9 100644 --- a/runtime/engine/common/matrix/kaldi-matrix.h +++ b/runtime/engine/common/matrix/kaldi-matrix.h @@ -590,7 +590,7 @@ class MatrixBase { * SpMatrix and use Eig() function there, which uses eigenvalue * decomposition * directly rather than SVD. - */ + */ /// stream read. /// Use instead of stream<<*this, if you want to add to existing contents. diff --git a/runtime/engine/common/matrix/kaldi-vector.cc b/runtime/engine/common/matrix/kaldi-vector.cc index 1d0b55b96..3ab9a7ffa 100644 --- a/runtime/engine/common/matrix/kaldi-vector.cc +++ b/runtime/engine/common/matrix/kaldi-vector.cc @@ -24,8 +24,10 @@ // limitations under the License. #include "matrix/kaldi-vector.h" + #include #include + #include "matrix/kaldi-matrix.h" namespace kaldi { diff --git a/runtime/engine/common/matrix/matrix-common.h b/runtime/engine/common/matrix/matrix-common.h index 512beb204..e915db0a7 100644 --- a/runtime/engine/common/matrix/matrix-common.h +++ b/runtime/engine/common/matrix/matrix-common.h @@ -90,7 +90,7 @@ typedef uint32 UnsignedMatrixIndexT; // typedef size_t MatrixIndexT; // typedef ssize_t SignedMatrixIndexT; // typedef size_t UnsignedMatrixIndexT; -} +} // namespace kaldi #endif // KALDI_MATRIX_MATRIX_COMMON_H_ diff --git a/runtime/engine/vad/CMakeLists.txt b/runtime/engine/vad/CMakeLists.txt index f61c5a9a8..edf18f4e3 100644 --- a/runtime/engine/vad/CMakeLists.txt +++ b/runtime/engine/vad/CMakeLists.txt @@ -4,4 +4,8 @@ ${CMAKE_CURRENT_SOURCE_DIR}/../ add_subdirectory(nnet) -add_subdirectory(interface) \ No newline at end of file +add_subdirectory(interface) + +if(ANDROID) + add_subdirectory(jni) +endif() \ No newline at end of file diff --git a/runtime/engine/vad/frontend/wav.h b/runtime/engine/vad/frontend/wav.h index c84326921..f9b7bee22 100644 --- a/runtime/engine/vad/frontend/wav.h +++ b/runtime/engine/vad/frontend/wav.h @@ -17,6 +17,7 @@ #include #include #include + #include #include diff --git a/runtime/engine/vad/interface/CMakeLists.txt b/runtime/engine/vad/interface/CMakeLists.txt index a58d7ed34..838296df5 100644 --- a/runtime/engine/vad/interface/CMakeLists.txt +++ b/runtime/engine/vad/interface/CMakeLists.txt @@ -2,34 +2,24 @@ set(srcs vad_interface.cc ) -add_library(vad_interface ${srcs}) -target_link_libraries(vad_interface PUBLIC ${FASTDEPLOY_LIBS} vad extern_glog) +add_library(pps_vad_interface ${srcs}) +target_link_libraries(pps_vad_interface PUBLIC ${FASTDEPLOY_LIBS} pps_vad) set(bin_name vad_interface_main) add_executable(${bin_name} ${CMAKE_CURRENT_SOURCE_DIR}/${bin_name}.cc) -target_link_libraries(${bin_name} ${FASTDEPLOY_LIBS} vad_interface) +target_link_libraries(${bin_name} ${FASTDEPLOY_LIBS} pps_vad_interface) # set_target_properties(${bin_name} PROPERTIES PUBLIC_HEADER "vad_interface.h;../frontend/wav.h") -install(TARGETS vad_interface DESTINATION lib) -install(FILES vad_interface.h DESTINATION include) + +file(RELATIVE_PATH DEST_DIR ${ENGINE_ROOT} ${CMAKE_CURRENT_SOURCE_DIR}) +install(TARGETS pps_vad_interface DESTINATION lib) +install(FILES vad_interface.h DESTINATION include/${DEST_DIR}) + install(TARGETS vad_interface_main RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib - PUBLIC_HEADER DESTINATION include + PUBLIC_HEADER DESTINATION include/${DEST_DIR} ) -install(FILES vad_interface_main.cc DESTINATION demo) - - -# build a CPack driven installer package -include (InstallRequiredSystemLibraries) -set(CPACK_PACKAGE_NAME "paddlespeech_vad_interface") -set(CPACK_PACKAGE_VENDOR "paddlespeech") -set(CPACK_PACKAGE_VERSION_MAJOR 1) -set(CPACK_PACKAGE_VERSION_MINOR 0) -set(CPACK_PACKAGE_VERSION_PATCH 0) -set(CPACK_PACKAGE_DESCRIPTION "paddlespeech vad interface") -set(CPACK_PACKAGE_CONTACT "paddlespeech@baidu.com") -set(CPACK_SOURCE_GENERATOR "TGZ") -include (CPack) +install(FILES vad_interface_main.cc DESTINATION demo/${DEST_DIR}) \ No newline at end of file diff --git a/runtime/engine/vad/interface/vad_interface.cc b/runtime/engine/vad/interface/vad_interface.cc index 734b44185..89e25f1bf 100644 --- a/runtime/engine/vad/interface/vad_interface.cc +++ b/runtime/engine/vad/interface/vad_interface.cc @@ -14,6 +14,7 @@ #include "vad/interface/vad_interface.h" + #include "common/base/config.h" #include "vad/nnet/vad.h" diff --git a/runtime/engine/vad/interface/vad_interface_main.cc b/runtime/engine/vad/interface/vad_interface_main.cc index cb9db5d34..a7ff1afa0 100644 --- a/runtime/engine/vad/interface/vad_interface_main.cc +++ b/runtime/engine/vad/interface/vad_interface_main.cc @@ -13,10 +13,11 @@ // limitations under the License. -#include "vad/interface/vad_interface.h" #include #include + #include "vad/frontend/wav.h" +#include "vad/interface/vad_interface.h" int main(int argc, char* argv[]) { if (argc < 3) { diff --git a/runtime/engine/vad/jni/CMakeLists.txt b/runtime/engine/vad/jni/CMakeLists.txt new file mode 100644 index 000000000..6fdfb1e1f --- /dev/null +++ b/runtime/engine/vad/jni/CMakeLists.txt @@ -0,0 +1,11 @@ +set(srcs + vad_jni_interface.cc +) + +add_library(pps_vad_jni_interface ${srcs}) +target_link_libraries(pps_vad_jni_interface PUBLIC ${FASTDEPLOY_LIBS} pps_vad_interface) + + +file(RELATIVE_PATH DEST_DIR ${ENGINE_ROOT} ${CMAKE_CURRENT_SOURCE_DIR}) +install(TARGETS pps_vad_jni_interface DESTINATION lib) +install(FILES vad_jni_interface.h DESTINATION include/${DEST_DIR}) \ No newline at end of file diff --git a/runtime/engine/vad/jni/vad_jni_interface.cc b/runtime/engine/vad/jni/vad_jni_interface.cc new file mode 100644 index 000000000..6ba63e35f --- /dev/null +++ b/runtime/engine/vad/jni/vad_jni_interface.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "vad/jni/vad_jni_interface.h" + +JNIEXPORT jlong JNICALL Java_com_baidu_paddlespeech_PPSVadJni_createInstance( + JNIEnv* env, jobject thiz, jstring conf_path) { + const char* path = env->GetStringUTFChars(conf_path, JNI_FALSE); + PPSHandle_t handle = PPSVadCreateInstance(path); + + return (jlong)(handle); +} + +JNIEXPORT jint JNICALL Java_com_baidu_paddlespeech_PPSVadJni_destoryInstance( + JNIEnv* env, jobject thiz, PPSJniHandle_t instance) { + PPSHandle_t handle = (PPSHandle_t)(instance); + return (jint)PPSVadDestroyInstance(handle); +} + + +JNIEXPORT jint JNICALL Java_com_baidu_paddlespeech_PPSVadJni_reset( + JNIEnv* env, jobject thiz, PPSJniHandle_t instance) { + PPSHandle_t handle = (PPSHandle_t)(instance); + return (jint)PPSVadReset(handle); +} + +JNIEXPORT jint JNICALL Java_com_baidu_paddlespeech_PPSVadJni_chunkSizeSamples( + JNIEnv* env, jobject thiz, PPSJniHandle_t instance) { + PPSHandle_t handle = (PPSHandle_t)(instance); + return (jint)PPSVadChunkSizeSamples(handle); +} + +JNIEXPORT jint JNICALL Java_com_baidu_paddlespeech_PPSVadJni_feedForward( + JNIEnv* env, jobject thiz, PPSJniHandle_t instance, jfloatArray chunk) { + PPSHandle_t handle = (PPSHandle_t)(instance); + jsize num_elms = env->GetArrayLength(chunk); + jfloat* chunk_ptr = env->GetFloatArrayElements(chunk, JNI_FALSE); + return (jint)PPSVadFeedForward(handle, (float*)chunk_ptr, (int)num_elms); +} \ No newline at end of file diff --git a/runtime/engine/vad/jni/vad_jni_interface.h b/runtime/engine/vad/jni/vad_jni_interface.h new file mode 100644 index 000000000..2bf976570 --- /dev/null +++ b/runtime/engine/vad/jni/vad_jni_interface.h @@ -0,0 +1,57 @@ +// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +// PackageName: paddlespeech.baidu.com +// ClassName: PPSVadJni +#include + +#include "vad/interface/vad_interface.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef jlong PPSJniHandle_t; + +JNIEXPORT PPSJniHandle_t JNICALL +Java_com_baidu_paddlespeech_PPSVadJni_createInstance(JNIEnv* env, + jobject thiz, + jstring conf_path); + +JNIEXPORT jint JNICALL Java_com_baidu_paddlespeech_PPSVadJni_destoryInstance( + JNIEnv* env, jobject thiz, PPSJniHandle_t instance); + + +JNIEXPORT jint JNICALL Java_com_baidu_paddlespeech_PPSVadJni_reset( + JNIEnv* env, jobject thiz, PPSJniHandle_t instance); + +JNIEXPORT jint JNICALL Java_com_baidu_paddlespeech_PPSVadJni_chunkSizeSamples( + JNIEnv* env, jobject thiz, PPSJniHandle_t instance); + +// typedef enum { +// PPS_VAD_ILLEGAL = 0, // error +// PPS_VAD_SIL, // silence +// PPS_VAD_START, // start speech +// PPS_VAD_SPEECH, // in speech +// PPS_VAD_END, // end speech +// PPS_VAD_NUMSTATES, // number of states +// } PPSVadState_t; + +JNIEXPORT jint JNICALL Java_com_baidu_paddlespeech_PPSVadJni_feedForward( + JNIEnv* env, jobject thiz, PPSJniHandle_t instance, jfloatArray chunk); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/runtime/engine/vad/nnet/CMakeLists.txt b/runtime/engine/vad/nnet/CMakeLists.txt index dafc2bb01..ffcb536a7 100644 --- a/runtime/engine/vad/nnet/CMakeLists.txt +++ b/runtime/engine/vad/nnet/CMakeLists.txt @@ -2,11 +2,15 @@ set(srcs vad.cc ) -add_library(vad ${srcs}) -target_link_libraries(vad PUBLIC ${FASTDEPLOY_LIBS} common) +add_library(pps_vad ${srcs}) +target_link_libraries(pps_vad PUBLIC ${FASTDEPLOY_LIBS} common) set(bin_name vad_nnet_main) add_executable(${bin_name} ${CMAKE_CURRENT_SOURCE_DIR}/${bin_name}.cc) # target_link_libraries(${bin_name} ${FASTDEPLOY_LIBS} vad gflags extern_glog) -target_link_libraries(${bin_name} ${FASTDEPLOY_LIBS} vad) \ No newline at end of file +target_link_libraries(${bin_name} ${FASTDEPLOY_LIBS} pps_vad) + + +file(RELATIVE_PATH DEST_DIR ${ENGINE_ROOT} ${CMAKE_CURRENT_SOURCE_DIR}) +install(TARGETS pps_vad DESTINATION lib) \ No newline at end of file diff --git a/runtime/engine/vad/nnet/vad.cc b/runtime/engine/vad/nnet/vad.cc index db69618aa..fed538402 100644 --- a/runtime/engine/vad/nnet/vad.cc +++ b/runtime/engine/vad/nnet/vad.cc @@ -13,14 +13,15 @@ // See the License for the specific language governing permissions and // limitations under the License. #include "vad/nnet/vad.h" + #include #include #ifdef NDEBUG -#define LOG_DEBUG \ - ::fastdeploy::FDLogger(true, "[DEBUG]") << __REL_FILE__ << "(" << __LINE__ \ - << ")::" << __FUNCTION__ << "\t" +#define LOG_DEBUG \ + ::fastdeploy::FDLogger(true, "[DEBUG]") \ + << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t" #else #define LOG_DEBUG \ ::fastdeploy::FDLogger(false, "[DEBUG]") \ @@ -323,4 +324,4 @@ std::ostream& operator<<(std::ostream& os, const Vad::State& s) { return os; } -} // namepsace ppspeech \ No newline at end of file +} // namespace ppspeech \ No newline at end of file diff --git a/runtime/engine/vad/nnet/vad.h b/runtime/engine/vad/nnet/vad.h index 565a5680b..7c322388a 100644 --- a/runtime/engine/vad/nnet/vad.h +++ b/runtime/engine/vad/nnet/vad.h @@ -17,6 +17,7 @@ #include #include #include + #include "fastdeploy/fastdeploy_model.h" #include "fastdeploy/runtime.h" #include "vad/frontend/wav.h" @@ -149,4 +150,4 @@ class Vad : public fastdeploy::FastDeployModel { const std::vector hc_node_dims_ = {2, 1, 64}; }; -} // namepsace ppspeech \ No newline at end of file +} // namespace ppspeech \ No newline at end of file