add vad jni; format code

pull/3026/head
Hui Zhang 3 years ago
parent a718ffe823
commit 27ae3482d4

@ -18,6 +18,11 @@ endif()
project(paddlespeech VERSION 0.1) 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(FetchContent)
include(ExternalProject) include(ExternalProject)
@ -163,6 +168,22 @@ include(summary)
############################################################################### ###############################################################################
# Add local library # Add local library
############################################################################### ###############################################################################
set(ENGINE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/engine) set(ENGINE_ROOT ${CMAKE_SOURCE_DIR}/engine)
add_subdirectory(engine) add_subdirectory(engine)
###############################################################################
# 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)

@ -1,9 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -xe 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. # the build script had verified in the paddlepaddle docker image.
# please follow the instruction below to install PaddlePaddle image. # please follow the instruction below to install PaddlePaddle image.
# https://www.paddlepaddle.org.cn/documentation/docs/zh/install/docker/linux-docker.html # 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/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 -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 -j cmake --build ${BUILD_DIR} -j

@ -91,13 +91,13 @@ if(ENABLE_VISION)
if(WIN32) if(WIN32)
file(GLOB OPENCV_DYN_LIBS ${OpenCV_DIR}/x64/vc15/bin/${DYN_LIB_SUFFIX}) 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)) elseif(ANDROID AND (NOT WITH_ANDROID_OPENCV_STATIC))
file(GLOB OPENCV_DYN_LIBS ${OpenCV_NATIVE_DIR}/libs/${ANDROID_ABI}/${DYN_LIB_SUFFIX}) 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 else() # linux/mac
file(GLOB OPENCV_DYN_LIBS ${OpenCV_DIR}/lib/${DYN_LIB_SUFFIX}) 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() endif()
# FlyCV # FlyCV

@ -15,6 +15,7 @@
function(pps_summary) function(pps_summary)
message(STATUS "") message(STATUS "")
message(STATUS "*************PaddleSpeech Building Summary**********") message(STATUS "*************PaddleSpeech Building Summary**********")
message(STATUS " PPS_VERSION : ${PPS_VERSION}")
message(STATUS " CMake version : ${CMAKE_VERSION}") message(STATUS " CMake version : ${CMAKE_VERSION}")
message(STATUS " CMake command : ${CMAKE_COMMAND}") message(STATUS " CMake command : ${CMAKE_COMMAND}")
message(STATUS " UNIX : ${UNIX}") message(STATUS " UNIX : ${UNIX}")

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "decoder/ctc_prefix_beam_search_decoder.h"
#include "base/common.h" #include "base/common.h"
#include "decoder/ctc_prefix_beam_search_decoder.h"
#include "frontend/data_cache.h" #include "frontend/data_cache.h"
#include "fst/symbol-table.h" #include "fst/symbol-table.h"
#include "kaldi/util/table-types.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); ori_feature_len - chunk_idx * chunk_stride, chunk_size);
} }
if (this_chunk_size < receptive_field_length) { if (this_chunk_size < receptive_field_length) {
LOG(WARNING) << "utt: " << utt << " skip last " LOG(WARNING)
<< this_chunk_size << " frames, expect is " << "utt: " << utt << " skip last " << this_chunk_size
<< receptive_field_length; << " frames, expect is " << receptive_field_length;
break; break;
} }

@ -14,8 +14,8 @@
// todo refactor, repalce with gtest // todo refactor, repalce with gtest
#include "decoder/ctc_tlg_decoder.h"
#include "base/common.h" #include "base/common.h"
#include "decoder/ctc_tlg_decoder.h"
#include "decoder/param.h" #include "decoder/param.h"
#include "frontend/data_cache.h" #include "frontend/data_cache.h"
#include "kaldi/util/table-types.h" #include "kaldi/util/table-types.h"

@ -13,12 +13,13 @@
// limitations under the License. // limitations under the License.
#include "nnet/nnet_producer.h" #include "nnet/nnet_producer.h"
#include "matrix/kaldi-matrix.h" #include "matrix/kaldi-matrix.h"
namespace ppspeech { namespace ppspeech {
using std::vector;
using kaldi::BaseFloat; using kaldi::BaseFloat;
using std::vector;
NnetProducer::NnetProducer(std::shared_ptr<NnetBase> nnet, NnetProducer::NnetProducer(std::shared_ptr<NnetBase> nnet,
std::shared_ptr<FrontendInterface> frontend) std::shared_ptr<FrontendInterface> frontend)

@ -13,13 +13,13 @@
// limitations under the License. // limitations under the License.
#include "nnet/u2_nnet.h"
#include "base/common.h" #include "base/common.h"
#include "decoder/param.h" #include "decoder/param.h"
#include "frontend/assembler.h" #include "frontend/assembler.h"
#include "frontend/data_cache.h" #include "frontend/data_cache.h"
#include "kaldi/util/table-types.h" #include "kaldi/util/table-types.h"
#include "nnet/decodable.h" #include "nnet/decodable.h"
#include "nnet/u2_nnet.h"
DEFINE_string(feature_rspecifier, "", "test feature rspecifier"); 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); ori_feature_len - chunk_idx * chunk_stride, chunk_size);
} }
if (this_chunk_size < receptive_field_length) { if (this_chunk_size < receptive_field_length) {
LOG(WARNING) << "utt: " << utt << " skip last " LOG(WARNING)
<< this_chunk_size << " frames, expect is " << "utt: " << utt << " skip last " << this_chunk_size
<< receptive_field_length; << " frames, expect is " << receptive_field_length;
break; break;
} }

@ -13,7 +13,6 @@
// limitations under the License. // limitations under the License.
#include "nnet/u2_nnet.h"
#include "base/common.h" #include "base/common.h"
#include "decoder/param.h" #include "decoder/param.h"
#include "frontend/feature_pipeline.h" #include "frontend/feature_pipeline.h"
@ -21,6 +20,7 @@
#include "kaldi/util/table-types.h" #include "kaldi/util/table-types.h"
#include "nnet/decodable.h" #include "nnet/decodable.h"
#include "nnet/nnet_producer.h" #include "nnet/nnet_producer.h"
#include "nnet/u2_nnet.h"
DEFINE_string(wav_rspecifier, "", "test wav rspecifier"); DEFINE_string(wav_rspecifier, "", "test wav rspecifier");
DEFINE_string(nnet_prob_wspecifier, "", "nnet porb wspecifier"); DEFINE_string(nnet_prob_wspecifier, "", "nnet porb wspecifier");

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "recognizer/u2_recognizer.h"
#include "common/base/thread_pool.h" #include "common/base/thread_pool.h"
#include "common/utils/file_utils.h" #include "common/utils/file_utils.h"
#include "common/utils/strings.h" #include "common/utils/strings.h"
@ -20,6 +19,7 @@
#include "frontend/wave-reader.h" #include "frontend/wave-reader.h"
#include "kaldi/util/table-types.h" #include "kaldi/util/table-types.h"
#include "nnet/u2_nnet.h" #include "nnet/u2_nnet.h"
#include "recognizer/u2_recognizer.h"
DEFINE_string(wav_rspecifier, "", "test feature rspecifier"); DEFINE_string(wav_rspecifier, "", "test feature rspecifier");
DEFINE_string(result_wspecifier, "", "test result wspecifier"); DEFINE_string(result_wspecifier, "", "test result wspecifier");

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "recognizer/u2_recognizer.h"
#include "decoder/param.h" #include "decoder/param.h"
#include "frontend/wave-reader.h" #include "frontend/wave-reader.h"
#include "kaldi/util/table-types.h" #include "kaldi/util/table-types.h"
#include "recognizer/u2_recognizer.h"
DEFINE_string(wav_rspecifier, "", "test feature rspecifier"); DEFINE_string(wav_rspecifier, "", "test feature rspecifier");
DEFINE_string(result_wspecifier, "", "test result wspecifier"); DEFINE_string(result_wspecifier, "", "test result wspecifier");

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "recognizer/u2_recognizer.h"
#include "decoder/param.h" #include "decoder/param.h"
#include "frontend/wave-reader.h" #include "frontend/wave-reader.h"
#include "kaldi/util/table-types.h" #include "kaldi/util/table-types.h"
#include "recognizer/u2_recognizer.h"
DEFINE_string(wav_rspecifier, "", "test feature rspecifier"); DEFINE_string(wav_rspecifier, "", "test feature rspecifier");
DEFINE_string(result_wspecifier, "", "test result wspecifier"); DEFINE_string(result_wspecifier, "", "test result wspecifier");

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "websocket/websocket_client.h"
#include "kaldi/feat/wave-reader.h" #include "kaldi/feat/wave-reader.h"
#include "kaldi/util/kaldi-io.h" #include "kaldi/util/kaldi-io.h"
#include "kaldi/util/table-types.h" #include "kaldi/util/table-types.h"
#include "websocket/websocket_client.h"
DEFINE_string(host, "127.0.0.1", "host of websocket server"); DEFINE_string(host, "127.0.0.1", "host of websocket server");
DEFINE_int32(port, 8082, "port of websocket server"); DEFINE_int32(port, 8082, "port of websocket server");

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "websocket/websocket_server.h"
#include "decoder/param.h" #include "decoder/param.h"
#include "websocket/websocket_server.h"
DEFINE_int32(port, 8082, "websocket listening port"); DEFINE_int32(port, 8082, "websocket listening port");

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include "cls/nnet/panns_interface.h" #include "cls/nnet/panns_interface.h"
#include "cls/nnet/panns_nnet.h" #include "cls/nnet/panns_nnet.h"
#include "common/base/config.h" #include "common/base/config.h"

@ -14,6 +14,7 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
#include "base/flags.h" #include "base/flags.h"
#include "cls/nnet/panns_interface.h" #include "cls/nnet/panns_interface.h"

@ -18,6 +18,9 @@
#pragma once #pragma once
#include <stdlib.h>
#include <unistd.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
@ -25,9 +28,6 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include <stdlib.h>
#include <unistd.h>
#include "base/common.h" #include "base/common.h"
#include "base/macros.h" #include "base/macros.h"
#ifndef WITH_GLOG #ifndef WITH_GLOG

@ -17,9 +17,8 @@
namespace ppspeech { namespace ppspeech {
using kaldi::BaseFloat; using kaldi::BaseFloat;
using std::vector;
using std::vector;
using std::unique_ptr; using std::unique_ptr;
using std::vector;
Assembler::Assembler(AssemblerOptions opts, Assembler::Assembler(AssemblerOptions opts,
unique_ptr<FrontendInterface> base_extractor) { unique_ptr<FrontendInterface> base_extractor) {

@ -17,12 +17,13 @@
*/ */
#include "frontend/rfft.h" #include "frontend/rfft.h"
#include "base/log.h"
#include <cmath> #include <cmath>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "base/log.h"
// see fftsg.c // see fftsg.c
#ifdef __cplusplus #ifdef __cplusplus
extern "C" void rdft(int n, int isgn, double *a, int *ip, double *w); extern "C" void rdft(int n, int isgn, double *a, int *ip, double *w);

@ -19,6 +19,8 @@
// See the Apache 2 License for the specific language governing permissions and // See the Apache 2 License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "frontend/wave-reader.h"
#include <algorithm> #include <algorithm>
#include <cstdio> #include <cstdio>
#include <limits> #include <limits>
@ -27,7 +29,6 @@
#include "base/kaldi-error.h" #include "base/kaldi-error.h"
#include "base/kaldi-utils.h" #include "base/kaldi-utils.h"
#include "frontend/wave-reader.h"
namespace kaldi { namespace kaldi {
@ -243,8 +244,7 @@ void WaveInfo::Read(std::istream &is) {
<< ", data chunk size: " << data_chunk_size << ", data chunk size: " << data_chunk_size
<< ". Assume 'stream mode' (reading data to EOF)."; << ". Assume 'stream mode' (reading data to EOF).";
if (!is_stream_mode && if (!is_stream_mode && std::abs(static_cast<int64>(riff_chunk_read) +
std::abs(static_cast<int64>(riff_chunk_read) +
static_cast<int64>(data_chunk_size) - static_cast<int64>(data_chunk_size) -
static_cast<int64>(riff_chunk_size)) > 1) { static_cast<int64>(riff_chunk_size)) > 1) {
// We allow the size to be off by one without warning, because there is // We allow the size to be off by one without warning, because there is

@ -24,8 +24,10 @@
// limitations under the License. // limitations under the License.
#include "matrix/kaldi-vector.h" #include "matrix/kaldi-vector.h"
#include <algorithm> #include <algorithm>
#include <string> #include <string>
#include "matrix/kaldi-matrix.h" #include "matrix/kaldi-matrix.h"
namespace kaldi { namespace kaldi {

@ -90,7 +90,7 @@ typedef uint32 UnsignedMatrixIndexT;
// typedef size_t MatrixIndexT; // typedef size_t MatrixIndexT;
// typedef ssize_t SignedMatrixIndexT; // typedef ssize_t SignedMatrixIndexT;
// typedef size_t UnsignedMatrixIndexT; // typedef size_t UnsignedMatrixIndexT;
} } // namespace kaldi
#endif // KALDI_MATRIX_MATRIX_COMMON_H_ #endif // KALDI_MATRIX_MATRIX_COMMON_H_

@ -5,3 +5,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/../
add_subdirectory(nnet) add_subdirectory(nnet)
add_subdirectory(interface) add_subdirectory(interface)
if(ANDROID)
add_subdirectory(jni)
endif()

@ -17,6 +17,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <iostream> #include <iostream>
#include <string> #include <string>

@ -2,34 +2,24 @@ set(srcs
vad_interface.cc vad_interface.cc
) )
add_library(vad_interface ${srcs}) add_library(pps_vad_interface ${srcs})
target_link_libraries(vad_interface PUBLIC ${FASTDEPLOY_LIBS} vad extern_glog) target_link_libraries(pps_vad_interface PUBLIC ${FASTDEPLOY_LIBS} pps_vad)
set(bin_name vad_interface_main) set(bin_name vad_interface_main)
add_executable(${bin_name} ${CMAKE_CURRENT_SOURCE_DIR}/${bin_name}.cc) 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") # 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 install(TARGETS vad_interface_main
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION lib LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include PUBLIC_HEADER DESTINATION include/${DEST_DIR}
) )
install(FILES vad_interface_main.cc DESTINATION demo) install(FILES vad_interface_main.cc DESTINATION demo/${DEST_DIR})
# 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)

@ -14,6 +14,7 @@
#include "vad/interface/vad_interface.h" #include "vad/interface/vad_interface.h"
#include "common/base/config.h" #include "common/base/config.h"
#include "vad/nnet/vad.h" #include "vad/nnet/vad.h"

@ -13,10 +13,11 @@
// limitations under the License. // limitations under the License.
#include "vad/interface/vad_interface.h"
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "vad/frontend/wav.h" #include "vad/frontend/wav.h"
#include "vad/interface/vad_interface.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (argc < 3) { if (argc < 3) {

@ -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})

@ -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);
}

@ -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 <jni.h>
#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

@ -2,11 +2,15 @@ set(srcs
vad.cc vad.cc
) )
add_library(vad ${srcs}) add_library(pps_vad ${srcs})
target_link_libraries(vad PUBLIC ${FASTDEPLOY_LIBS} common) target_link_libraries(pps_vad PUBLIC ${FASTDEPLOY_LIBS} common)
set(bin_name vad_nnet_main) set(bin_name vad_nnet_main)
add_executable(${bin_name} ${CMAKE_CURRENT_SOURCE_DIR}/${bin_name}.cc) 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 gflags extern_glog)
target_link_libraries(${bin_name} ${FASTDEPLOY_LIBS} vad) 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)

@ -13,14 +13,15 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "vad/nnet/vad.h" #include "vad/nnet/vad.h"
#include <cstring> #include <cstring>
#include <iomanip> #include <iomanip>
#ifdef NDEBUG #ifdef NDEBUG
#define LOG_DEBUG \ #define LOG_DEBUG \
::fastdeploy::FDLogger(true, "[DEBUG]") << __REL_FILE__ << "(" << __LINE__ \ ::fastdeploy::FDLogger(true, "[DEBUG]") \
<< ")::" << __FUNCTION__ << "\t" << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t"
#else #else
#define LOG_DEBUG \ #define LOG_DEBUG \
::fastdeploy::FDLogger(false, "[DEBUG]") \ ::fastdeploy::FDLogger(false, "[DEBUG]") \
@ -323,4 +324,4 @@ std::ostream& operator<<(std::ostream& os, const Vad::State& s) {
return os; return os;
} }
} // namepsace ppspeech } // namespace ppspeech

@ -17,6 +17,7 @@
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#include "fastdeploy/fastdeploy_model.h" #include "fastdeploy/fastdeploy_model.h"
#include "fastdeploy/runtime.h" #include "fastdeploy/runtime.h"
#include "vad/frontend/wav.h" #include "vad/frontend/wav.h"
@ -149,4 +150,4 @@ class Vad : public fastdeploy::FastDeployModel {
const std::vector<int64_t> hc_node_dims_ = {2, 1, 64}; const std::vector<int64_t> hc_node_dims_ = {2, 1, 64};
}; };
} // namepsace ppspeech } // namespace ppspeech
Loading…
Cancel
Save