Ziyi Lin
commited on
Commit
·
b743710
1
Parent(s):
a81d5c4
Upload materials part 1
Browse files- LICENSE +43 -0
- README.md +399 -3
- include/__pycache__/ten_vad.cpython-310.pyc +0 -0
- include/ten_vad.h +84 -0
- include/ten_vad.py +101 -0
- requirements.txt +5 -0
- setup.py +23 -0
LICENSE
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Open Source License
|
| 2 |
+
|
| 3 |
+
The ten-vad is licensed pursuant to the Apache License v2.0, with the
|
| 4 |
+
following additional conditions. You may reproduce, prepare Derivative Works
|
| 5 |
+
of, publicly display, publicly perform, sublicense, distribute, or otherwise
|
| 6 |
+
make available (together, "Deploy") the ten-vad, for commercial or
|
| 7 |
+
non-commercial purposes, provided that you agree to abide by the terms below:
|
| 8 |
+
|
| 9 |
+
1. You may not (i) host the ten-vad or the Derivative Works on any End
|
| 10 |
+
User devices, including but not limited to any mobile terminal devices
|
| 11 |
+
or (ii) Deploy the ten-vad in a way that competes with Agora's
|
| 12 |
+
offerings and/or that allows others to compete with Agora's offerings,
|
| 13 |
+
including without limitation enabling any third party to develop or
|
| 14 |
+
deploy Applications.
|
| 15 |
+
|
| 16 |
+
2. You may Deploy the ten-vad solely to create and enable deployment
|
| 17 |
+
of your Application(s) solely for your benefit and the benefit of your
|
| 18 |
+
direct End Users. If you prefer, you may include the following notice in
|
| 19 |
+
the documentation of your Application(s): "Powered by ten-vad".
|
| 20 |
+
|
| 21 |
+
3. Derivative Works of the ten-vad remain subject to this Open Source
|
| 22 |
+
License.
|
| 23 |
+
|
| 24 |
+
4. "End Users" shall mean the end-users of your Application(s) who access
|
| 25 |
+
the ten-vad solely to the extent necessary to access and use the
|
| 26 |
+
Application(s) you create or deploy using ten-vad.
|
| 27 |
+
|
| 28 |
+
5. "Application(s)" shall mean your software programs designed or developed
|
| 29 |
+
by using the ten-vad or where deployment is enabled by the ten-vad.
|
| 30 |
+
|
| 31 |
+
Copyright © 2025 Agora
|
| 32 |
+
|
| 33 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 34 |
+
you may not use this file except in compliance with the License.
|
| 35 |
+
You may obtain a copy of the License at
|
| 36 |
+
|
| 37 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 38 |
+
|
| 39 |
+
Unless required by applicable law or agreed to in writing, software
|
| 40 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 41 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 42 |
+
See the License for the specific language governing permissions and
|
| 43 |
+
limitations under the License.
|
README.md
CHANGED
|
@@ -1,3 +1,399 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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+
|
| 6 |
+
|
| 7 |
+
## **Introduction**
|
| 8 |
+
**TEN VAD** is a real-time voice activity detection system designed for enterprise use, providing accurate frame-level speech activity detection. It shows superior precision compared to both WebRTC VAD and Silero VAD, which are commonly used in the industry. Additionally, TEN VAD offers lower computational complexity and reduced memory usage compared to Silero VAD. Meanwhile, the architecture's temporal efficiency enables rapid voice activity detection, significantly reducing end-to-end response and turn detection latency in conversational AI systems.
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
## **Key Features**
|
| 13 |
+
|
| 14 |
+
### **1. High-Performance:**
|
| 15 |
+
|
| 16 |
+
The precision-recall curves comparing the performance of WebRTC VAD (pitch-based), Silero VAD, and TEN VAD are shown below. The evaluation is conducted on the precisely manually annotated TEN-VAD-TestSet. The audio files are from librispeech, gigaspeech, DNS Challenge etc. As demonstrated, TEN VAD achieves the best performance. Additionally, cross-validation experiments conducted on large internal real-world datasets demonstrate the reproducibility of these findings. The **TEN-VAD-TestSet with annotated labels** is released in directory "TEN-VAD-TestSet" of this repository.
|
| 17 |
+
|
| 18 |
+
<br>
|
| 19 |
+
|
| 20 |
+
<div style="text-align:">
|
| 21 |
+
<img src="./images/PR_Curves_TEN-VAD-TestSet.png" width="800">
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
Note that the default threshold of 0.5 is used to generate binary speech indicators (0 for non-speech signal, 1 for speech signal). This threshold needs to be tuned according to your domain-specific task. The precision-recall curve can be obtained by executing the following script on Linux x64. The output figure will be saved in the same directory as the script. Note that only PR curves of Silero VAD and TEN VAD are plotted, we did not plot the one of WebRTC VAD, which is used in the latese version of WebRTC.
|
| 25 |
+
|
| 26 |
+
```
|
| 27 |
+
cd ./examples
|
| 28 |
+
python plot_pr_curves.py
|
| 29 |
+
```
|
| 30 |
+
<br>
|
| 31 |
+
|
| 32 |
+
### **2. Agent-Friendly:**
|
| 33 |
+
As illustrated in the figure below, TEN VAD rapidly detects speech-to-non-speech transitions, whereas Silero VAD suffers from a delay of several hundred milliseconds, resulting in increased end-to-end latency in human-agent interaction systems. In addition, as demonstrated in the 6.5s-7.0s audio segment, Silero VAD fails to identify short silent durations between adjacent speech segments.
|
| 34 |
+
<div style="text-align:">
|
| 35 |
+
<img src="./images/Agent-Friendly-image.png" width="800">
|
| 36 |
+
</div>
|
| 37 |
+
<br>
|
| 38 |
+
|
| 39 |
+
### **3. Lightweight:**
|
| 40 |
+
We evaluated the RTF (Real-Time Factor) across five distinct platforms, each equipped with varying CPUs. TEN VAD demonstrates much lower computational complexity and smaller library size than Silero VAD.
|
| 41 |
+
|
| 42 |
+
<table>
|
| 43 |
+
<tr>
|
| 44 |
+
<th align="center" rowspan="2" valign="middle"> Platform </th>
|
| 45 |
+
<th align="center" rowspan="2" valign="middle"> CPU </th>
|
| 46 |
+
<th align="center" colspan="2"> RTF </th>
|
| 47 |
+
<th align="center" colspan="2"> Lib Size </th>
|
| 48 |
+
</tr>
|
| 49 |
+
<tr>
|
| 50 |
+
<th align="center" style="white-space: nowrap;"> TEN VAD </th>
|
| 51 |
+
<th align="center" style="white-space: nowrap;"> Silero VAD </th>
|
| 52 |
+
<th align="center"> TEN VAD </th>
|
| 53 |
+
<th align="center"> Silero VAD </th>
|
| 54 |
+
</tr>
|
| 55 |
+
<tr>
|
| 56 |
+
<th align="center" rowspan="3"> Linux </th>
|
| 57 |
+
<td style="white-space: nowrap;"> AMD Ryzen 9 5900X 12-Core </td>
|
| 58 |
+
<td align="center"> 0.0150 </td>
|
| 59 |
+
<td rowspan="2" style="text-align: center; vertical-align: middle;"> / </td>
|
| 60 |
+
<td rowspan="3" style="text-align: center; vertical-align: middle;"> 306KB </td>
|
| 61 |
+
<td rowspan="9" style="text-align: center; vertical-align: middle;"> 2.16MB(JIT) / 2.22MB(ONNX) </td>
|
| 62 |
+
</tr>
|
| 63 |
+
<tr>
|
| 64 |
+
<td style="white-space: nowrap;"> Intel(R) Xeon(R) Platinum 8253 </td>
|
| 65 |
+
<td align="center"> 0.0136 </td>
|
| 66 |
+
</tr>
|
| 67 |
+
<tr>
|
| 68 |
+
<td style="white-space: nowrap;"> Intel(R) Xeon(R) Gold 6348 CPU @ 2.60GHz </td>
|
| 69 |
+
<td align="center"> 0.0086 </td>
|
| 70 |
+
<td align="center"> 0.0127 </td>
|
| 71 |
+
</tr>
|
| 72 |
+
<tr>
|
| 73 |
+
<th align="center"> Windows </th>
|
| 74 |
+
<td> Intel i7-10710U </td>
|
| 75 |
+
<td align="center"> 0.0150 </td>
|
| 76 |
+
<td rowspan="6" style="text-align: center; vertical-align: middle;"> / </td>
|
| 77 |
+
<td align="center" style="white-space: nowrap;"> 464KB(x86) / 508KB(x64) </td>
|
| 78 |
+
</tr>
|
| 79 |
+
<tr>
|
| 80 |
+
<th align="center"> macOS </th>
|
| 81 |
+
<td> M1 </td>
|
| 82 |
+
<td align="center"> 0.0160 </td>
|
| 83 |
+
<td align="center"> 731KB </td>
|
| 84 |
+
</tr>
|
| 85 |
+
<tr>
|
| 86 |
+
<th align="center" rowspan="2"> Android </th>
|
| 87 |
+
<td> Galaxy J6+ (32bit, 425) </td>
|
| 88 |
+
<td align="center"> 0.0570 </td>
|
| 89 |
+
<td rowspan="2" style="white-space: nowrap;" style="text-align: center; vertical-align: middle;"> 373KB(v7a) / 532KB(v8a)</td>
|
| 90 |
+
</tr>
|
| 91 |
+
<tr>
|
| 92 |
+
<td> Oppo A3s (450) </td>
|
| 93 |
+
<td align="center"> 0.0490 </td>
|
| 94 |
+
</tr>
|
| 95 |
+
<tr>
|
| 96 |
+
<th align="center" rowspan="2"> iOS </th>
|
| 97 |
+
<td> iPhone6 (A8) </td>
|
| 98 |
+
<td align="center"> 0.0210 </td>
|
| 99 |
+
<td rowspan="2" style="text-align: center; vertical-align: middle;"> 320KB</td>
|
| 100 |
+
</tr>
|
| 101 |
+
<tr>
|
| 102 |
+
<td> iPhone8 (A11) </td>
|
| 103 |
+
<td align="center"> 0.0050 </td>
|
| 104 |
+
</tr>
|
| 105 |
+
</table>
|
| 106 |
+
|
| 107 |
+
<style>
|
| 108 |
+
th, td {
|
| 109 |
+
border: 1px solid #ddd;
|
| 110 |
+
padding: 8px;
|
| 111 |
+
}
|
| 112 |
+
</style>
|
| 113 |
+
<br>
|
| 114 |
+
|
| 115 |
+
### **4. Multiple programming languages and platforms:**
|
| 116 |
+
TEN VAD provides cross-platform C compatibility across five operating systems (Linux x64, Windows, macOS, Android, iOS), with Python bindings optimized for Linux x64.
|
| 117 |
+
<br>
|
| 118 |
+
<br>
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
### **5. Supproted sampling rate and hop size:**
|
| 122 |
+
TEN VAD operates on 16kHz audio input with configurable hop sizes (optimized frame configurations: 160/256 samples=10/16ms). Other sampling rates must be resampled to 16kHz.
|
| 123 |
+
<br>
|
| 124 |
+
<br>
|
| 125 |
+
|
| 126 |
+
## **Installation**
|
| 127 |
+
```
|
| 128 |
+
git clone https://huggingface.co/TEN-framework/ten-vad
|
| 129 |
+
```
|
| 130 |
+
<br>
|
| 131 |
+
|
| 132 |
+
## **Quick Start**
|
| 133 |
+
The project supports five major platforms with dynamic library linking.
|
| 134 |
+
<table>
|
| 135 |
+
<tr>
|
| 136 |
+
<th align="center"> Platform </th>
|
| 137 |
+
<th align="center"> Dynamic Lib </th>
|
| 138 |
+
<th align="center"> Supported Arch </th>
|
| 139 |
+
<th align="center"> Interface Language </th>
|
| 140 |
+
<th align="center"> Header </th>
|
| 141 |
+
<th align="center"> Comment </v>
|
| 142 |
+
</tr>
|
| 143 |
+
<tr>
|
| 144 |
+
<th align="center"> Linux </th>
|
| 145 |
+
<td align="center"> libten_vad.so </td>
|
| 146 |
+
<td align="center"> x64 </td>
|
| 147 |
+
<td align="center"> Python, C </td>
|
| 148 |
+
<td rowspan="5" style="text-align: center; vertical-align: middle;">ten_vad.h <br> ten_vad.py</td>
|
| 149 |
+
<td> </td>
|
| 150 |
+
</tr>
|
| 151 |
+
<tr>
|
| 152 |
+
<th align="center"> Windows </th>
|
| 153 |
+
<td align="center"> ten_vad.dll </td>
|
| 154 |
+
<td align="center"> x64, x86 </td>
|
| 155 |
+
<td align="center"> C </td>
|
| 156 |
+
<td> </td>
|
| 157 |
+
</tr>
|
| 158 |
+
<tr>
|
| 159 |
+
<th align="center"> macOS </th>
|
| 160 |
+
<td align="center"> ten_vad.framework </td>
|
| 161 |
+
<td align="center"> arm64, x86_64 </td>
|
| 162 |
+
<td align="center"> C </td>
|
| 163 |
+
<td> </td>
|
| 164 |
+
</tr>
|
| 165 |
+
<tr>
|
| 166 |
+
<th align="center"> Android </th>
|
| 167 |
+
<td align="center"> libten_vad.so </td>
|
| 168 |
+
<td align="center"> arm64-v8a, armeabi-v7a </td>
|
| 169 |
+
<td align="center"> C </td>
|
| 170 |
+
<td> </td>
|
| 171 |
+
</tr>
|
| 172 |
+
<tr>
|
| 173 |
+
<th align="center"> iOS </th>
|
| 174 |
+
<td align="center" style="text-align: center; vertical-align: middle;"> ten_vad.framework </td>
|
| 175 |
+
<td align="center" style="text-align: center; vertical-align: middle;"> arm64 </td>
|
| 176 |
+
<td align="center"> C </td>
|
| 177 |
+
<td> 1. not simulator <br> 2. not iPad </td>
|
| 178 |
+
</tr>
|
| 179 |
+
</table>
|
| 180 |
+
<br>
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
### **Python Usage**
|
| 184 |
+
#### **1. Linux**
|
| 185 |
+
#### **Requirements**
|
| 186 |
+
- numpy (Version 1.17.4/1.26.4 verified)
|
| 187 |
+
- scipy (Version 1.4.1/1.13.1 verified)
|
| 188 |
+
- scikit-learn (Version 1.2.2/1.5.0 verified, for plotting PR curves)
|
| 189 |
+
- matplotlib (Version 3.1.3/3.10.0 verified, for plotting PR curves)
|
| 190 |
+
- torchaudio (Version 2.2.2 verified, for plotting PR curves)
|
| 191 |
+
|
| 192 |
+
- Python version 3.8.19/3.10.14 verified
|
| 193 |
+
|
| 194 |
+
Note: You could use other versions of above packages, but we didn't test other versions.
|
| 195 |
+
|
| 196 |
+
You can install the above mentioned dependencies via requirements.txt:
|
| 197 |
+
|
| 198 |
+
```
|
| 199 |
+
pip install -r requirements.txt
|
| 200 |
+
```
|
| 201 |
+
<br>
|
| 202 |
+
|
| 203 |
+
#### **Usage**
|
| 204 |
+
Note: For usage in python, you can either use it by **git clone** or **pip**.
|
| 205 |
+
|
| 206 |
+
##### **By using git clone:**
|
| 207 |
+
|
| 208 |
+
1. Clone the repository
|
| 209 |
+
```
|
| 210 |
+
git clone https://huggingface.co/TEN-framework/ten-vad
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
2. Enter examples directory
|
| 214 |
+
```
|
| 215 |
+
cd ./examples
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
3. Test
|
| 219 |
+
```
|
| 220 |
+
python test.py s0724-s0730.wav out.txt
|
| 221 |
+
```
|
| 222 |
+
<br>
|
| 223 |
+
|
| 224 |
+
##### **By using pip:**
|
| 225 |
+
|
| 226 |
+
1. Install via pip
|
| 227 |
+
|
| 228 |
+
```
|
| 229 |
+
pip install -U --force-reinstall -v git+https://huggingface.co/TEN-framework/ten-vad
|
| 230 |
+
```
|
| 231 |
+
|
| 232 |
+
2. Write your own use cases and import the class, the attributes of class TenVAD you can refer to ten_vad.py
|
| 233 |
+
|
| 234 |
+
```
|
| 235 |
+
from ten_vad import TenVad
|
| 236 |
+
```
|
| 237 |
+
<br>
|
| 238 |
+
|
| 239 |
+
### **C Usage**
|
| 240 |
+
#### **Build Scripts**
|
| 241 |
+
Located in examples/ directory:
|
| 242 |
+
|
| 243 |
+
- Linux: build-and-deploy-linux.sh
|
| 244 |
+
- Windows: build-and-deploy-windows.bat
|
| 245 |
+
- macOS: build-and-deploy-mac.sh
|
| 246 |
+
- Android: build-and-deploy-android.sh
|
| 247 |
+
- iOS: build-and-deploy-ios.sh
|
| 248 |
+
|
| 249 |
+
#### **Dynamic Library Configuration**
|
| 250 |
+
Runtime library path configuration:
|
| 251 |
+
- Linux/Android: LD_LIBRARY_PATH
|
| 252 |
+
- macOS: DYLD_FRAMEWORK_PATH
|
| 253 |
+
- Windows: DLL in executable directory or system PATH
|
| 254 |
+
|
| 255 |
+
#### **Customization**
|
| 256 |
+
- Modify platform-specific build scripts
|
| 257 |
+
- Adjust CMakeLists.txt
|
| 258 |
+
- Configure toolchain and architecture settings
|
| 259 |
+
|
| 260 |
+
#### **Overview of Usage**
|
| 261 |
+
- Navigate to examples/
|
| 262 |
+
- Execute platform-specific build script
|
| 263 |
+
- Configure dynamic library path
|
| 264 |
+
- Run demo with sample audio s0724-s0730.wav
|
| 265 |
+
- Processed results saved to out.txt
|
| 266 |
+
|
| 267 |
+
<br>
|
| 268 |
+
|
| 269 |
+
The detailed usage methods of each platform are as follows <br>
|
| 270 |
+
|
| 271 |
+
#### **1. Linux**
|
| 272 |
+
##### **Requirements**
|
| 273 |
+
- Clang (e.g. 6.0.0-1ubuntu2 verified)
|
| 274 |
+
- CMake
|
| 275 |
+
- Terminal
|
| 276 |
+
|
| 277 |
+
##### **Usage**
|
| 278 |
+
```
|
| 279 |
+
1) cd ./examples
|
| 280 |
+
2) ./build-and-deploy-linux.sh
|
| 281 |
+
```
|
| 282 |
+
<br>
|
| 283 |
+
|
| 284 |
+
#### **2. Windows**
|
| 285 |
+
##### **Requirements**
|
| 286 |
+
- Visual Studio (2017, 2019, 2022 verified)
|
| 287 |
+
- CMake (3.26.0-rc6 verified)
|
| 288 |
+
- Terminal (MINGW64 or powershell)
|
| 289 |
+
|
| 290 |
+
##### **Usage**
|
| 291 |
+
```
|
| 292 |
+
1) cd ./examples
|
| 293 |
+
2) Configure "build-and-deploy-windows.bat" with your preferred:
|
| 294 |
+
- Architecture (default: x64)
|
| 295 |
+
- Visual Studio version (default: 2019)
|
| 296 |
+
3) ./build-and-deploy-windows.bat
|
| 297 |
+
```
|
| 298 |
+
<br>
|
| 299 |
+
|
| 300 |
+
#### **3. macOS**
|
| 301 |
+
##### **Requirements**
|
| 302 |
+
- Xcode (15.2 verified)
|
| 303 |
+
- CMake (3.19.2 verified)
|
| 304 |
+
|
| 305 |
+
##### **Usage**
|
| 306 |
+
```
|
| 307 |
+
1) cd ./examples
|
| 308 |
+
2) Configure "build-and-deploy-mac.sh" with your target architecture:
|
| 309 |
+
- Default: arm64 (Apple Silicon)
|
| 310 |
+
- Alternative: x86_64 (Intel)
|
| 311 |
+
3) ./build-and-deploy-mac.sh
|
| 312 |
+
```
|
| 313 |
+
<br>
|
| 314 |
+
|
| 315 |
+
#### **4. Android**
|
| 316 |
+
##### **Requirements**
|
| 317 |
+
- NDK (r25b, macOS verified)
|
| 318 |
+
- CMake (3.19.2, macOS verified)
|
| 319 |
+
- adb (1.0.41, macOS verified)
|
| 320 |
+
|
| 321 |
+
##### **Usage**
|
| 322 |
+
```
|
| 323 |
+
1) cd ./examples
|
| 324 |
+
2) export ANDROID_NDK=/path/to/android-ndk # Replace it with your NDK installation path
|
| 325 |
+
3) Configure "build-and-deploy-android.sh" with your build settings:
|
| 326 |
+
- Architecture: arm64-v8a (default) or armeabi-v7a
|
| 327 |
+
- Toolchain: aarch64-linux-android-clang (default) or custom NDK toolchain
|
| 328 |
+
4) ./build-and-deploy-android.sh
|
| 329 |
+
```
|
| 330 |
+
<br>
|
| 331 |
+
|
| 332 |
+
#### **5. iOS**
|
| 333 |
+
##### **Requirements**
|
| 334 |
+
Xcode (15.2, macOS verified)
|
| 335 |
+
CMake (3.19.2, macOS verified)
|
| 336 |
+
##### **Usage**
|
| 337 |
+
1. Enter examples directory
|
| 338 |
+
```
|
| 339 |
+
cd ./examples
|
| 340 |
+
```
|
| 341 |
+
|
| 342 |
+
2. Creates Xcode project files for iOS build
|
| 343 |
+
```
|
| 344 |
+
./build-and-deploy-ios.sh
|
| 345 |
+
```
|
| 346 |
+
|
| 347 |
+
3. Follow the steps below to build and test on iOS device:
|
| 348 |
+
|
| 349 |
+
3.1. Use Xcode to open .xcodeproj files: a) cd ./build-ios, b) open ./ten_vad_demo.xcodeproj
|
| 350 |
+
|
| 351 |
+
3.2. In Xcode IDE, select ten_vad_demo target (should check: Edit Scheme → Run → Release), then select your iOS Device (not simulator).
|
| 352 |
+
|
| 353 |
+
<div style="text-align:">
|
| 354 |
+
<img src="./images/ios_image_1.jpg" width="800">
|
| 355 |
+
</div>
|
| 356 |
+
|
| 357 |
+
3.3. Drag ten_vad/lib/iOS/ten_vad.framework to "Frameworks, Libraries, and Embedded Content"
|
| 358 |
+
|
| 359 |
+
- (in TARGETS → ten_vad_demo → ten_vad_demo → General, should set Embed to "Embed & Sign").
|
| 360 |
+
|
| 361 |
+
- or add it directly in this way: "Frameworks, Libraries, and Embedded Content" → "+" → Add Other... → Add Files →...
|
| 362 |
+
|
| 363 |
+
- Note: If this step is not completed, you may encounter the following runtime error: "dyld: Library not loaded: @rpath/ten_vad.framework/ten_vad".
|
| 364 |
+
|
| 365 |
+
<div style="text-align:">
|
| 366 |
+
<img src="./images/ios_image_2.png" width="800">
|
| 367 |
+
</div>
|
| 368 |
+
|
| 369 |
+
3.4. Configure iOS device Signature
|
| 370 |
+
|
| 371 |
+
- in TARGETS → ten_vad_demo → Signing & Capabilities → Signing
|
| 372 |
+
|
| 373 |
+
- Modify Bundle Identifier: modify "com.yourcompany" to yours;
|
| 374 |
+
|
| 375 |
+
- Specify Provisioning Profile
|
| 376 |
+
|
| 377 |
+
- In TARGETS → ten_vad_demo → Build Settings → Signing → Code Signing Identity:
|
| 378 |
+
- Specify your Certification
|
| 379 |
+
|
| 380 |
+
3.5. Build in Xcode and run demo on your device.
|
| 381 |
+
<br>
|
| 382 |
+
|
| 383 |
+
## **Citations**
|
| 384 |
+
```
|
| 385 |
+
@misc{TEN VAD,
|
| 386 |
+
author = {TEN Team},
|
| 387 |
+
title = {TEN VAD: A Low-Latency, Lightweight and High-Performance Streaming Voice Activity Detector (VAD)},
|
| 388 |
+
year = {2025},
|
| 389 |
+
publisher = {GitHub},
|
| 390 |
+
journal = {GitHub repository},
|
| 391 |
+
howpublished = {https://github.com/TEN-framework/ten-vad.git},
|
| 392 |
+
commit = {insert_some_commit_here},
|
| 393 |
+
email = {TODO}
|
| 394 |
+
}
|
| 395 |
+
```
|
| 396 |
+
<br>
|
| 397 |
+
|
| 398 |
+
## **License**
|
| 399 |
+
This project is Apache 2.0 licensed.
|
include/__pycache__/ten_vad.cpython-310.pyc
ADDED
|
Binary file (2.62 kB). View file
|
|
|
include/ten_vad.h
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
//
|
| 2 |
+
// This file is part of TEN Framework, an open source project.
|
| 3 |
+
// Licensed under the Apache License, Version 2.0.
|
| 4 |
+
// See the LICENSE file for more information.
|
| 5 |
+
//
|
| 6 |
+
#ifndef TEN_VAD_H
|
| 7 |
+
#define TEN_VAD_H
|
| 8 |
+
|
| 9 |
+
#if defined(__APPLE__) || defined(__ANDROID__) || defined(__linux__)
|
| 10 |
+
#define TENVAD_API __attribute__((visibility("default")))
|
| 11 |
+
#elif defined(_WIN32) || defined(__CYGWIN__)
|
| 12 |
+
#ifdef TENVAD_EXPORTS
|
| 13 |
+
#define TENVAD_API __declspec(dllexport)
|
| 14 |
+
#else
|
| 15 |
+
#define TENVAD_API __declspec(dllimport)
|
| 16 |
+
#endif
|
| 17 |
+
#else
|
| 18 |
+
#define TENVAD_API
|
| 19 |
+
#endif
|
| 20 |
+
|
| 21 |
+
#include <stddef.h> /* size_t */
|
| 22 |
+
#include <stdint.h> /* int16_t */
|
| 23 |
+
|
| 24 |
+
#ifdef __cplusplus
|
| 25 |
+
extern "C"
|
| 26 |
+
{
|
| 27 |
+
#endif
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* @typedef ten_vad_handle
|
| 31 |
+
* @brief Opaque handle for ten_vad instance.
|
| 32 |
+
*/
|
| 33 |
+
typedef void *ten_vad_handle_t;
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* @brief Create and initialize a ten_vad instance.
|
| 37 |
+
*
|
| 38 |
+
* @param[out] handle Pointer to receive the vad handle.
|
| 39 |
+
* @param[in] hop_size The number of samples between the start points of
|
| 40 |
+
* two consecutive analysis frames. (e.g., 256).
|
| 41 |
+
* @param[in] threshold VAD detection threshold ranging from [0.0, 1.0]
|
| 42 |
+
* (default: 0.5).
|
| 43 |
+
* @return 0 on success, or -1 error occurs.
|
| 44 |
+
*/
|
| 45 |
+
TENVAD_API int ten_vad_create(ten_vad_handle_t *handle, size_t hop_size,
|
| 46 |
+
float threshold);
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* @brief Process one audio frame for voice activity detection.
|
| 50 |
+
* Must call ten_vad_init() before calling this, and ten_vad_destroy() when done.
|
| 51 |
+
*
|
| 52 |
+
* @param[in] handle Valid VAD handle returned by ten_vad_create().
|
| 53 |
+
* @param[in] audio_data Pointer to an array of int16_t samples,
|
| 54 |
+
* buffer length must equal the hop size specified at ten_vad_create.
|
| 55 |
+
* @param[in] audio_data_length size of audio_data buffer, here should be equal to hop_size.
|
| 56 |
+
* @param[out] out_probability Pointer to a float (size 1) that receives the
|
| 57 |
+
* voice activity probability in the range [0.0, 1.0].
|
| 58 |
+
* @param[out] out_flag Pointer to an int (size 1) that receives the
|
| 59 |
+
* detection result: 0 = no voice, 1 = voice detected.
|
| 60 |
+
* @return 0 on success, or -1 error occurs.
|
| 61 |
+
*/
|
| 62 |
+
TENVAD_API int ten_vad_process(ten_vad_handle_t handle, const int16_t *audio_data, size_t audio_data_length,
|
| 63 |
+
float *out_probability, int *out_flag);
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* @brief Destroy a ten_vad instance and release its resources.
|
| 67 |
+
*
|
| 68 |
+
* @param[in,out] handle Pointer to the ten_vad handle; set to NULL on return.
|
| 69 |
+
* @return 0 on success, or -1 error occurs.
|
| 70 |
+
*/
|
| 71 |
+
TENVAD_API int ten_vad_destroy(ten_vad_handle_t *handle);
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* @brief Get the ten_vad library version string.
|
| 75 |
+
*
|
| 76 |
+
* @return The version string (e.g., "1.0.0").
|
| 77 |
+
*/
|
| 78 |
+
TENVAD_API const char *ten_vad_get_version(void);
|
| 79 |
+
|
| 80 |
+
#ifdef __cplusplus
|
| 81 |
+
}
|
| 82 |
+
#endif
|
| 83 |
+
|
| 84 |
+
#endif /* TEN_VAD_H */
|
include/ten_vad.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of TEN Framework, an open source project.
|
| 3 |
+
# Licensed under the Apache License, Version 2.0.
|
| 4 |
+
# See the LICENSE file for more information.
|
| 5 |
+
#
|
| 6 |
+
from ctypes import c_int, c_int32, c_float, c_size_t, CDLL, c_void_p, POINTER
|
| 7 |
+
import numpy as np
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
class TenVad:
|
| 11 |
+
def __init__(self, hop_size: int = 256, threshold: float = 0.5):
|
| 12 |
+
self.hop_size = hop_size
|
| 13 |
+
self.threshold = threshold
|
| 14 |
+
if os.path.exists(
|
| 15 |
+
os.path.join(
|
| 16 |
+
os.path.dirname(os.path.relpath(__file__)),
|
| 17 |
+
"../lib/Linux/x64/libten_vad.so",
|
| 18 |
+
)
|
| 19 |
+
):
|
| 20 |
+
self.vad_library = CDLL(
|
| 21 |
+
os.path.join(
|
| 22 |
+
os.path.dirname(os.path.relpath(__file__)),
|
| 23 |
+
"../lib/Linux/x64/libten_vad.so",
|
| 24 |
+
)
|
| 25 |
+
)
|
| 26 |
+
else:
|
| 27 |
+
self.vad_library = CDLL(
|
| 28 |
+
os.path.join(
|
| 29 |
+
os.path.dirname(
|
| 30 |
+
os.path.relpath(__file__)),
|
| 31 |
+
"./ten_vad_library/libten_vad.so",
|
| 32 |
+
)
|
| 33 |
+
)
|
| 34 |
+
self.vad_handler = c_void_p(0)
|
| 35 |
+
self.out_probability = c_float()
|
| 36 |
+
self.out_flags = c_int32()
|
| 37 |
+
|
| 38 |
+
self.vad_library.ten_vad_create.argtypes = [
|
| 39 |
+
POINTER(c_void_p),
|
| 40 |
+
c_size_t,
|
| 41 |
+
c_float,
|
| 42 |
+
]
|
| 43 |
+
self.vad_library.ten_vad_create.restype = c_int
|
| 44 |
+
|
| 45 |
+
self.vad_library.ten_vad_destroy.argtypes = [POINTER(c_void_p)]
|
| 46 |
+
self.vad_library.ten_vad_destroy.restype = c_int
|
| 47 |
+
|
| 48 |
+
self.vad_library.ten_vad_process.argtypes = [
|
| 49 |
+
c_void_p,
|
| 50 |
+
c_void_p,
|
| 51 |
+
c_size_t,
|
| 52 |
+
POINTER(c_float),
|
| 53 |
+
POINTER(c_int32),
|
| 54 |
+
]
|
| 55 |
+
self.vad_library.ten_vad_process.restype = c_int
|
| 56 |
+
self.create_and_init_handler()
|
| 57 |
+
|
| 58 |
+
def create_and_init_handler(self):
|
| 59 |
+
assert (
|
| 60 |
+
self.vad_library.ten_vad_create(
|
| 61 |
+
POINTER(c_void_p)(self.vad_handler),
|
| 62 |
+
c_size_t(self.hop_size),
|
| 63 |
+
c_float(self.threshold),
|
| 64 |
+
)
|
| 65 |
+
== 0
|
| 66 |
+
), "[TEN VAD]: create handler failure!"
|
| 67 |
+
|
| 68 |
+
def __del__(self):
|
| 69 |
+
assert (
|
| 70 |
+
self.vad_library.ten_vad_destroy(
|
| 71 |
+
POINTER(c_void_p)(self.vad_handler)
|
| 72 |
+
)
|
| 73 |
+
== 0
|
| 74 |
+
), "[TEN VAD]: destroy handler failure!"
|
| 75 |
+
|
| 76 |
+
def get_input_data(self, audio_data: np.ndarray):
|
| 77 |
+
audio_data = np.squeeze(audio_data)
|
| 78 |
+
assert (
|
| 79 |
+
len(audio_data.shape) == 1
|
| 80 |
+
and audio_data.shape[0] == self.hop_size
|
| 81 |
+
), "[TEN VAD]: audio data shape should be [%d]" % (
|
| 82 |
+
self.hop_size
|
| 83 |
+
)
|
| 84 |
+
assert (
|
| 85 |
+
type(audio_data[0]) == np.int16
|
| 86 |
+
), "[TEN VAD]: audio data type error, must be int16"
|
| 87 |
+
data_pointer = audio_data.__array_interface__["data"][0]
|
| 88 |
+
return c_void_p(data_pointer)
|
| 89 |
+
|
| 90 |
+
def process(self, audio_data: np.ndarray):
|
| 91 |
+
input_pointer = self.get_input_data(audio_data)
|
| 92 |
+
self.vad_library.ten_vad_process(
|
| 93 |
+
self.vad_handler,
|
| 94 |
+
input_pointer,
|
| 95 |
+
c_size_t(self.hop_size),
|
| 96 |
+
POINTER(c_float)(self.out_probability),
|
| 97 |
+
POINTER(c_int32)(self.out_flags),
|
| 98 |
+
)
|
| 99 |
+
return self.out_probability.value, self.out_flags.value
|
| 100 |
+
|
| 101 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
scipy
|
| 3 |
+
scikit-learn
|
| 4 |
+
matplotlib
|
| 5 |
+
torchaudio
|
setup.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from setuptools import setup
|
| 2 |
+
import os, shutil
|
| 3 |
+
from setuptools.command.install import install
|
| 4 |
+
|
| 5 |
+
class custom_install_command(install):
|
| 6 |
+
def run(self):
|
| 7 |
+
install.run(self)
|
| 8 |
+
target_dir = os.path.join(self.install_lib, "ten_vad_library")
|
| 9 |
+
os.makedirs(target_dir, exist_ok=True)
|
| 10 |
+
shutil.copy("lib/Linux/x64/libten_vad.so", target_dir)
|
| 11 |
+
print(f"Files installed to: {target_dir}")
|
| 12 |
+
|
| 13 |
+
root_dir = os.path.dirname(os.path.abspath(__file__))
|
| 14 |
+
shutil.copy(f"{root_dir}/include/ten_vad.py", f"{root_dir}/ten_vad.py")
|
| 15 |
+
setup(
|
| 16 |
+
name="ten_vad",
|
| 17 |
+
version="1.0",
|
| 18 |
+
py_modules=["ten_vad"],
|
| 19 |
+
cmdclass={
|
| 20 |
+
"install": custom_install_command,
|
| 21 |
+
},
|
| 22 |
+
)
|
| 23 |
+
os.remove(f"{root_dir}/ten_vad.py")
|