Add prebuilt C++ shared library SDK (libopenwakeword_ax) + header for secondary development
Browse files- cpp/lib/ax650|ax630c/libopenwakeword_ax.so: prebuilt shared libraries
- cpp/include/openwakeword_ax.hpp: public API (WakeWordDetector::ProcessFrame)
- cpp/README.md: shared-library usage section
- README.md: 二次开发 section with link snippet
- README.md +22 -0
- cpp/README.md +44 -4
- cpp/include/openwakeword_ax.hpp +45 -0
- cpp/lib/ax630c/libopenwakeword_ax.so +1 -0
- cpp/lib/ax630c/libopenwakeword_ax.so.0 +1 -0
- cpp/lib/ax630c/libopenwakeword_ax.so.0.1.0 +0 -0
- cpp/lib/ax650/libopenwakeword_ax.so +1 -0
- cpp/lib/ax650/libopenwakeword_ax.so.0 +1 -0
- cpp/lib/ax650/libopenwakeword_ax.so.0.1.0 +0 -0
README.md
CHANGED
|
@@ -108,6 +108,28 @@ THRESHOLD=0.5 bash cpp/run_batch_openwakeword_ax630c.sh # AX630C
|
|
| 108 |
结果分别写入 `outputs/cpp_ax650_batch/` 和 `outputs/cpp_ax630c_batch/`。
|
| 109 |
详细 C++ 说明见 `cpp/README.md`。
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
## 参考
|
| 112 |
|
| 113 |
- [openWakeWord](https://github.com/dscripka/openWakeWord)
|
|
|
|
| 108 |
结果分别写入 `outputs/cpp_ax650_batch/` 和 `outputs/cpp_ax630c_batch/`。
|
| 109 |
详细 C++ 说明见 `cpp/README.md`。
|
| 110 |
|
| 111 |
+
### 共享库(二次开发)
|
| 112 |
+
|
| 113 |
+
```text
|
| 114 |
+
cpp/lib/ax650/libopenwakeword_ax.so # AX650 共享库
|
| 115 |
+
cpp/lib/ax630c/libopenwakeword_ax.so # AX630C 共享库
|
| 116 |
+
cpp/include/openwakeword_ax.hpp # 公共 API 头文件
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
```cpp
|
| 120 |
+
#include "openwakeword_ax.hpp"
|
| 121 |
+
|
| 122 |
+
openwakeword::WakeWordDetector detector(
|
| 123 |
+
"models/650", // axmodel 目录
|
| 124 |
+
"config/openwakeword_mel_weights.bin", // CPU mel 权重
|
| 125 |
+
0.5f); // 阈值
|
| 126 |
+
openwakeword::FrameResult result = detector.ProcessFrame(pcm_frame); // 1280 samples
|
| 127 |
+
// result.names / result.max_scores / result.any_triggered
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
板端运行时需提供 BSP 动态库路径(AX650 通常为 `/soc/lib`,AX630C 为
|
| 131 |
+
`/opt/lib`)。共享库源码与构建脚本在 GitHub 仓库。
|
| 132 |
+
|
| 133 |
## 参考
|
| 134 |
|
| 135 |
- [openWakeWord](https://github.com/dscripka/openWakeWord)
|
cpp/README.md
CHANGED
|
@@ -88,9 +88,49 @@ THRESHOLD=0.6 AUDIO=audio/openwakeword/hey_mycroft_test.wav \
|
|
| 88 |
bash cpp/run_openwakeword_ax630c.sh
|
| 89 |
```
|
| 90 |
|
| 91 |
-
##
|
| 92 |
|
| 93 |
-
|
| 94 |
-
https://github.com/AXERA-TECH/openWakeWord.AXERA
|
| 95 |
-
(HuggingFace 仅发布预编译二进制。)
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
bash cpp/run_openwakeword_ax630c.sh
|
| 89 |
```
|
| 90 |
|
| 91 |
+
## 二次开发(共享库)
|
| 92 |
|
| 93 |
+
编译产物除可执行文件外,还包含共享库:
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
```text
|
| 96 |
+
cpp/lib/ax650/libopenwakeword_ax.so # AX650
|
| 97 |
+
cpp/lib/ax630c/libopenwakeword_ax.so # AX630C
|
| 98 |
+
cpp/include/openwakeword_ax.hpp # 公共 API 头文件
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
在自己的 CMake 工程中链接:
|
| 102 |
+
|
| 103 |
+
```cmake
|
| 104 |
+
add_library(openwakeword_ax SHARED IMPORTED)
|
| 105 |
+
set_target_properties(openwakeword_ax PROPERTIES
|
| 106 |
+
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/cpp/lib/ax650/libopenwakeword_ax.so")
|
| 107 |
+
target_include_directories(your_app PRIVATE cpp/include)
|
| 108 |
+
target_link_libraries(your_app PRIVATE openwakeword_ax)
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
最小使用示例:
|
| 112 |
+
|
| 113 |
+
```cpp
|
| 114 |
+
#include "openwakeword_ax.hpp"
|
| 115 |
+
|
| 116 |
+
openwakeword::WakeWordDetector detector(
|
| 117 |
+
"models/650", // axmodel 目录
|
| 118 |
+
"config/openwakeword_mel_weights.bin", // CPU mel 权重
|
| 119 |
+
0.5f); // 阈值
|
| 120 |
+
|
| 121 |
+
// 每 80ms 喂一帧 1280 个 int16 样本(16 kHz)
|
| 122 |
+
openwakeword::FrameResult result = detector.ProcessFrame(pcm_frame);
|
| 123 |
+
for (std::size_t i = 0; i < result.names.size(); ++i) {
|
| 124 |
+
printf("%s max_score=%.4f\n", result.names[i].c_str(),
|
| 125 |
+
result.max_scores[i]);
|
| 126 |
+
}
|
| 127 |
+
if (result.any_triggered) { /* 唤醒 */ }
|
| 128 |
+
detector.Reset(); // 新会话时清空流式状态
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
板端运行时需提供 BSP 动态库路径(AX650 通常为 `/soc/lib`,AX630C 为
|
| 132 |
+
`/opt/lib`):
|
| 133 |
+
|
| 134 |
+
```bash
|
| 135 |
+
export LD_LIBRARY_PATH=/soc/lib:${LD_LIBRARY_PATH}
|
| 136 |
+
```
|
cpp/include/openwakeword_ax.hpp
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <cstdint>
|
| 4 |
+
#include <string>
|
| 5 |
+
#include <vector>
|
| 6 |
+
|
| 7 |
+
namespace openwakeword {
|
| 8 |
+
|
| 9 |
+
// 单帧(80ms)推理结果:6 个官方唤醒词的逐类 logits 与汇总。
|
| 10 |
+
struct FrameResult {
|
| 11 |
+
std::vector<std::string> names; // 分类器名(alexa_v0.1 ...)
|
| 12 |
+
std::vector<std::vector<float>> logits; // 每个分类器的逐类 logit
|
| 13 |
+
std::vector<float> max_scores; // 每个分类器的最大 logit
|
| 14 |
+
bool any_triggered = false; // 任一 max_score > threshold
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
// 流式唤醒词检测器:mel 在 CPU 计算,embedding + 6 个分类器在 NPU 执行。
|
| 18 |
+
class WakeWordDetector {
|
| 19 |
+
public:
|
| 20 |
+
// models_dir:包含 openwakeword__*.axmodel 的目录(models/650 或 models/630C)
|
| 21 |
+
// mel_weights:openwakeword_mel_weights.bin(CPU mel 权重)
|
| 22 |
+
WakeWordDetector(const std::string& models_dir,
|
| 23 |
+
const std::string& mel_weights,
|
| 24 |
+
float threshold = 0.5f);
|
| 25 |
+
~WakeWordDetector();
|
| 26 |
+
|
| 27 |
+
WakeWordDetector(const WakeWordDetector&) = delete;
|
| 28 |
+
WakeWordDetector& operator=(const WakeWordDetector&) = delete;
|
| 29 |
+
|
| 30 |
+
// 清空流式状态(新会话/断句后调用)
|
| 31 |
+
void Reset();
|
| 32 |
+
|
| 33 |
+
// 处理一帧 1280 个 int16 样本(80ms @16kHz),返回 6 个分类器的得分。
|
| 34 |
+
// 前 5 帧为预热窗口(返回 0),与 openwakeword 官方行为一致。
|
| 35 |
+
FrameResult ProcessFrame(const int16_t* samples);
|
| 36 |
+
|
| 37 |
+
float threshold() const { return threshold_; }
|
| 38 |
+
|
| 39 |
+
private:
|
| 40 |
+
struct Impl;
|
| 41 |
+
Impl* impl_;
|
| 42 |
+
float threshold_;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
} // namespace openwakeword
|
cpp/lib/ax630c/libopenwakeword_ax.so
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
libopenwakeword_ax.so.0
|
cpp/lib/ax630c/libopenwakeword_ax.so.0
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
libopenwakeword_ax.so.0.1.0
|
cpp/lib/ax630c/libopenwakeword_ax.so.0.1.0
ADDED
|
Binary file (56.3 kB). View file
|
|
|
cpp/lib/ax650/libopenwakeword_ax.so
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
libopenwakeword_ax.so.0
|
cpp/lib/ax650/libopenwakeword_ax.so.0
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
libopenwakeword_ax.so.0.1.0
|
cpp/lib/ax650/libopenwakeword_ax.so.0.1.0
ADDED
|
Binary file (56.3 kB). View file
|
|
|