diff --git a/runtime/core/bin/stream_kws_main.cc b/runtime/core/bin/stream_kws_main.cc index 22f9d4a..e7dec44 100644 --- a/runtime/core/bin/stream_kws_main.cc +++ b/runtime/core/bin/stream_kws_main.cc @@ -24,25 +24,26 @@ #include "kws/keyword_spotting.h" #include "utils/log.h" -int exiting = 0; -std::shared_ptr feature_pipeline; +int g_exiting = 0; +std::shared_ptr g_feature_pipeline; -void sig_routine(int dunno) { +void SigRoutine(int dunno) { if (dunno == SIGINT) { - exiting = 1; + g_exiting = 1; } } -static int recordCallback(const void* input, void* output, - unsigned long framesCount, // NOLINT - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, void* userData) { +static int RecordCallback(const void* input, void* output, + unsigned long frames_count, // NOLINT + const PaStreamCallbackTimeInfo* time_info, + PaStreamCallbackFlags status_flags, void* user_data) { const auto* pcm_data = static_cast(input); - std::vector v(pcm_data, pcm_data + framesCount); - feature_pipeline->AcceptWaveform(v); + std::vector v(pcm_data, pcm_data + frames_count); + g_feature_pipeline->AcceptWaveform(v); - if (exiting) { + if (g_exiting) { LOG(INFO) << "Exiting loop."; + g_feature_pipeline->set_input_finished(); return paComplete; } else { return paContinue; @@ -58,10 +59,10 @@ int main(int argc, char* argv[]) { const std::string model_path = argv[3]; wenet::FeaturePipelineConfig feature_config(num_bins, 16000); - feature_pipeline = std::make_shared(feature_config); + g_feature_pipeline = std::make_shared(feature_config); wekws::KeywordSpotting spotter(model_path); - signal(SIGINT, sig_routine); + signal(SIGINT, SigRoutine); PaError err = Pa_Initialize(); PaStreamParameters params; std::cout << err << " " << Pa_GetDeviceCount() << std::endl; @@ -79,7 +80,7 @@ int main(int argc, char* argv[]) { int interval = 500; int frames_per_buffer = 16000 / 1000 * interval; Pa_OpenStream(&stream, ¶ms, NULL, 16000, frames_per_buffer, paClipOff, - recordCallback, NULL); + RecordCallback, NULL); Pa_StartStream(stream); LOG(INFO) << "=== Now recording!! Please speak into the microphone. ==="; @@ -87,7 +88,7 @@ int main(int argc, char* argv[]) { while (Pa_IsStreamActive(stream)) { Pa_Sleep(interval); std::vector> feats; - feature_pipeline->Read(batch_size, &feats); + g_feature_pipeline->Read(batch_size, &feats); std::vector> prob; spotter.Forward(feats, &prob); for (int t = 0; t < prob.size(); t++) { diff --git a/runtime/raspberrypi/README.md b/runtime/raspberrypi/README.md new file mode 100644 index 0000000..64e5890 --- /dev/null +++ b/runtime/raspberrypi/README.md @@ -0,0 +1,44 @@ +# WeNet & Raspberry PI + +There are two ways to build the runtime binaries for Raspberry PI. + +1. Refer `runtime/onnxruntime/README.md` to build it in Raspberry PI. +2. Cross compile and `scp` the binaries and libraries to Raspberry PI. + +## Cross Compile + +* Step 1. Install cross compile tools in the PC. + +``` sh +sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu +``` + +Or download, and install the binaries from: https://releases.linaro.org/components/toolchain/binaries/latest-7 + + +* Step 2. Export your experiment model to ONNX by https://github.com/wenet-e2e/wekws/blob/main/wekws/bin/export_onnx.py + +``` sh +exp=exp # Change it to your experiment dir +python -m wekws.bin.export_onnx \ + --config $exp/train.yaml \ + --checkpoint $exp/final.pt \ + --output_dir final.onnx +``` + +* Step 3. Build. The build requires cmake 3.14 or above. and Send the binary and libraries to Raspberry PI. + +``` sh +cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=toolchains/aarch64-linux-gnu.toolchain.cmake +cmake --build build +scp -r build/bin pi@xxx.xxx.xxx:/path/to/wekws +scp fc_base/onnxruntime-src/lib/libonnxruntime.so* pi@xxx.xxx.xxx:/path/to/wekws +``` + +* Step 4. Run. The log will be shown in Raspberry PI's console. + +``` sh +cd /path/to/wekws +export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH +./build/bin/stream_kws_main 40 80 final.onnx +```