@glassly/bluetooth-sdk 0.1.0-dev.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (548) hide show
  1. package/README.md +563 -0
  2. package/android/build.gradle +450 -0
  3. package/android/gradle.properties.example +9 -0
  4. package/android/lc3Lib/CMakeLists.txt +6 -0
  5. package/android/lc3Lib/build.gradle +212 -0
  6. package/android/lc3Lib/proguard-rules.pro +33 -0
  7. package/android/lc3Lib/src/main/AndroidManifest.xml +2 -0
  8. package/android/lc3Lib/src/main/cpp/CMakeLists.txt +8 -0
  9. package/android/lc3Lib/src/main/cpp/google_opus_stuff/CMakeLists.txt +30 -0
  10. package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/CMakeLists.txt +7 -0
  11. package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.cc +96 -0
  12. package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.h +53 -0
  13. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/Makefile.am +6 -0
  14. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h +26 -0
  15. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h.in +26 -0
  16. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/ogg.h +209 -0
  17. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/os_types.h +158 -0
  18. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus.h +981 -0
  19. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_custom.h +342 -0
  20. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_defines.h +799 -0
  21. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_multistream.h +660 -0
  22. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_projection.h +568 -0
  23. package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_types.h +166 -0
  24. package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.cc +268 -0
  25. package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.h +115 -0
  26. package/android/lc3Lib/src/main/cpp/google_opus_stuff/opus_tools/opus_header.h +59 -0
  27. package/android/lc3Lib/src/main/cpp/liblc3/CMakeLists.txt +38 -0
  28. package/android/lc3Lib/src/main/cpp/liblc3/include/lc3.h +309 -0
  29. package/android/lc3Lib/src/main/cpp/liblc3/include/lc3_private.h +162 -0
  30. package/android/lc3Lib/src/main/cpp/liblc3/include/rnnoise.h +114 -0
  31. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/CMakeLists.txt +19 -0
  32. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.c +92 -0
  33. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.h +44 -0
  34. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.c +375 -0
  35. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.h +315 -0
  36. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.c +129 -0
  37. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.h +69 -0
  38. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/common.h +148 -0
  39. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.c +70 -0
  40. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.h +43 -0
  41. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/fastmath.h +158 -0
  42. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/lc3.c +702 -0
  43. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.c +893 -0
  44. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.h +111 -0
  45. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_arm.h +506 -0
  46. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_neon.h +281 -0
  47. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/makefile.mk +35 -0
  48. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.c +452 -0
  49. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.h +57 -0
  50. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct_neon.h +296 -0
  51. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/meson.build +46 -0
  52. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.c +61 -0
  53. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.h +57 -0
  54. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.c +880 -0
  55. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.h +103 -0
  56. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.c +904 -0
  57. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.h +119 -0
  58. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.c +3457 -0
  59. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.h +94 -0
  60. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.c +457 -0
  61. package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.h +99 -0
  62. package/android/lc3Lib/src/main/cpp/liblc3/liblc3.cpp +159 -0
  63. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/_kiss_fft_guts.h +182 -0
  64. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/arch.h +261 -0
  65. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.c +279 -0
  66. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.h +59 -0
  67. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/common.h +48 -0
  68. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/compile.sh +3 -0
  69. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/denoise.c +646 -0
  70. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.c +601 -0
  71. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.h +203 -0
  72. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/opus_types.h +159 -0
  73. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.c +526 -0
  74. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.h +149 -0
  75. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.c +178 -0
  76. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.h +69 -0
  77. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.c +11051 -0
  78. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.h +34 -0
  79. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_reader.c +168 -0
  80. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_train.py +66 -0
  81. package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/tansig_table.h +45 -0
  82. package/android/lc3Lib/src/main/java/com/glassly/lc3Lib/Lc3Cpp.java +38 -0
  83. package/android/lc3Lib/third_party/CMakeLists.txt +23 -0
  84. package/android/lc3Lib/third_party/CMakeLists_libogg.txt +18 -0
  85. package/android/lc3Lib/third_party/CMakeLists_libopus.txt +18 -0
  86. package/android/lc3Lib/third_party/CMakeLists_opus-tools.txt +23 -0
  87. package/android/lc3Lib/third_party/opus_tools/src/AUTHORS +5 -0
  88. package/android/lc3Lib/third_party/opus_tools/src/CMakeLists.txt +4 -0
  89. package/android/lc3Lib/third_party/opus_tools/src/COPYING +371 -0
  90. package/android/lc3Lib/third_party/opus_tools/src/ChangeLog +3 -0
  91. package/android/lc3Lib/third_party/opus_tools/src/Makefile.am +42 -0
  92. package/android/lc3Lib/third_party/opus_tools/src/Makefile.unix +23 -0
  93. package/android/lc3Lib/third_party/opus_tools/src/NEWS +0 -0
  94. package/android/lc3Lib/third_party/opus_tools/src/README +0 -0
  95. package/android/lc3Lib/third_party/opus_tools/src/autogen.sh +115 -0
  96. package/android/lc3Lib/third_party/opus_tools/src/configure.ac +293 -0
  97. package/android/lc3Lib/third_party/opus_tools/src/src/arch.h +239 -0
  98. package/android/lc3Lib/third_party/opus_tools/src/src/audio-in.c +1046 -0
  99. package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.c +245 -0
  100. package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.h +28 -0
  101. package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.c +320 -0
  102. package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.h +51 -0
  103. package/android/lc3Lib/third_party/opus_tools/src/src/lpc.c +157 -0
  104. package/android/lc3Lib/third_party/opus_tools/src/src/lpc.h +27 -0
  105. package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.c +286 -0
  106. package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.h +59 -0
  107. package/android/lc3Lib/third_party/opus_tools/src/src/opusdec.c +884 -0
  108. package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.c +1021 -0
  109. package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.h +101 -0
  110. package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.c +639 -0
  111. package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.h +51 -0
  112. package/android/lc3Lib/third_party/opus_tools/src/src/os_support.h +167 -0
  113. package/android/lc3Lib/third_party/opus_tools/src/src/resample.c +1137 -0
  114. package/android/lc3Lib/third_party/opus_tools/src/src/speex_resampler.h +344 -0
  115. package/android/lc3Lib/third_party/opus_tools/src/src/stack_alloc.h +115 -0
  116. package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.c +125 -0
  117. package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.h +62 -0
  118. package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.c +223 -0
  119. package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.h +60 -0
  120. package/android/settings.gradle +4 -0
  121. package/android/silero/LICENSE.md +17 -0
  122. package/android/silero/build.gradle +50 -0
  123. package/android/silero/proguard-rules.pro +24 -0
  124. package/android/silero/src/androidTest/assets/hello.wav +0 -0
  125. package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +79 -0
  126. package/android/silero/src/main/assets/LICENSE +21 -0
  127. package/android/silero/src/main/assets/silero_vad.onnx +0 -0
  128. package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +160 -0
  129. package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +449 -0
  130. package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +15 -0
  131. package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +14 -0
  132. package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +12 -0
  133. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +47 -0
  134. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +41 -0
  135. package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +44 -0
  136. package/android/src/main/AndroidManifest.xml +42 -0
  137. package/android/src/main/assets/G2Firmware/README.md +11 -0
  138. package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdk.kt +2325 -0
  139. package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkAnalytics.kt +216 -0
  140. package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDebug.kt +14 -0
  141. package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDefaults.kt +7 -0
  142. package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkModule.kt +1088 -0
  143. package/android/src/main/java/com/glassly/bluetoothsdk/Bridge.kt +953 -0
  144. package/android/src/main/java/com/glassly/bluetoothsdk/DeviceManager.kt +2528 -0
  145. package/android/src/main/java/com/glassly/bluetoothsdk/DeviceStore.kt +360 -0
  146. package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedChangelogCatalog.kt +8 -0
  147. package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedReleaseMetadata.kt +11 -0
  148. package/android/src/main/java/com/glassly/bluetoothsdk/LocalNetworkModule.kt +414 -0
  149. package/android/src/main/java/com/glassly/bluetoothsdk/ObservableStore.kt +88 -0
  150. package/android/src/main/java/com/glassly/bluetoothsdk/OtaManifest.kt +191 -0
  151. package/android/src/main/java/com/glassly/bluetoothsdk/ReleaseChangelog.kt +61 -0
  152. package/android/src/main/java/com/glassly/bluetoothsdk/ScopedNetworkReadiness.kt +17 -0
  153. package/android/src/main/java/com/glassly/bluetoothsdk/audio/AudioModels.kt +144 -0
  154. package/android/src/main/java/com/glassly/bluetoothsdk/camera/CameraModels.kt +486 -0
  155. package/android/src/main/java/com/glassly/bluetoothsdk/connection/ConnectionModels.kt +78 -0
  156. package/android/src/main/java/com/glassly/bluetoothsdk/controllers/ControllerManager.kt +158 -0
  157. package/android/src/main/java/com/glassly/bluetoothsdk/controllers/R1.kt +937 -0
  158. package/android/src/main/java/com/glassly/bluetoothsdk/debug/BleTraceLogger.kt +165 -0
  159. package/android/src/main/java/com/glassly/bluetoothsdk/events/BluetoothEvents.kt +178 -0
  160. package/android/src/main/java/com/glassly/bluetoothsdk/internal/MapParsing.kt +140 -0
  161. package/android/src/main/java/com/glassly/bluetoothsdk/net/LocalIpv4.kt +57 -0
  162. package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServer.kt +304 -0
  163. package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/OtaServerModule.kt +120 -0
  164. package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistry.java +108 -0
  165. package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoUploadServer.kt +622 -0
  166. package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/PhotoReceiverModule.kt +156 -0
  167. package/android/src/main/java/com/glassly/bluetoothsdk/requests/DisplayRequests.kt +56 -0
  168. package/android/src/main/java/com/glassly/bluetoothsdk/services/Foreground.kt +272 -0
  169. package/android/src/main/java/com/glassly/bluetoothsdk/services/PhoneMic.kt +1195 -0
  170. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Ar99.java +2653 -0
  171. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuard.kt +49 -0
  172. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapper.kt +27 -0
  173. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1.kt +3878 -0
  174. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizer.kt +38 -0
  175. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2.kt +6428 -0
  176. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassification.kt +49 -0
  177. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwRenderer.kt +1241 -0
  178. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCache.kt +270 -0
  179. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocol.kt +291 -0
  180. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2Flasher.kt +411 -0
  181. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/GlasslyBle.java +43189 -0
  182. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Mach1.kt +1280 -0
  183. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLive.kt +10817 -0
  184. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLiveL2capChannel.kt +274 -0
  185. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +54 -0
  186. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraNex.kt +2011 -0
  187. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Nimo.kt +2532 -0
  188. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/SGCManager.kt +470 -0
  189. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Simulated.kt +228 -0
  190. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/Ar99OtaManager.java +566 -0
  191. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaByteUtils.java +18 -0
  192. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCommandConstants.java +35 -0
  193. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCrc32Util.java +13 -0
  194. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaGattTransport.java +11 -0
  195. package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaProtocol.java +92 -0
  196. package/android/src/main/java/com/glassly/bluetoothsdk/speakerid/SpeakerIdEngine.kt +525 -0
  197. package/android/src/main/java/com/glassly/bluetoothsdk/status/DeviceStatus.kt +669 -0
  198. package/android/src/main/java/com/glassly/bluetoothsdk/status/RuntimeState.kt +201 -0
  199. package/android/src/main/java/com/glassly/bluetoothsdk/status/WifiHotspotStatus.kt +189 -0
  200. package/android/src/main/java/com/glassly/bluetoothsdk/streaming/StreamModels.kt +518 -0
  201. package/android/src/main/java/com/glassly/bluetoothsdk/stt/STTTools.kt +391 -0
  202. package/android/src/main/java/com/glassly/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +518 -0
  203. package/android/src/main/java/com/glassly/bluetoothsdk/stt/VadGateSpeechPolicy.kt +229 -0
  204. package/android/src/main/java/com/glassly/bluetoothsdk/tts/TTSTools.kt +248 -0
  205. package/android/src/main/java/com/glassly/bluetoothsdk/types/DeviceModels.kt +96 -0
  206. package/android/src/main/java/com/glassly/bluetoothsdk/utils/AES.java +106 -0
  207. package/android/src/main/java/com/glassly/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
  208. package/android/src/main/java/com/glassly/bluetoothsdk/utils/AvifExifStripper.java +573 -0
  209. package/android/src/main/java/com/glassly/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
  210. package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleJsonCompact.java +496 -0
  211. package/android/src/main/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadService.java +677 -0
  212. package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleWireProtocol.java +108 -0
  213. package/android/src/main/java/com/glassly/bluetoothsdk/utils/Constants.kt +46 -0
  214. package/android/src/main/java/com/glassly/bluetoothsdk/utils/G1Text.kt +436 -0
  215. package/android/src/main/java/com/glassly/bluetoothsdk/utils/HeifExifTagReader.java +199 -0
  216. package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
  217. package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleUploadService.java +77 -0
  218. package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900LengthCodec.java +115 -0
  219. package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtils.java +827 -0
  220. package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunkReassembler.java +228 -0
  221. package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunker.java +325 -0
  222. package/android/src/main/java/com/glassly/bluetoothsdk/utils/NexSGCUtils.kt +698 -0
  223. package/android/src/main/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitor.kt +348 -0
  224. package/android/src/main/java/com/glassly/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
  225. package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Ar99OpusPcmDecoder.java +398 -0
  226. package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
  227. package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
  228. package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
  229. package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +328 -0
  230. package/android/src/main/res/values/strings.xml +4 -0
  231. package/android/src/test/java/com/glassly/bluetoothsdk/BluetoothSdkExceptionTest.kt +18 -0
  232. package/android/src/test/java/com/glassly/bluetoothsdk/OtaManifestDowngradeTest.kt +86 -0
  233. package/android/src/test/java/com/glassly/bluetoothsdk/OtaStartResponsePolicyTest.kt +30 -0
  234. package/android/src/test/java/com/glassly/bluetoothsdk/ReleaseChangelogTest.kt +13 -0
  235. package/android/src/test/java/com/glassly/bluetoothsdk/ScopedNetworkReadinessTest.kt +39 -0
  236. package/android/src/test/java/com/glassly/bluetoothsdk/StreamStatusEventTest.kt +29 -0
  237. package/android/src/test/java/com/glassly/bluetoothsdk/camera/PhotoRequestTest.kt +141 -0
  238. package/android/src/test/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServerTest.kt +82 -0
  239. package/android/src/test/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistryTest.java +75 -0
  240. package/android/src/test/java/com/glassly/bluetoothsdk/services/ForegroundServiceTypeTest.kt +69 -0
  241. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/Ar99AdvertisementMatcherTest.java +22 -0
  242. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuardTest.kt +73 -0
  243. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapperTest.kt +67 -0
  244. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/EvenRleTest.kt +63 -0
  245. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizerTest.kt +31 -0
  246. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassificationTest.kt +89 -0
  247. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwRendererTest.kt +344 -0
  248. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCacheTest.kt +200 -0
  249. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocolTest.kt +131 -0
  250. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLiveGattCharacteristicsTest.kt +39 -0
  251. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +133 -0
  252. package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/NimoProtocolTest.kt +333 -0
  253. package/android/src/test/java/com/glassly/bluetoothsdk/utils/AvifExifStripperTest.java +46 -0
  254. package/android/src/test/java/com/glassly/bluetoothsdk/utils/BinaryMessageChunkerTest.java +84 -0
  255. package/android/src/test/java/com/glassly/bluetoothsdk/utils/BleJsonCompactTest.java +319 -0
  256. package/android/src/test/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadServiceTest.java +107 -0
  257. package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsEndiannessTest.java +172 -0
  258. package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsTest.java +24 -0
  259. package/android/src/test/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitorTest.kt +45 -0
  260. package/android/src/test/resources/avif_with_exif.avif +0 -0
  261. package/app.plugin.js +3 -0
  262. package/build/BluetoothSdk.types.d.ts +1354 -0
  263. package/build/BluetoothSdk.types.d.ts.map +1 -0
  264. package/build/BluetoothSdk.types.js +41 -0
  265. package/build/BluetoothSdk.types.js.map +1 -0
  266. package/build/_internal.d.ts +17 -0
  267. package/build/_internal.d.ts.map +1 -0
  268. package/build/_internal.js +16 -0
  269. package/build/_internal.js.map +1 -0
  270. package/build/_private/BluetoothSdkModule.d.ts +172 -0
  271. package/build/_private/BluetoothSdkModule.d.ts.map +1 -0
  272. package/build/_private/BluetoothSdkModule.js +300 -0
  273. package/build/_private/BluetoothSdkModule.js.map +1 -0
  274. package/build/_private/LocalNetworkModule.d.ts +38 -0
  275. package/build/_private/LocalNetworkModule.d.ts.map +1 -0
  276. package/build/_private/LocalNetworkModule.js +3 -0
  277. package/build/_private/LocalNetworkModule.js.map +1 -0
  278. package/build/_private/cameraRequestPayload.d.ts +4 -0
  279. package/build/_private/cameraRequestPayload.d.ts.map +1 -0
  280. package/build/_private/cameraRequestPayload.js +32 -0
  281. package/build/_private/cameraRequestPayload.js.map +1 -0
  282. package/build/_private/photoRequestPayload.d.ts +6 -0
  283. package/build/_private/photoRequestPayload.d.ts.map +1 -0
  284. package/build/_private/photoRequestPayload.js +86 -0
  285. package/build/_private/photoRequestPayload.js.map +1 -0
  286. package/build/_private/sdkOtaManifest.d.ts +11 -0
  287. package/build/_private/sdkOtaManifest.d.ts.map +1 -0
  288. package/build/_private/sdkOtaManifest.js +15 -0
  289. package/build/_private/sdkOtaManifest.js.map +1 -0
  290. package/build/changelogs.d.ts +7 -0
  291. package/build/changelogs.d.ts.map +1 -0
  292. package/build/changelogs.js +46 -0
  293. package/build/changelogs.js.map +1 -0
  294. package/build/debug.d.ts +3 -0
  295. package/build/debug.d.ts.map +1 -0
  296. package/build/debug.js +8 -0
  297. package/build/debug.js.map +1 -0
  298. package/build/generated/changelogCatalog.d.ts +9 -0
  299. package/build/generated/changelogCatalog.d.ts.map +1 -0
  300. package/build/generated/changelogCatalog.js +12 -0
  301. package/build/generated/changelogCatalog.js.map +1 -0
  302. package/build/generated/releaseMetadata.d.ts +12 -0
  303. package/build/generated/releaseMetadata.d.ts.map +1 -0
  304. package/build/generated/releaseMetadata.js +10 -0
  305. package/build/generated/releaseMetadata.js.map +1 -0
  306. package/build/index.d.ts +6 -0
  307. package/build/index.d.ts.map +1 -0
  308. package/build/index.js +171 -0
  309. package/build/index.js.map +1 -0
  310. package/build/ota-server/OtaServer.types.d.ts +14 -0
  311. package/build/ota-server/OtaServer.types.d.ts.map +1 -0
  312. package/build/ota-server/OtaServer.types.js +2 -0
  313. package/build/ota-server/OtaServer.types.js.map +1 -0
  314. package/build/ota-server/OtaServerModule.d.ts +21 -0
  315. package/build/ota-server/OtaServerModule.d.ts.map +1 -0
  316. package/build/ota-server/OtaServerModule.js +3 -0
  317. package/build/ota-server/OtaServerModule.js.map +1 -0
  318. package/build/ota-server/OtaServerModule.web.d.ts +10 -0
  319. package/build/ota-server/OtaServerModule.web.d.ts.map +1 -0
  320. package/build/ota-server/OtaServerModule.web.js +12 -0
  321. package/build/ota-server/OtaServerModule.web.js.map +1 -0
  322. package/build/ota-server/index.d.ts +3 -0
  323. package/build/ota-server/index.d.ts.map +1 -0
  324. package/build/ota-server/index.js +3 -0
  325. package/build/ota-server/index.js.map +1 -0
  326. package/build/ota-transport/index.d.ts +67 -0
  327. package/build/ota-transport/index.d.ts.map +1 -0
  328. package/build/ota-transport/index.js +58 -0
  329. package/build/ota-transport/index.js.map +1 -0
  330. package/build/photo-receiver/PhotoReceiver.types.d.ts +18 -0
  331. package/build/photo-receiver/PhotoReceiver.types.d.ts.map +1 -0
  332. package/build/photo-receiver/PhotoReceiver.types.js +2 -0
  333. package/build/photo-receiver/PhotoReceiver.types.js.map +1 -0
  334. package/build/photo-receiver/PhotoReceiverModule.d.ts +10 -0
  335. package/build/photo-receiver/PhotoReceiverModule.d.ts.map +1 -0
  336. package/build/photo-receiver/PhotoReceiverModule.js +3 -0
  337. package/build/photo-receiver/PhotoReceiverModule.js.map +1 -0
  338. package/build/photo-receiver/PhotoReceiverModule.web.d.ts +10 -0
  339. package/build/photo-receiver/PhotoReceiverModule.web.d.ts.map +1 -0
  340. package/build/photo-receiver/PhotoReceiverModule.web.js +12 -0
  341. package/build/photo-receiver/PhotoReceiverModule.web.js.map +1 -0
  342. package/build/photo-receiver/index.d.ts +3 -0
  343. package/build/photo-receiver/index.d.ts.map +1 -0
  344. package/build/photo-receiver/index.js +3 -0
  345. package/build/photo-receiver/index.js.map +1 -0
  346. package/build/react/index.d.ts +5 -0
  347. package/build/react/index.d.ts.map +1 -0
  348. package/build/react/index.js +4 -0
  349. package/build/react/index.js.map +1 -0
  350. package/build/react/useBluetooth.d.ts +100 -0
  351. package/build/react/useBluetooth.d.ts.map +1 -0
  352. package/build/react/useBluetooth.js +167 -0
  353. package/build/react/useBluetooth.js.map +1 -0
  354. package/build/react/useBluetoothEvent.d.ts +6 -0
  355. package/build/react/useBluetoothEvent.d.ts.map +1 -0
  356. package/build/react/useBluetoothEvent.js +21 -0
  357. package/build/react/useBluetoothEvent.js.map +1 -0
  358. package/build/react/useBluetoothScan.d.ts +22 -0
  359. package/build/react/useBluetoothScan.d.ts.map +1 -0
  360. package/build/react/useBluetoothScan.js +135 -0
  361. package/build/react/useBluetoothScan.js.map +1 -0
  362. package/build/react/useBluetoothStatus.d.ts +16 -0
  363. package/build/react/useBluetoothStatus.d.ts.map +1 -0
  364. package/build/react/useBluetoothStatus.js +137 -0
  365. package/build/react/useBluetoothStatus.js.map +1 -0
  366. package/build/react/useGlassesConnection.d.ts +29 -0
  367. package/build/react/useGlassesConnection.d.ts.map +1 -0
  368. package/build/react/useGlassesConnection.js +153 -0
  369. package/build/react/useGlassesConnection.js.map +1 -0
  370. package/build/types/index.d.ts +3 -0
  371. package/build/types/index.d.ts.map +1 -0
  372. package/build/types/index.js +2 -0
  373. package/build/types/index.js.map +1 -0
  374. package/expo-module.config.json +14 -0
  375. package/ios/BackgroundOtaArtifactDownloader.swift +125 -0
  376. package/ios/BluetoothSdkModule.swift +1034 -0
  377. package/ios/GlasslyBluetoothSDK.podspec +106 -0
  378. package/ios/LocalIPv4.swift +150 -0
  379. package/ios/LocalOtaServer.swift +309 -0
  380. package/ios/LocalPhotoUploadServer.swift +754 -0
  381. package/ios/OtaServerModule.swift +147 -0
  382. package/ios/Packages/CoreObjC/CoreObjC.xcodeproj/project.pbxproj +213 -0
  383. package/ios/Packages/CoreObjC/PcmConverter.h +22 -0
  384. package/ios/Packages/CoreObjC/PcmConverter.m +266 -0
  385. package/ios/Packages/CoreObjC/attdet.c +92 -0
  386. package/ios/Packages/CoreObjC/attdet.h +44 -0
  387. package/ios/Packages/CoreObjC/bits.c +375 -0
  388. package/ios/Packages/CoreObjC/bits.h +315 -0
  389. package/ios/Packages/CoreObjC/bwdet.c +129 -0
  390. package/ios/Packages/CoreObjC/bwdet.h +69 -0
  391. package/ios/Packages/CoreObjC/common.h +151 -0
  392. package/ios/Packages/CoreObjC/energy.c +70 -0
  393. package/ios/Packages/CoreObjC/energy.h +43 -0
  394. package/ios/Packages/CoreObjC/fastmath.h +158 -0
  395. package/ios/Packages/CoreObjC/include/PcmConverter.h +22 -0
  396. package/ios/Packages/CoreObjC/lc3.c +704 -0
  397. package/ios/Packages/CoreObjC/lc3.h +313 -0
  398. package/ios/Packages/CoreObjC/lc3_cpp.h +283 -0
  399. package/ios/Packages/CoreObjC/lc3_private.h +163 -0
  400. package/ios/Packages/CoreObjC/ltpf.c +905 -0
  401. package/ios/Packages/CoreObjC/ltpf.h +111 -0
  402. package/ios/Packages/CoreObjC/ltpf_arm.h +506 -0
  403. package/ios/Packages/CoreObjC/ltpf_neon.h +281 -0
  404. package/ios/Packages/CoreObjC/makefile.mk +35 -0
  405. package/ios/Packages/CoreObjC/mdct.c +469 -0
  406. package/ios/Packages/CoreObjC/mdct.h +57 -0
  407. package/ios/Packages/CoreObjC/mdct_neon.h +296 -0
  408. package/ios/Packages/CoreObjC/meson.build +61 -0
  409. package/ios/Packages/CoreObjC/plc.c +61 -0
  410. package/ios/Packages/CoreObjC/plc.h +57 -0
  411. package/ios/Packages/CoreObjC/rnnoise.h +114 -0
  412. package/ios/Packages/CoreObjC/sns.c +880 -0
  413. package/ios/Packages/CoreObjC/sns.h +103 -0
  414. package/ios/Packages/CoreObjC/spec.c +907 -0
  415. package/ios/Packages/CoreObjC/spec.h +119 -0
  416. package/ios/Packages/CoreObjC/tables.c +3457 -0
  417. package/ios/Packages/CoreObjC/tables.h +94 -0
  418. package/ios/Packages/CoreObjC/tns.c +457 -0
  419. package/ios/Packages/CoreObjC/tns.h +99 -0
  420. package/ios/Packages/SherpaOnnx/Model/joiner.onnx +0 -0
  421. package/ios/Packages/SherpaOnnx/Model/tokens.txt +502 -0
  422. package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +2383 -0
  423. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +48 -0
  424. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
  425. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
  426. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
  427. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
  428. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
  429. package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
  430. package/ios/Packages/libbz2/module.modulemap +5 -0
  431. package/ios/Packages/libbz2/shim.h +1 -0
  432. package/ios/PhotoReceiverModule.swift +129 -0
  433. package/ios/Source/BluetoothSDK.swift +2303 -0
  434. package/ios/Source/BluetoothSDKDebug.swift +12 -0
  435. package/ios/Source/BluetoothSdkDefaults.swift +29 -0
  436. package/ios/Source/Bridge.swift +708 -0
  437. package/ios/Source/Bridging-Header.h +16 -0
  438. package/ios/Source/DeviceManager.swift +2109 -0
  439. package/ios/Source/DeviceStore.swift +336 -0
  440. package/ios/Source/GeneratedChangelogCatalog.swift +7 -0
  441. package/ios/Source/GeneratedReleaseMetadata.swift +11 -0
  442. package/ios/Source/ObservableStore.swift +118 -0
  443. package/ios/Source/OtaManifest.swift +211 -0
  444. package/ios/Source/PrivacyInfo.xcprivacy +23 -0
  445. package/ios/Source/ReleaseChangelog.swift +65 -0
  446. package/ios/Source/Resources/G2Firmware/README.md +10 -0
  447. package/ios/Source/audio/AudioModels.swift +178 -0
  448. package/ios/Source/audio/PcmStreamPlayer.swift +410 -0
  449. package/ios/Source/camera/CameraModels.swift +866 -0
  450. package/ios/Source/connection/ScanSession.swift +27 -0
  451. package/ios/Source/controllers/ControllerManager.swift +184 -0
  452. package/ios/Source/controllers/R1.swift +829 -0
  453. package/ios/Source/errors/BluetoothSdkError.swift +19 -0
  454. package/ios/Source/events/BluetoothEvents.swift +342 -0
  455. package/ios/Source/internal/BleTraceLogger.swift +192 -0
  456. package/ios/Source/internal/BluetoothAvailability.swift +78 -0
  457. package/ios/Source/internal/BluetoothSdkAnalytics.swift +199 -0
  458. package/ios/Source/internal/ValueParsing.swift +99 -0
  459. package/ios/Source/requests/DisplayRequests.swift +82 -0
  460. package/ios/Source/services/PhoneMic.swift +662 -0
  461. package/ios/Source/sgcs/Ar99.swift +2451 -0
  462. package/ios/Source/sgcs/Frame.swift +649 -0
  463. package/ios/Source/sgcs/G1.swift +2554 -0
  464. package/ios/Source/sgcs/G2.swift +6887 -0
  465. package/ios/Source/sgcs/G2CfwClassification.swift +43 -0
  466. package/ios/Source/sgcs/G2CfwRenderer.swift +1279 -0
  467. package/ios/Source/sgcs/G2CfwTextureCache.swift +233 -0
  468. package/ios/Source/sgcs/G2FlashProtocol.swift +312 -0
  469. package/ios/Source/sgcs/G2Flasher.swift +773 -0
  470. package/ios/Source/sgcs/Mach1.swift +541 -0
  471. package/ios/Source/sgcs/MentraLive.swift +7011 -0
  472. package/ios/Source/sgcs/MentraLiveL2capChannel.swift +183 -0
  473. package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +64 -0
  474. package/ios/Source/sgcs/MentraNex.swift +3221 -0
  475. package/ios/Source/sgcs/Nimo.swift +1886 -0
  476. package/ios/Source/sgcs/SGCManager.swift +608 -0
  477. package/ios/Source/sgcs/Simulated.swift +274 -0
  478. package/ios/Source/sgcs/ar99/ota/Ar99OtaManager.swift +637 -0
  479. package/ios/Source/sgcs/glassly_ble.pb.swift +4354 -0
  480. package/ios/Source/speakerid/SpeakerIdEngine.swift +573 -0
  481. package/ios/Source/status/DeviceStatus.swift +981 -0
  482. package/ios/Source/status/RuntimeState.swift +359 -0
  483. package/ios/Source/status/WifiHotspotStatus.swift +345 -0
  484. package/ios/Source/streaming/StreamModels.swift +693 -0
  485. package/ios/Source/stt/STTTools.swift +191 -0
  486. package/ios/Source/stt/SherpaOnnxTranscriber.swift +466 -0
  487. package/ios/Source/tts/TTSTools.swift +171 -0
  488. package/ios/Source/types/DeviceModels.swift +177 -0
  489. package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
  490. package/ios/Source/utils/BinaryCodec.swift +61 -0
  491. package/ios/Source/utils/BleJsonCompact.swift +405 -0
  492. package/ios/Source/utils/BleWireProtocol.swift +92 -0
  493. package/ios/Source/utils/Constants.swift +78 -0
  494. package/ios/Source/utils/Enums.swift +95 -0
  495. package/ios/Source/utils/G1Text.swift +2096 -0
  496. package/ios/Source/utils/JSCExperiment.swift +241 -0
  497. package/ios/Source/utils/MemoryMonitor.swift +44 -0
  498. package/ios/Source/utils/MessageChunkReassembler.swift +190 -0
  499. package/ios/Source/utils/MessageChunker.swift +294 -0
  500. package/ios/Source/utils/Models.swift +135 -0
  501. package/ios/Source/utils/PhoneAudioMonitor.swift +230 -0
  502. package/ios/Source/utils/TarBz2Extractor.swift +257 -0
  503. package/ios/Tests/BluetoothSDKTests/G2CfwClassificationTests.swift +78 -0
  504. package/ios/Tests/BluetoothSDKTests/G2CfwRendererTests.swift +372 -0
  505. package/ios/Tests/BluetoothSDKTests/G2CfwTextureCacheTests.swift +162 -0
  506. package/ios/Tests/BluetoothSDKTests/G2FlashProtocolTests.swift +182 -0
  507. package/ios/Tests/MentraLivePairingAdvertisementTests.swift +160 -0
  508. package/ios/Tests/ReleaseChangelogTests.swift +13 -0
  509. package/package.json +129 -0
  510. package/plugin/build/index.d.ts +10 -0
  511. package/plugin/build/index.js +12 -0
  512. package/plugin/build/withAndroid.d.ts +3 -0
  513. package/plugin/build/withAndroid.js +190 -0
  514. package/plugin/build/withIos.d.ts +5 -0
  515. package/plugin/build/withIos.js +108 -0
  516. package/scripts/inject-ios-sdk-version.mjs +65 -0
  517. package/scripts/public-ota-api.test.mjs +37 -0
  518. package/scripts/verify-release-package.mjs +45 -0
  519. package/scripts/write-release-metadata.mjs +152 -0
  520. package/scripts/write-release-metadata.test.mjs +37 -0
  521. package/src/BluetoothSdk.types.ts +1623 -0
  522. package/src/_internal.ts +16 -0
  523. package/src/_private/BluetoothSdkModule.ts +684 -0
  524. package/src/_private/LocalNetworkModule.ts +50 -0
  525. package/src/_private/cameraRequestPayload.ts +34 -0
  526. package/src/_private/photoRequestPayload.ts +90 -0
  527. package/src/_private/sdkOtaManifest.ts +18 -0
  528. package/src/changelogs.ts +46 -0
  529. package/src/debug.ts +9 -0
  530. package/src/generated/changelogCatalog.ts +13 -0
  531. package/src/generated/releaseMetadata.ts +20 -0
  532. package/src/index.ts +321 -0
  533. package/src/ota-server/OtaServer.types.ts +10 -0
  534. package/src/ota-server/OtaServerModule.ts +23 -0
  535. package/src/ota-server/OtaServerModule.web.ts +17 -0
  536. package/src/ota-server/index.ts +2 -0
  537. package/src/ota-transport/index.ts +116 -0
  538. package/src/photo-receiver/PhotoReceiver.types.ts +20 -0
  539. package/src/photo-receiver/PhotoReceiverModule.ts +11 -0
  540. package/src/photo-receiver/PhotoReceiverModule.web.ts +17 -0
  541. package/src/photo-receiver/index.ts +2 -0
  542. package/src/react/index.ts +21 -0
  543. package/src/react/useBluetooth.ts +309 -0
  544. package/src/react/useBluetoothEvent.ts +35 -0
  545. package/src/react/useBluetoothScan.ts +173 -0
  546. package/src/react/useBluetoothStatus.ts +180 -0
  547. package/src/react/useGlassesConnection.ts +202 -0
  548. package/src/types/index.ts +12 -0
@@ -0,0 +1,4689 @@
1
+ // sherpa-onnx/c-api/c-api.h
2
+ //
3
+ // Copyright (c) 2023 Xiaomi Corporation
4
+ /**
5
+ * @file c-api.h
6
+ * @brief Public C API for sherpa-onnx.
7
+ *
8
+ * This header exposes the main sherpa-onnx inference features through a stable
9
+ * C interface. It is intended for native C/C++ applications and for language
10
+ * bindings that need a C ABI.
11
+ *
12
+ * The file is organized by feature family. The major API groups are:
13
+ *
14
+ * - Utility helpers: version/build information, file checks, WAVE I/O, and a
15
+ * display helper for incremental text output
16
+ * - Streaming ASR: online recognizers, online streams, endpointing, and
17
+ * per-stream runtime options
18
+ * - Non-streaming ASR: offline recognizers, offline streams, batch decode, and
19
+ * result retrieval
20
+ * - Keyword spotting: streaming keyword detection, custom keyword streams, and
21
+ * keyword result snapshots
22
+ * - Voice activity detection: Silero/Ten VAD models, speech segment buffers,
23
+ * and detector state management
24
+ * - Text-to-speech: offline TTS model families, generation configuration, and
25
+ * generated audio helpers
26
+ * - Spoken language identification
27
+ * - Speaker embedding extraction and speaker enrollment/search/verification
28
+ * - Audio tagging
29
+ * - Offline and online punctuation restoration
30
+ * - Linear resampling
31
+ * - Offline speaker diarization
32
+ * - Offline and online speech enhancement / denoising
33
+ * - HarmonyOS-specific constructor variants
34
+ *
35
+ * Common ownership rules:
36
+ *
37
+ * - Opaque handles created by `SherpaOnnxCreate*()` functions are generally
38
+ * destroyed with a matching `SherpaOnnxDestroy*()` function
39
+ * - Snapshot/result objects returned by query functions usually need explicit
40
+ * destruction as documented on each API
41
+ * - Strings or arrays returned by helper/query functions are either:
42
+ * - statically owned by the library and must not be freed, or
43
+ * - heap-allocated for the caller and must be released with the matching
44
+ * `Free`/`Destroy` API
45
+ *
46
+ * General usage pattern:
47
+ *
48
+ * 1. Zero-initialize a config struct with `memset(&config, 0, sizeof(config))`
49
+ * 2. Fill in the required model paths and runtime options
50
+ * 3. Create the corresponding engine with `SherpaOnnxCreate*()`
51
+ * 4. Create a stream if the feature uses one
52
+ * 5. Feed audio or text, run the compute/decode API, and retrieve results
53
+ * 6. Release every returned object with the documented matching API
54
+ *
55
+ * The examples in `c-api-examples/` show complete end-to-end usage. Useful
56
+ * starting points include:
57
+ *
58
+ * - `decode-file-c-api.c` for ASR
59
+ * - `kws-c-api.c` for keyword spotting
60
+ * - `vad-whisper-c-api.c` for VAD
61
+ * - `offline-tts-c-api.c` and `kokoro-tts-en-c-api.c` for TTS
62
+ * - `speaker-identification-c-api.c` for speaker embedding and verification
63
+ * - `audio-tagging-c-api.c` for audio tagging
64
+ * - `add-punctuation-c-api.c` and `add-punctuation-online-c-api.c` for
65
+ * punctuation
66
+ * - `offline-sepaker-diarization-c-api.c` for diarization
67
+ * - `speech-enhancement-gtcrn-c-api.c` and
68
+ * `online-speech-enhancement-gtcrn-c-api.c` for speech enhancement
69
+ */
70
+
71
+ #ifndef SHERPA_ONNX_C_API_C_API_H_
72
+ #define SHERPA_ONNX_C_API_C_API_H_
73
+
74
+ #include <stdint.h>
75
+
76
+ #ifdef __cplusplus
77
+ extern "C" {
78
+ #endif
79
+
80
+ // See https://github.com/pytorch/pytorch/blob/main/c10/macros/Export.h
81
+ // We will set SHERPA_ONNX_BUILD_SHARED_LIBS and SHERPA_ONNX_BUILD_MAIN_LIB in
82
+ // CMakeLists.txt
83
+
84
+ #if defined(__GNUC__)
85
+ #pragma GCC diagnostic push
86
+ #pragma GCC diagnostic ignored "-Wattributes"
87
+ #endif
88
+
89
+ #if defined(_WIN32)
90
+ #if defined(SHERPA_ONNX_BUILD_SHARED_LIBS)
91
+ #define SHERPA_ONNX_EXPORT __declspec(dllexport)
92
+ #define SHERPA_ONNX_IMPORT __declspec(dllimport)
93
+ #else
94
+ #define SHERPA_ONNX_EXPORT
95
+ #define SHERPA_ONNX_IMPORT
96
+ #endif
97
+ #else // WIN32
98
+ #define SHERPA_ONNX_EXPORT __attribute__((visibility("default")))
99
+
100
+ #define SHERPA_ONNX_IMPORT SHERPA_ONNX_EXPORT
101
+ #endif // WIN32
102
+
103
+ #if defined(SHERPA_ONNX_BUILD_MAIN_LIB)
104
+ #define SHERPA_ONNX_API SHERPA_ONNX_EXPORT
105
+ #else
106
+ #define SHERPA_ONNX_API SHERPA_ONNX_IMPORT
107
+ #endif
108
+
109
+ #ifndef SHERPA_ONNX_DEPRECATED
110
+ #if defined(_MSC_VER)
111
+ #define SHERPA_ONNX_DEPRECATED(msg) __declspec(deprecated(msg))
112
+ #elif defined(__GNUC__) || defined(__clang__)
113
+ #define SHERPA_ONNX_DEPRECATED(msg) __attribute__((deprecated(msg)))
114
+ #else
115
+ #define SHERPA_ONNX_DEPRECATED(msg)
116
+ #endif
117
+ #endif
118
+
119
+ /**
120
+ * @brief Return the sherpa-onnx version string.
121
+ *
122
+ * The returned pointer refers to statically allocated memory owned by the
123
+ * library. Do not free it and do not modify it.
124
+ *
125
+ * @return Version string, for example `"1.12.1"`.
126
+ *
127
+ * @code
128
+ * printf("sherpa-onnx version: %s\n", SherpaOnnxGetVersionStr());
129
+ * @endcode
130
+ */
131
+ SHERPA_ONNX_API const char *SherpaOnnxGetVersionStr();
132
+
133
+ /**
134
+ * @brief Return the Git SHA1 used to build the library.
135
+ *
136
+ * The returned pointer refers to statically allocated memory owned by the
137
+ * library. Do not free it and do not modify it.
138
+ *
139
+ * @return Short Git SHA1 string, for example `"6982b86c"`.
140
+ */
141
+ SHERPA_ONNX_API const char *SherpaOnnxGetGitSha1();
142
+
143
+ /**
144
+ * @brief Return the Git build date used to build the library.
145
+ *
146
+ * The returned pointer refers to statically allocated memory owned by the
147
+ * library. Do not free it and do not modify it.
148
+ *
149
+ * @return Build date string, for example `"Fri Jun 20 11:22:52 2025"`.
150
+ */
151
+ SHERPA_ONNX_API const char *SherpaOnnxGetGitDate();
152
+
153
+ /**
154
+ * @brief Check whether a file exists.
155
+ *
156
+ * @param filename File path to test.
157
+ * @return 1 if the file exists; otherwise 0.
158
+ *
159
+ * @code
160
+ * if (!SherpaOnnxFileExists("./Obama.wav")) {
161
+ * fprintf(stderr, "Please download Obama.wav\n");
162
+ * }
163
+ * @endcode
164
+ */
165
+ SHERPA_ONNX_API int32_t SherpaOnnxFileExists(const char *filename);
166
+
167
+ /**
168
+ * @brief Configuration for a streaming transducer model.
169
+ *
170
+ * Please refer to
171
+ * https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
172
+ * to download compatible pre-trained models.
173
+ */
174
+ typedef struct SherpaOnnxOnlineTransducerModelConfig {
175
+ /** Path to the encoder ONNX model. */
176
+ const char *encoder;
177
+ /** Path to the decoder ONNX model. */
178
+ const char *decoder;
179
+ /** Path to the joiner ONNX model. */
180
+ const char *joiner;
181
+ } SherpaOnnxOnlineTransducerModelConfig;
182
+
183
+ /**
184
+ * @brief Configuration for a streaming Paraformer model.
185
+ *
186
+ * Please visit
187
+ * https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-paraformer/index.html
188
+ * to download compatible models.
189
+ */
190
+ typedef struct SherpaOnnxOnlineParaformerModelConfig {
191
+ /** Path to the encoder ONNX model. */
192
+ const char *encoder;
193
+ /** Path to the decoder ONNX model. */
194
+ const char *decoder;
195
+ } SherpaOnnxOnlineParaformerModelConfig;
196
+
197
+ /**
198
+ * @brief Configuration for a streaming Zipformer2 CTC model.
199
+ */
200
+ typedef struct SherpaOnnxOnlineZipformer2CtcModelConfig {
201
+ /** Path to the ONNX model. */
202
+ const char *model;
203
+ } SherpaOnnxOnlineZipformer2CtcModelConfig;
204
+
205
+ /** @brief Configuration for a streaming NeMo CTC model. */
206
+ typedef struct SherpaOnnxOnlineNemoCtcModelConfig {
207
+ /** Path to the ONNX model. */
208
+ const char *model;
209
+ } SherpaOnnxOnlineNemoCtcModelConfig;
210
+
211
+ /** @brief Configuration for a streaming T-One CTC model. */
212
+ typedef struct SherpaOnnxOnlineToneCtcModelConfig {
213
+ /** Path to the ONNX model. */
214
+ const char *model;
215
+ } SherpaOnnxOnlineToneCtcModelConfig;
216
+
217
+ /**
218
+ * @brief Model configuration shared by streaming ASR recognizers.
219
+ *
220
+ * Zero-initialize this struct before use, then fill in the sub-config for the
221
+ * model family you want to use together with the shared fields such as
222
+ * @c tokens, @c provider, and @c num_threads.
223
+ *
224
+ * Exactly one model family should be configured for each recognizer. For
225
+ * example, set only one of @c transducer, @c paraformer, @c zipformer2_ctc,
226
+ * @c nemo_ctc, or @c t_one_ctc.
227
+ *
228
+ * If multiple model families are configured at the same time, the
229
+ * implementation will choose one of them, and which one is used is
230
+ * implementation-defined. Do not rely on any precedence rule.
231
+ */
232
+ typedef struct SherpaOnnxOnlineModelConfig {
233
+ /** Streaming transducer model files. */
234
+ SherpaOnnxOnlineTransducerModelConfig transducer;
235
+ /** Streaming Paraformer model files. */
236
+ SherpaOnnxOnlineParaformerModelConfig paraformer;
237
+ /** Streaming Zipformer2 CTC model files. */
238
+ SherpaOnnxOnlineZipformer2CtcModelConfig zipformer2_ctc;
239
+ /** Path to the tokens file. */
240
+ const char *tokens;
241
+ /** Number of threads used by the ONNX Runtime backend. */
242
+ int32_t num_threads;
243
+ /** Execution provider, for example "cpu", "cuda", or "coreml". */
244
+ const char *provider;
245
+ /** Non-zero to print model debug information. */
246
+ int32_t debug;
247
+ /** Optional explicit model type override. */
248
+ const char *model_type;
249
+ /**
250
+ * Modeling unit used by the tokens.
251
+ *
252
+ * Valid values include:
253
+ * - "cjkchar"
254
+ * - "bpe"
255
+ * - "cjkchar+bpe"
256
+ */
257
+ const char *modeling_unit;
258
+ /** Path to the BPE vocabulary file when BPE is used. */
259
+ const char *bpe_vocab;
260
+ /** Optional in-memory tokens data. Used instead of @c tokens when non-NULL.
261
+ */
262
+ const char *tokens_buf;
263
+ /** Size in bytes of @c tokens_buf, excluding the trailing '\0'. */
264
+ int32_t tokens_buf_size;
265
+ /** Streaming NeMo CTC model files. */
266
+ SherpaOnnxOnlineNemoCtcModelConfig nemo_ctc;
267
+ /** Streaming T-One CTC model files. */
268
+ SherpaOnnxOnlineToneCtcModelConfig t_one_ctc;
269
+ } SherpaOnnxOnlineModelConfig;
270
+
271
+ /**
272
+ * @brief Feature extraction settings for ASR.
273
+ *
274
+ * The bundled ASR models typically expect 16 kHz mono audio and 80-bin
275
+ * features.
276
+ */
277
+ typedef struct SherpaOnnxFeatureConfig {
278
+ /** Sample rate expected by the model, for example 16000. */
279
+ int32_t sample_rate;
280
+
281
+ /** Feature dimension expected by the model, for example 80. */
282
+ int32_t feature_dim;
283
+ } SherpaOnnxFeatureConfig;
284
+
285
+ /** @brief Configuration for HLG/FST-based online CTC decoding. */
286
+ typedef struct SherpaOnnxOnlineCtcFstDecoderConfig {
287
+ /** Path to the decoding graph. */
288
+ const char *graph;
289
+ /** Decoder max-active setting. */
290
+ int32_t max_active;
291
+ } SherpaOnnxOnlineCtcFstDecoderConfig;
292
+
293
+ /** @brief Configuration for homophone replacement. */
294
+ typedef struct SherpaOnnxHomophoneReplacerConfig {
295
+ /** Unused legacy field kept for ABI compatibility. */
296
+ const char *dict_dir;
297
+ /** Path to the lexicon used by the homophone replacer. */
298
+ const char *lexicon;
299
+ /** Path to the replacement rule FST file. */
300
+ const char *rule_fsts;
301
+ } SherpaOnnxHomophoneReplacerConfig;
302
+
303
+ /**
304
+ * @brief Configuration for a streaming ASR recognizer.
305
+ *
306
+ * Zero-initialize this struct before use. Then fill in @c feat_config,
307
+ * @c model_config, and any optional decoding, endpoint, or hotword settings.
308
+ *
309
+ * Example model package:
310
+ * `sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20`
311
+ *
312
+ * @code
313
+ * SherpaOnnxOnlineRecognizerConfig config;
314
+ * memset(&config, 0, sizeof(config));
315
+ *
316
+ * config.feat_config.sample_rate = 16000;
317
+ * config.feat_config.feature_dim = 80;
318
+ *
319
+ * config.model_config.transducer.encoder =
320
+ * "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
321
+ * "encoder-epoch-99-avg-1.int8.onnx";
322
+ * config.model_config.transducer.decoder =
323
+ * "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
324
+ * "decoder-epoch-99-avg-1.onnx";
325
+ * config.model_config.transducer.joiner =
326
+ * "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
327
+ * "joiner-epoch-99-avg-1.int8.onnx";
328
+ * config.model_config.tokens =
329
+ * "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
330
+ * "tokens.txt";
331
+ * config.model_config.provider = "cpu";
332
+ * config.model_config.num_threads = 1;
333
+ *
334
+ * config.decoding_method = "greedy_search";
335
+ * @endcode
336
+ * @see SherpaOnnxCreateOnlineRecognizer
337
+ */
338
+ typedef struct SherpaOnnxOnlineRecognizerConfig {
339
+ /** Feature extraction settings. */
340
+ SherpaOnnxFeatureConfig feat_config;
341
+ /** Streaming model configuration. */
342
+ SherpaOnnxOnlineModelConfig model_config;
343
+
344
+ /** Decoding method, for example "greedy_search" or "modified_beam_search". */
345
+ const char *decoding_method;
346
+
347
+ /** Number of active paths for modified beam search. */
348
+ int32_t max_active_paths;
349
+
350
+ /** Set to non-zero to enable endpoint detection. */
351
+ int32_t enable_endpoint;
352
+
353
+ /** Endpoint rule 1 trailing silence threshold in seconds. */
354
+ float rule1_min_trailing_silence;
355
+
356
+ /** Endpoint rule 2 trailing silence threshold in seconds. */
357
+ float rule2_min_trailing_silence;
358
+
359
+ /** Endpoint rule 3 utterance-length threshold in seconds. */
360
+ float rule3_min_utterance_length;
361
+
362
+ /** Path to a hotwords file. */
363
+ const char *hotwords_file;
364
+
365
+ /** Bonus score added to each hotword token during decoding. */
366
+ float hotwords_score;
367
+
368
+ /** Optional HLG/FST online CTC decoder configuration. */
369
+ SherpaOnnxOnlineCtcFstDecoderConfig ctc_fst_decoder_config;
370
+ /** Path to punctuation or text-processing rule FSTs. */
371
+ const char *rule_fsts;
372
+ /** Path to FAR archives used by text-processing rules. */
373
+ const char *rule_fars;
374
+ /** Optional blank penalty applied during decoding. */
375
+ float blank_penalty;
376
+
377
+ /** Optional in-memory hotwords text used instead of @c hotwords_file. */
378
+ const char *hotwords_buf;
379
+ /** Size in bytes of @c hotwords_buf, excluding the trailing '\0'. */
380
+ int32_t hotwords_buf_size;
381
+ /** Optional homophone replacement configuration. */
382
+ SherpaOnnxHomophoneReplacerConfig hr;
383
+ } SherpaOnnxOnlineRecognizerConfig;
384
+
385
+ /**
386
+ * @brief Incremental recognition result for a streaming ASR stream.
387
+ *
388
+ * All pointers in this struct are owned by the result object returned from
389
+ * SherpaOnnxGetOnlineStreamResult() and become invalid after
390
+ * SherpaOnnxDestroyOnlineRecognizerResult() is called.
391
+ * @see SherpaOnnxGetOnlineStreamResult
392
+ */
393
+ typedef struct SherpaOnnxOnlineRecognizerResult {
394
+ /** Recognized text accumulated so far. */
395
+ const char *text;
396
+
397
+ /**
398
+ * Contiguous memory block containing token strings separated by '\0'.
399
+ *
400
+ * Use @c tokens_arr for convenient indexed access.
401
+ */
402
+ const char *tokens;
403
+
404
+ /** Array of @c count pointers into @c tokens. */
405
+ const char *const *tokens_arr;
406
+
407
+ /**
408
+ * Optional token timestamps in seconds.
409
+ *
410
+ * This field may be NULL when the model does not provide timestamps.
411
+ * When non-NULL, it contains @c count entries and is parallel to
412
+ * @c tokens_arr.
413
+ */
414
+ float *timestamps;
415
+
416
+ /** Number of entries in @c tokens_arr and, when available, @c timestamps. */
417
+ int32_t count;
418
+
419
+ /** JSON serialization of the result. */
420
+ const char *json;
421
+ } SherpaOnnxOnlineRecognizerResult;
422
+
423
+ /** @brief Streaming recognizer handle. */
424
+ typedef struct SherpaOnnxOnlineRecognizer SherpaOnnxOnlineRecognizer;
425
+ /** @brief Streaming decoding state for one utterance or stream. */
426
+ typedef struct SherpaOnnxOnlineStream SherpaOnnxOnlineStream;
427
+
428
+ /**
429
+ * @brief Create a streaming ASR recognizer.
430
+ *
431
+ * The returned recognizer runs locally and does not require Internet access.
432
+ *
433
+ * @param config Recognizer configuration.
434
+ * @return A recognizer handle on success, or NULL if the configuration is
435
+ * invalid. The caller owns the returned object and must free it with
436
+ * SherpaOnnxDestroyOnlineRecognizer().
437
+ *
438
+ * @code
439
+ * SherpaOnnxOnlineRecognizerConfig config;
440
+ * memset(&config, 0, sizeof(config));
441
+ * config.feat_config.sample_rate = 16000;
442
+ * config.feat_config.feature_dim = 80;
443
+ * config.model_config.transducer.encoder =
444
+ * "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
445
+ * "encoder-epoch-99-avg-1.int8.onnx";
446
+ * config.model_config.transducer.decoder =
447
+ * "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
448
+ * "decoder-epoch-99-avg-1.onnx";
449
+ * config.model_config.transducer.joiner =
450
+ * "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
451
+ * "joiner-epoch-99-avg-1.int8.onnx";
452
+ * config.model_config.tokens =
453
+ * "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
454
+ * "tokens.txt";
455
+ * config.model_config.provider = "cpu";
456
+ * config.model_config.num_threads = 1;
457
+ * config.decoding_method = "greedy_search";
458
+ *
459
+ * const SherpaOnnxOnlineRecognizer *recognizer =
460
+ * SherpaOnnxCreateOnlineRecognizer(&config);
461
+ * @endcode
462
+ * @see SherpaOnnxOnlineRecognizerConfig, SherpaOnnxDestroyOnlineRecognizer
463
+ */
464
+ SHERPA_ONNX_API const SherpaOnnxOnlineRecognizer *
465
+ SherpaOnnxCreateOnlineRecognizer(
466
+ const SherpaOnnxOnlineRecognizerConfig *config);
467
+
468
+ /**
469
+ * @brief Destroy a streaming recognizer.
470
+ *
471
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
472
+ *
473
+ * @code
474
+ * SherpaOnnxDestroyOnlineRecognizer(recognizer);
475
+ * recognizer = NULL;
476
+ * @endcode
477
+ * @see SherpaOnnxCreateOnlineRecognizer
478
+ */
479
+ SHERPA_ONNX_API void SherpaOnnxDestroyOnlineRecognizer(
480
+ const SherpaOnnxOnlineRecognizer *recognizer);
481
+
482
+ /**
483
+ * @brief Create a streaming ASR state object.
484
+ *
485
+ * One stream corresponds to one decoding state. Reuse the same recognizer to
486
+ * create multiple streams.
487
+ *
488
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
489
+ * @return A newly created stream. The caller owns the returned object and must
490
+ * free it with SherpaOnnxDestroyOnlineStream().
491
+ *
492
+ * @code
493
+ * const SherpaOnnxWave *wave = SherpaOnnxReadWave(
494
+ * "./sherpa-onnx-streaming-paraformer-bilingual-zh-en/test_wavs/0.wav");
495
+ * const SherpaOnnxOnlineStream *stream =
496
+ * SherpaOnnxCreateOnlineStream(recognizer);
497
+ * @endcode
498
+ * @see SherpaOnnxDestroyOnlineStream
499
+ */
500
+ SHERPA_ONNX_API const SherpaOnnxOnlineStream *SherpaOnnxCreateOnlineStream(
501
+ const SherpaOnnxOnlineRecognizer *recognizer);
502
+
503
+ /**
504
+ * @brief Create a streaming ASR state object with per-stream hotwords.
505
+ *
506
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
507
+ * @param hotwords Hotwords text to associate with the stream.
508
+ * @return A newly created stream. The caller owns the returned object and must
509
+ * free it with SherpaOnnxDestroyOnlineStream().
510
+ *
511
+ * @code
512
+ * const SherpaOnnxOnlineStream *stream =
513
+ * SherpaOnnxCreateOnlineStreamWithHotwords(recognizer,
514
+ * "▁HELLO ▁WORLD");
515
+ * @endcode
516
+ */
517
+ SHERPA_ONNX_API const SherpaOnnxOnlineStream *
518
+ SherpaOnnxCreateOnlineStreamWithHotwords(
519
+ const SherpaOnnxOnlineRecognizer *recognizer, const char *hotwords);
520
+
521
+ /**
522
+ * @brief Destroy a streaming ASR state object.
523
+ *
524
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream() or
525
+ * SherpaOnnxCreateOnlineStreamWithHotwords().
526
+ *
527
+ * @code
528
+ * SherpaOnnxDestroyOnlineStream(stream);
529
+ * stream = NULL;
530
+ * @endcode
531
+ * @see SherpaOnnxCreateOnlineStream
532
+ */
533
+ SHERPA_ONNX_API void SherpaOnnxDestroyOnlineStream(
534
+ const SherpaOnnxOnlineStream *stream);
535
+
536
+ /**
537
+ * @brief Append audio samples to a streaming ASR stream.
538
+ *
539
+ * The input is mono floating-point PCM normalized to the range [-1, 1].
540
+ * If @p sample_rate differs from the recognizer feature sample rate,
541
+ * sherpa-onnx resamples internally.
542
+ *
543
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
544
+ * @param sample_rate Sample rate of @p samples.
545
+ * @param samples Pointer to @p n samples in the range [-1, 1].
546
+ * @param n Number of samples.
547
+ *
548
+ * @code
549
+ * int32_t start = 0;
550
+ * int32_t chunk_size = 3200; // 0.2 seconds at 16 kHz
551
+ * SherpaOnnxOnlineStreamAcceptWaveform(stream, wave->sample_rate,
552
+ * wave->samples + start, chunk_size);
553
+ * @endcode
554
+ * @see SherpaOnnxCreateOnlineStream, SherpaOnnxDecodeOnlineStream
555
+ */
556
+ SHERPA_ONNX_API void SherpaOnnxOnlineStreamAcceptWaveform(
557
+ const SherpaOnnxOnlineStream *stream, int32_t sample_rate,
558
+ const float *samples, int32_t n);
559
+
560
+ /**
561
+ * @brief Check whether a streaming ASR stream is ready to decode.
562
+ *
563
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
564
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
565
+ * @return 1 if enough frames are available for decoding; otherwise 0.
566
+ *
567
+ * @code
568
+ * if (SherpaOnnxIsOnlineStreamReady(recognizer, stream)) {
569
+ * SherpaOnnxDecodeOnlineStream(recognizer, stream);
570
+ * }
571
+ * @endcode
572
+ */
573
+ SHERPA_ONNX_API int32_t
574
+ SherpaOnnxIsOnlineStreamReady(const SherpaOnnxOnlineRecognizer *recognizer,
575
+ const SherpaOnnxOnlineStream *stream);
576
+
577
+ /**
578
+ * @brief Decode one step of a streaming ASR stream.
579
+ *
580
+ * Call this only when SherpaOnnxIsOnlineStreamReady() returns 1.
581
+ *
582
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
583
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
584
+ *
585
+ * @code
586
+ * SherpaOnnxOnlineStreamAcceptWaveform(stream, sample_rate, samples, n);
587
+ * while (SherpaOnnxIsOnlineStreamReady(recognizer, stream)) {
588
+ * SherpaOnnxDecodeOnlineStream(recognizer, stream);
589
+ * }
590
+ * @endcode
591
+ * @see SherpaOnnxIsOnlineStreamReady, SherpaOnnxGetOnlineStreamResult
592
+ */
593
+ SHERPA_ONNX_API void SherpaOnnxDecodeOnlineStream(
594
+ const SherpaOnnxOnlineRecognizer *recognizer,
595
+ const SherpaOnnxOnlineStream *stream);
596
+
597
+ /**
598
+ * @brief Decode multiple streaming ASR streams in parallel.
599
+ *
600
+ * The caller must ensure every stream in @p streams is ready before calling
601
+ * this function.
602
+ *
603
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
604
+ * @param streams Array of @p n stream pointers.
605
+ * @param n Number of streams in @p streams.
606
+ *
607
+ * @code
608
+ * const SherpaOnnxOnlineStream *streams[2] = {stream1, stream2};
609
+ * SherpaOnnxDecodeMultipleOnlineStreams(recognizer, streams, 2);
610
+ * @endcode
611
+ */
612
+ SHERPA_ONNX_API void SherpaOnnxDecodeMultipleOnlineStreams(
613
+ const SherpaOnnxOnlineRecognizer *recognizer,
614
+ const SherpaOnnxOnlineStream **streams, int32_t n);
615
+
616
+ /**
617
+ * @brief Get the current streaming ASR result for a stream.
618
+ *
619
+ * The returned snapshot is independent from the stream state. The caller owns
620
+ * it and must free it with SherpaOnnxDestroyOnlineRecognizerResult().
621
+ *
622
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
623
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
624
+ * @return A newly allocated result snapshot.
625
+ *
626
+ * @code
627
+ * const SherpaOnnxOnlineRecognizerResult *r =
628
+ * SherpaOnnxGetOnlineStreamResult(recognizer, stream);
629
+ * printf("%s\n", r->text);
630
+ * // r->tokens_arr[i] and r->timestamps[i] are parallel when timestamps
631
+ * // are available.
632
+ * SherpaOnnxDestroyOnlineRecognizerResult(r);
633
+ * @endcode
634
+ * @see SherpaOnnxDestroyOnlineRecognizerResult
635
+ */
636
+ SHERPA_ONNX_API const SherpaOnnxOnlineRecognizerResult *
637
+ SherpaOnnxGetOnlineStreamResult(const SherpaOnnxOnlineRecognizer *recognizer,
638
+ const SherpaOnnxOnlineStream *stream);
639
+
640
+ /**
641
+ * @brief Destroy a result returned by SherpaOnnxGetOnlineStreamResult().
642
+ *
643
+ * @param r A pointer returned by SherpaOnnxGetOnlineStreamResult().
644
+ *
645
+ * @code
646
+ * SherpaOnnxDestroyOnlineRecognizerResult(r);
647
+ * r = NULL;
648
+ * @endcode
649
+ * @see SherpaOnnxGetOnlineStreamResult
650
+ */
651
+ SHERPA_ONNX_API void SherpaOnnxDestroyOnlineRecognizerResult(
652
+ const SherpaOnnxOnlineRecognizerResult *r);
653
+
654
+ /**
655
+ * @brief Get the current streaming ASR result as JSON.
656
+ *
657
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
658
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
659
+ * @return A newly allocated JSON string. Free it with
660
+ * SherpaOnnxDestroyOnlineStreamResultJson().
661
+ *
662
+ * @code
663
+ * const char *json =
664
+ * SherpaOnnxGetOnlineStreamResultAsJson(recognizer, stream);
665
+ * puts(json);
666
+ * SherpaOnnxDestroyOnlineStreamResultJson(json);
667
+ * @endcode
668
+ */
669
+ SHERPA_ONNX_API const char *SherpaOnnxGetOnlineStreamResultAsJson(
670
+ const SherpaOnnxOnlineRecognizer *recognizer,
671
+ const SherpaOnnxOnlineStream *stream);
672
+
673
+ /**
674
+ * @brief Free a JSON string returned by
675
+ * SherpaOnnxGetOnlineStreamResultAsJson().
676
+ *
677
+ * @param s A pointer returned by SherpaOnnxGetOnlineStreamResultAsJson().
678
+ *
679
+ * @code
680
+ * SherpaOnnxDestroyOnlineStreamResultJson(json);
681
+ * json = NULL;
682
+ * @endcode
683
+ */
684
+ SHERPA_ONNX_API void SherpaOnnxDestroyOnlineStreamResultJson(const char *s);
685
+
686
+ /**
687
+ * @brief Reset a streaming ASR stream after an endpoint or utterance boundary.
688
+ *
689
+ * This clears the decoder state for the stream so that it can be reused for a
690
+ * new utterance.
691
+ *
692
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
693
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
694
+ *
695
+ * @code
696
+ * if (SherpaOnnxOnlineStreamIsEndpoint(recognizer, stream)) {
697
+ * SherpaOnnxOnlineStreamReset(recognizer, stream);
698
+ * }
699
+ * @endcode
700
+ */
701
+ SHERPA_ONNX_API void SherpaOnnxOnlineStreamReset(
702
+ const SherpaOnnxOnlineRecognizer *recognizer,
703
+ const SherpaOnnxOnlineStream *stream);
704
+
705
+ /**
706
+ * @brief Signal end-of-input for a streaming ASR stream.
707
+ *
708
+ * After calling this function, do not append more samples to the stream.
709
+ *
710
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
711
+ *
712
+ * @code
713
+ * SherpaOnnxOnlineStreamInputFinished(stream);
714
+ * @endcode
715
+ */
716
+ SHERPA_ONNX_API void SherpaOnnxOnlineStreamInputFinished(
717
+ const SherpaOnnxOnlineStream *stream);
718
+
719
+ /**
720
+ * @brief Set a per-stream runtime option.
721
+ *
722
+ * This is a generic extension point for model-specific or runtime-specific
723
+ * options such as "is_final" for streaming Paraformer.
724
+ *
725
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
726
+ * @param key Option name.
727
+ * @param value Option value represented as text.
728
+ *
729
+ * @code
730
+ * SherpaOnnxOnlineStreamSetOption(stream, "is_final", "1");
731
+ * @endcode
732
+ */
733
+ SHERPA_ONNX_API void SherpaOnnxOnlineStreamSetOption(
734
+ const SherpaOnnxOnlineStream *stream, const char *key, const char *value);
735
+
736
+ /**
737
+ * @brief Get a per-stream runtime option.
738
+ *
739
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
740
+ * @param key Option name.
741
+ * @return The option value. The returned pointer is owned by the stream, must
742
+ * not be freed by the caller, and may be invalidated if the option is
743
+ * overwritten or the stream is destroyed.
744
+ *
745
+ * @code
746
+ * const char *value = SherpaOnnxOnlineStreamGetOption(stream, "is_final");
747
+ * @endcode
748
+ */
749
+ SHERPA_ONNX_API const char *SherpaOnnxOnlineStreamGetOption(
750
+ const SherpaOnnxOnlineStream *stream, const char *key);
751
+
752
+ /**
753
+ * @brief Check whether a per-stream runtime option exists.
754
+ *
755
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
756
+ * @param key Option name.
757
+ * @return 1 if the option exists; otherwise 0.
758
+ *
759
+ * @code
760
+ * int32_t has_option = SherpaOnnxOnlineStreamHasOption(stream, "is_final");
761
+ * @endcode
762
+ */
763
+ SHERPA_ONNX_API int32_t SherpaOnnxOnlineStreamHasOption(
764
+ const SherpaOnnxOnlineStream *stream, const char *key);
765
+
766
+ /**
767
+ * @brief Check whether endpoint detection has triggered for a stream.
768
+ *
769
+ * @param recognizer A pointer returned by SherpaOnnxCreateOnlineRecognizer().
770
+ * @param stream A pointer returned by SherpaOnnxCreateOnlineStream().
771
+ * @return 1 if an endpoint is detected; otherwise 0.
772
+ *
773
+ * @code
774
+ * if (SherpaOnnxOnlineStreamIsEndpoint(recognizer, stream)) {
775
+ * SherpaOnnxOnlineStreamReset(recognizer, stream);
776
+ * }
777
+ * @endcode
778
+ */
779
+ SHERPA_ONNX_API int32_t
780
+ SherpaOnnxOnlineStreamIsEndpoint(const SherpaOnnxOnlineRecognizer *recognizer,
781
+ const SherpaOnnxOnlineStream *stream);
782
+
783
+ /**
784
+ * @brief Helper for pretty-printing incremental recognition results.
785
+ *
786
+ * This utility is mainly used by example programs on Linux and macOS.
787
+ */
788
+ typedef struct SherpaOnnxDisplay SherpaOnnxDisplay;
789
+
790
+ /**
791
+ * @brief Create a display helper.
792
+ *
793
+ * @param max_word_per_line Maximum number of words to show per line.
794
+ * @return A newly allocated display helper. Free it with
795
+ * SherpaOnnxDestroyDisplay().
796
+ *
797
+ * @code
798
+ * const SherpaOnnxDisplay *display = SherpaOnnxCreateDisplay(50);
799
+ * @endcode
800
+ */
801
+ SHERPA_ONNX_API const SherpaOnnxDisplay *SherpaOnnxCreateDisplay(
802
+ int32_t max_word_per_line);
803
+
804
+ /**
805
+ * @brief Destroy a display helper.
806
+ *
807
+ * @param display A pointer returned by SherpaOnnxCreateDisplay().
808
+ */
809
+ SHERPA_ONNX_API void SherpaOnnxDestroyDisplay(const SherpaOnnxDisplay *display);
810
+
811
+ /**
812
+ * @brief Print one line of text using the display helper.
813
+ *
814
+ * @param display A pointer returned by SherpaOnnxCreateDisplay().
815
+ * @param idx Segment or utterance index to print.
816
+ * @param s Text to print.
817
+ *
818
+ * @code
819
+ * SherpaOnnxPrint(display, segment_id, r->text);
820
+ * @endcode
821
+ */
822
+ SHERPA_ONNX_API void SherpaOnnxPrint(const SherpaOnnxDisplay *display,
823
+ int32_t idx, const char *s);
824
+ // ============================================================
825
+ // For offline ASR (i.e., non-streaming ASR)
826
+ // ============================================================
827
+
828
+ /**
829
+ * @brief Configuration for a non-streaming transducer model.
830
+ */
831
+ typedef struct SherpaOnnxOfflineTransducerModelConfig {
832
+ /** Path to the encoder ONNX model. */
833
+ const char *encoder;
834
+ /** Path to the decoder ONNX model. */
835
+ const char *decoder;
836
+ /** Path to the joiner ONNX model. */
837
+ const char *joiner;
838
+ } SherpaOnnxOfflineTransducerModelConfig;
839
+
840
+ /** @brief Configuration for a non-streaming Paraformer model. */
841
+ typedef struct SherpaOnnxOfflineParaformerModelConfig {
842
+ /** Path to the ONNX model. */
843
+ const char *model;
844
+ } SherpaOnnxOfflineParaformerModelConfig;
845
+
846
+ /** @brief Configuration for a non-streaming NeMo CTC model. */
847
+ typedef struct SherpaOnnxOfflineNemoEncDecCtcModelConfig {
848
+ /** Path to the ONNX model. */
849
+ const char *model;
850
+ } SherpaOnnxOfflineNemoEncDecCtcModelConfig;
851
+
852
+ /**
853
+ * @brief Configuration for a non-streaming Whisper model.
854
+ */
855
+ typedef struct SherpaOnnxOfflineWhisperModelConfig {
856
+ /** Path to the encoder ONNX model. */
857
+ const char *encoder;
858
+ /** Path to the decoder ONNX model. */
859
+ const char *decoder;
860
+ /** Optional language hint, for example "en" or "zh". */
861
+ const char *language;
862
+ /** Optional Whisper task such as "transcribe" or "translate". */
863
+ const char *task;
864
+ /** Number of tail padding frames appended internally. */
865
+ int32_t tail_paddings;
866
+
867
+ /** Non-zero to enable token-level timestamps when supported by the model. */
868
+ int32_t enable_token_timestamps;
869
+
870
+ /** Non-zero to enable Whisper segment-level timestamps. */
871
+ int32_t enable_segment_timestamps;
872
+ } SherpaOnnxOfflineWhisperModelConfig;
873
+
874
+ /** @brief Configuration for a Canary model. */
875
+ typedef struct SherpaOnnxOfflineCanaryModelConfig {
876
+ /** Path to the encoder ONNX model. */
877
+ const char *encoder;
878
+ /** Path to the decoder ONNX model. */
879
+ const char *decoder;
880
+ /** Source language hint. */
881
+ const char *src_lang;
882
+ /** Target language hint. */
883
+ const char *tgt_lang;
884
+ /** Non-zero to enable punctuation and capitalization when supported. */
885
+ int32_t use_pnc;
886
+ } SherpaOnnxOfflineCanaryModelConfig;
887
+
888
+ /** @brief Configuration for a Cohere Transcribe model. */
889
+ typedef struct SherpaOnnxOfflineCohereTranscribeModelConfig {
890
+ /** Path to the encoder ONNX model. */
891
+ const char *encoder;
892
+ /** Path to the decoder ONNX model. */
893
+ const char *decoder;
894
+ /** Optional language hint, for example "en" or "zh". */
895
+ const char *language;
896
+ /** Non-zero to enable punctuation. */
897
+ int32_t use_punct;
898
+ /** Non-zero to enable inverse text normalization. */
899
+ int32_t use_itn;
900
+ } SherpaOnnxOfflineCohereTranscribeModelConfig;
901
+
902
+ /** @brief Configuration for a FireRedAsr encoder/decoder model. */
903
+ typedef struct SherpaOnnxOfflineFireRedAsrModelConfig {
904
+ /** Path to the encoder ONNX model. */
905
+ const char *encoder;
906
+ /** Path to the decoder ONNX model. */
907
+ const char *decoder;
908
+ } SherpaOnnxOfflineFireRedAsrModelConfig;
909
+
910
+ /** @brief Configuration for a FireRedAsr CTC model. */
911
+ typedef struct SherpaOnnxOfflineFireRedAsrCtcModelConfig {
912
+ /** Path to the ONNX model. */
913
+ const char *model;
914
+ } SherpaOnnxOfflineFireRedAsrCtcModelConfig;
915
+
916
+ /** @brief Configuration for a Moonshine model. */
917
+ typedef struct SherpaOnnxOfflineMoonshineModelConfig {
918
+ /** Path to the preprocessor ONNX model. */
919
+ const char *preprocessor;
920
+ /** Path to the encoder ONNX model. */
921
+ const char *encoder;
922
+ /** Path to the uncached decoder ONNX model. */
923
+ const char *uncached_decoder;
924
+ /** Path to the cached decoder ONNX model. */
925
+ const char *cached_decoder;
926
+ /** Path to the merged decoder ONNX model. */
927
+ const char *merged_decoder;
928
+ } SherpaOnnxOfflineMoonshineModelConfig;
929
+
930
+ /** @brief Configuration for a TDNN model. */
931
+ typedef struct SherpaOnnxOfflineTdnnModelConfig {
932
+ /** Path to the ONNX model. */
933
+ const char *model;
934
+ } SherpaOnnxOfflineTdnnModelConfig;
935
+
936
+ /** @brief Configuration for an offline language model. */
937
+ typedef struct SherpaOnnxOfflineLMConfig {
938
+ /** Path to the language model. */
939
+ const char *model;
940
+ /** Interpolation scale for the language model. */
941
+ float scale;
942
+ } SherpaOnnxOfflineLMConfig;
943
+
944
+ /** @brief Configuration for a SenseVoice model. */
945
+ typedef struct SherpaOnnxOfflineSenseVoiceModelConfig {
946
+ /** Path to the ONNX model. */
947
+ const char *model;
948
+ /** Optional language hint. */
949
+ const char *language;
950
+ /** Non-zero to enable inverse text normalization. */
951
+ int32_t use_itn;
952
+ } SherpaOnnxOfflineSenseVoiceModelConfig;
953
+
954
+ /** @brief Configuration for a Dolphin model. */
955
+ typedef struct SherpaOnnxOfflineDolphinModelConfig {
956
+ /** Path to the ONNX model. */
957
+ const char *model;
958
+ } SherpaOnnxOfflineDolphinModelConfig;
959
+
960
+ /** @brief Configuration for an offline Zipformer CTC model. */
961
+ typedef struct SherpaOnnxOfflineZipformerCtcModelConfig {
962
+ /** Path to the ONNX model. */
963
+ const char *model;
964
+ } SherpaOnnxOfflineZipformerCtcModelConfig;
965
+
966
+ /** @brief Configuration for an offline WeNet CTC model. */
967
+ typedef struct SherpaOnnxOfflineWenetCtcModelConfig {
968
+ /** Path to the ONNX model. */
969
+ const char *model;
970
+ } SherpaOnnxOfflineWenetCtcModelConfig;
971
+
972
+ /** @brief Configuration for an omnilingual offline CTC model. */
973
+ typedef struct SherpaOnnxOfflineOmnilingualAsrCtcModelConfig {
974
+ /** Path to the ONNX model. */
975
+ const char *model;
976
+ } SherpaOnnxOfflineOmnilingualAsrCtcModelConfig;
977
+
978
+ /** @brief Configuration for an offline FunASR Nano model. */
979
+ typedef struct SherpaOnnxOfflineFunASRNanoModelConfig {
980
+ /** Path to the encoder adaptor. */
981
+ const char *encoder_adaptor;
982
+ /** Path to the LLM ONNX model. */
983
+ const char *llm;
984
+ /** Path to the embedding model. */
985
+ const char *embedding;
986
+ /** Path to the tokenizer file. */
987
+ const char *tokenizer;
988
+ /** System prompt. */
989
+ const char *system_prompt;
990
+ /** User prompt. */
991
+ const char *user_prompt;
992
+ /** Maximum number of generated tokens. */
993
+ int32_t max_new_tokens;
994
+ /** Sampling temperature. */
995
+ float temperature;
996
+ /** Top-p sampling threshold. */
997
+ float top_p;
998
+ /** Random seed. */
999
+ int32_t seed;
1000
+ /** Optional language hint. */
1001
+ const char *language;
1002
+ /** Non-zero to enable inverse text normalization. */
1003
+ int32_t itn;
1004
+ /** Optional hotwords text. */
1005
+ const char *hotwords;
1006
+ } SherpaOnnxOfflineFunASRNanoModelConfig;
1007
+
1008
+ /** @brief Configuration for an offline Qwen3-ASR model. */
1009
+ typedef struct SherpaOnnxOfflineQwen3ASRModelConfig {
1010
+ /** Path to the conv-frontend ONNX model. */
1011
+ const char *conv_frontend;
1012
+ /** Path to the encoder ONNX model. */
1013
+ const char *encoder;
1014
+ /** Path to the decoder ONNX model (with KV cache). */
1015
+ const char *decoder;
1016
+ /** Path to the tokenizer directory (e.g. containing `vocab.json`). */
1017
+ const char *tokenizer;
1018
+ /** Maximum total sequence length supported by the model. */
1019
+ int32_t max_total_len;
1020
+ /** Maximum number of new tokens to generate. */
1021
+ int32_t max_new_tokens;
1022
+ /** Sampling temperature. */
1023
+ float temperature;
1024
+ /** Top-p (nucleus) sampling threshold. */
1025
+ float top_p;
1026
+ /** Random seed for reproducible sampling. */
1027
+ int32_t seed;
1028
+ /** Optional comma-separated hotwords (UTF-8, ASCII ','), e.g. @c
1029
+ * "foo,bar,baz". */
1030
+ const char *hotwords;
1031
+ } SherpaOnnxOfflineQwen3ASRModelConfig;
1032
+
1033
+ /** @brief Configuration for a MedASR CTC model. */
1034
+ typedef struct SherpaOnnxOfflineMedAsrCtcModelConfig {
1035
+ /** Path to the ONNX model. */
1036
+ const char *model;
1037
+ } SherpaOnnxOfflineMedAsrCtcModelConfig;
1038
+
1039
+ /**
1040
+ * @brief Model configuration shared by offline ASR recognizers.
1041
+ *
1042
+ * Zero-initialize this struct before use, then fill in exactly the sub-config
1043
+ * needed by the model family you want to run.
1044
+ *
1045
+ * Exactly one model family should be configured for each recognizer. For
1046
+ * example, set only one of @c transducer, @c paraformer, @c nemo_ctc,
1047
+ * @c whisper, @c tdnn, @c sense_voice, @c moonshine, @c fire_red_asr,
1048
+ * @c dolphin, @c zipformer_ctc, @c canary, @c cohere_transcribe,
1049
+ * @c wenet_ctc, @c omnilingual, @c medasr, @c funasr_nano,
1050
+ * @c fire_red_asr_ctc, or @c qwen3_asr.
1051
+ *
1052
+ * If multiple model families are configured at the same time, the
1053
+ * implementation will choose one of them, and which one is used is
1054
+ * implementation-defined. Do not rely on any precedence rule.
1055
+ */
1056
+ typedef struct SherpaOnnxOfflineModelConfig {
1057
+ /** Non-streaming transducer model files. */
1058
+ SherpaOnnxOfflineTransducerModelConfig transducer;
1059
+ /** Non-streaming Paraformer model files. */
1060
+ SherpaOnnxOfflineParaformerModelConfig paraformer;
1061
+ /** Non-streaming NeMo CTC model files. */
1062
+ SherpaOnnxOfflineNemoEncDecCtcModelConfig nemo_ctc;
1063
+ /** Whisper model files and options. */
1064
+ SherpaOnnxOfflineWhisperModelConfig whisper;
1065
+ /** TDNN model files. */
1066
+ SherpaOnnxOfflineTdnnModelConfig tdnn;
1067
+
1068
+ /** Path to the tokens file. */
1069
+ const char *tokens;
1070
+ /** Number of backend threads. */
1071
+ int32_t num_threads;
1072
+ /** Non-zero to print debug information. */
1073
+ int32_t debug;
1074
+ /** Execution provider, for example "cpu" or "cuda". */
1075
+ const char *provider;
1076
+ /** Optional explicit model type override. */
1077
+ const char *model_type;
1078
+ /** Modeling unit, such as "cjkchar", "bpe", or "cjkchar+bpe". */
1079
+ const char *modeling_unit;
1080
+ /** Path to the BPE vocabulary file when BPE is used. */
1081
+ const char *bpe_vocab;
1082
+ /** Path to the TeleSpeech CTC model. */
1083
+ const char *telespeech_ctc;
1084
+ /** SenseVoice configuration. */
1085
+ SherpaOnnxOfflineSenseVoiceModelConfig sense_voice;
1086
+ /** Moonshine configuration. */
1087
+ SherpaOnnxOfflineMoonshineModelConfig moonshine;
1088
+ /** FireRedAsr configuration. */
1089
+ SherpaOnnxOfflineFireRedAsrModelConfig fire_red_asr;
1090
+ /** Dolphin configuration. */
1091
+ SherpaOnnxOfflineDolphinModelConfig dolphin;
1092
+ /** Zipformer CTC configuration. */
1093
+ SherpaOnnxOfflineZipformerCtcModelConfig zipformer_ctc;
1094
+ /** Canary configuration. */
1095
+ SherpaOnnxOfflineCanaryModelConfig canary;
1096
+ /** WeNet CTC configuration. */
1097
+ SherpaOnnxOfflineWenetCtcModelConfig wenet_ctc;
1098
+ /** Omnilingual CTC configuration. */
1099
+ SherpaOnnxOfflineOmnilingualAsrCtcModelConfig omnilingual;
1100
+ /** MedASR configuration. */
1101
+ SherpaOnnxOfflineMedAsrCtcModelConfig medasr;
1102
+ /** FunASR Nano configuration. */
1103
+ SherpaOnnxOfflineFunASRNanoModelConfig funasr_nano;
1104
+ /** FireRedAsr CTC configuration. */
1105
+ SherpaOnnxOfflineFireRedAsrCtcModelConfig fire_red_asr_ctc;
1106
+ /** Qwen3-ASR configuration. */
1107
+ SherpaOnnxOfflineQwen3ASRModelConfig qwen3_asr;
1108
+ /** Cohere Transcribe configuration. */
1109
+ SherpaOnnxOfflineCohereTranscribeModelConfig cohere_transcribe;
1110
+ } SherpaOnnxOfflineModelConfig;
1111
+
1112
+ /**
1113
+ * @brief Configuration for a non-streaming ASR recognizer.
1114
+ *
1115
+ * Zero-initialize this struct before use.
1116
+ *
1117
+ * Example using Whisper:
1118
+ *
1119
+ * @code
1120
+ * SherpaOnnxOfflineRecognizerConfig config;
1121
+ * memset(&config, 0, sizeof(config));
1122
+ *
1123
+ * config.feat_config.sample_rate = 16000;
1124
+ * config.feat_config.feature_dim = 80;
1125
+ *
1126
+ * config.model_config.whisper.encoder =
1127
+ * "./sherpa-onnx-whisper-tiny/tiny-encoder.onnx";
1128
+ * config.model_config.whisper.decoder =
1129
+ * "./sherpa-onnx-whisper-tiny/tiny-decoder.onnx";
1130
+ * config.model_config.whisper.language = "en";
1131
+ * config.model_config.whisper.task = "transcribe";
1132
+ * config.model_config.tokens =
1133
+ * "./sherpa-onnx-whisper-tiny/tiny-tokens.txt";
1134
+ * config.model_config.provider = "cpu";
1135
+ * config.model_config.num_threads = 1;
1136
+ *
1137
+ * config.decoding_method = "greedy_search";
1138
+ * @endcode
1139
+ *
1140
+ * Example using SenseVoice:
1141
+ *
1142
+ * @code
1143
+ * config.model_config.sense_voice.model =
1144
+ * "./sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17-int8/model.int8.onnx";
1145
+ * config.model_config.sense_voice.language = "auto";
1146
+ * config.model_config.sense_voice.use_itn = 1;
1147
+ * config.model_config.tokens =
1148
+ * "./sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17-int8/tokens.txt";
1149
+ * @endcode
1150
+ *
1151
+ * Example using Parakeet TDT:
1152
+ *
1153
+ * @code
1154
+ * config.model_config.transducer.encoder =
1155
+ * "./sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8/encoder.int8.onnx";
1156
+ * config.model_config.transducer.decoder =
1157
+ * "./sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8/decoder.int8.onnx";
1158
+ * config.model_config.transducer.joiner =
1159
+ * "./sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8/joiner.int8.onnx";
1160
+ * config.model_config.tokens =
1161
+ * "./sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8/tokens.txt";
1162
+ * config.model_config.model_type = "nemo_transducer";
1163
+ * @endcode
1164
+ * @see SherpaOnnxCreateOfflineRecognizer
1165
+ */
1166
+ typedef struct SherpaOnnxOfflineRecognizerConfig {
1167
+ /** Feature extraction settings. */
1168
+ SherpaOnnxFeatureConfig feat_config;
1169
+ /** Offline model configuration. */
1170
+ SherpaOnnxOfflineModelConfig model_config;
1171
+ /** Optional language model configuration. */
1172
+ SherpaOnnxOfflineLMConfig lm_config;
1173
+
1174
+ /** Decoding method, for example "greedy_search" or "modified_beam_search". */
1175
+ const char *decoding_method;
1176
+ /** Number of active paths for modified beam search. */
1177
+ int32_t max_active_paths;
1178
+
1179
+ /** Path to a hotwords file. */
1180
+ const char *hotwords_file;
1181
+
1182
+ /** Bonus score added to each hotword token. */
1183
+ float hotwords_score;
1184
+ /** Path to punctuation or text-processing rule FSTs. */
1185
+ const char *rule_fsts;
1186
+ /** Path to FAR archives used by text-processing rules. */
1187
+ const char *rule_fars;
1188
+ /** Optional blank penalty applied during decoding. */
1189
+ float blank_penalty;
1190
+
1191
+ /** Optional homophone replacement configuration. */
1192
+ SherpaOnnxHomophoneReplacerConfig hr;
1193
+ } SherpaOnnxOfflineRecognizerConfig;
1194
+
1195
+ /** @brief Non-streaming recognizer handle. */
1196
+ typedef struct SherpaOnnxOfflineRecognizer SherpaOnnxOfflineRecognizer;
1197
+
1198
+ /** @brief Non-streaming decoding state for one utterance. */
1199
+ typedef struct SherpaOnnxOfflineStream SherpaOnnxOfflineStream;
1200
+
1201
+ /**
1202
+ * @brief Create a non-streaming ASR recognizer.
1203
+ *
1204
+ * @param config Recognizer configuration.
1205
+ * @return A recognizer handle on success, or NULL if the configuration is
1206
+ * invalid. The caller owns the returned object and must free it with
1207
+ * SherpaOnnxDestroyOfflineRecognizer().
1208
+ *
1209
+ * Whisper example:
1210
+ *
1211
+ * @code
1212
+ * SherpaOnnxOfflineRecognizerConfig config;
1213
+ * memset(&config, 0, sizeof(config));
1214
+ * config.feat_config.sample_rate = 16000;
1215
+ * config.feat_config.feature_dim = 80;
1216
+ * config.model_config.whisper.encoder =
1217
+ * "./sherpa-onnx-whisper-tiny/tiny-encoder.onnx";
1218
+ * config.model_config.whisper.decoder =
1219
+ * "./sherpa-onnx-whisper-tiny/tiny-decoder.onnx";
1220
+ * config.model_config.whisper.language = "en";
1221
+ * config.model_config.whisper.task = "transcribe";
1222
+ * config.model_config.tokens =
1223
+ * "./sherpa-onnx-whisper-tiny/tiny-tokens.txt";
1224
+ * config.model_config.provider = "cpu";
1225
+ * config.model_config.num_threads = 1;
1226
+ * config.decoding_method = "greedy_search";
1227
+ *
1228
+ * const SherpaOnnxOfflineRecognizer *recognizer =
1229
+ * SherpaOnnxCreateOfflineRecognizer(&config);
1230
+ * @endcode
1231
+ *
1232
+ * SenseVoice example:
1233
+ *
1234
+ * @code
1235
+ * config.model_config.sense_voice.model =
1236
+ * "./sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17-int8/model.int8.onnx";
1237
+ * config.model_config.sense_voice.language = "auto";
1238
+ * config.model_config.sense_voice.use_itn = 1;
1239
+ * config.model_config.tokens =
1240
+ * "./sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17-int8/tokens.txt";
1241
+ * @endcode
1242
+ *
1243
+ * Parakeet TDT example:
1244
+ *
1245
+ * @code
1246
+ * config.model_config.transducer.encoder =
1247
+ * "./sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8/encoder.int8.onnx";
1248
+ * config.model_config.transducer.decoder =
1249
+ * "./sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8/decoder.int8.onnx";
1250
+ * config.model_config.transducer.joiner =
1251
+ * "./sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8/joiner.int8.onnx";
1252
+ * config.model_config.tokens =
1253
+ * "./sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8/tokens.txt";
1254
+ * config.model_config.model_type = "nemo_transducer";
1255
+ * @endcode
1256
+ * @see SherpaOnnxOfflineRecognizerConfig, SherpaOnnxDestroyOfflineRecognizer
1257
+ */
1258
+ SHERPA_ONNX_API const SherpaOnnxOfflineRecognizer *
1259
+ SherpaOnnxCreateOfflineRecognizer(
1260
+ const SherpaOnnxOfflineRecognizerConfig *config);
1261
+
1262
+ /**
1263
+ * @brief Update the configuration of an existing offline recognizer.
1264
+ *
1265
+ * @param recognizer Recognizer handle.
1266
+ * @param config New recognizer configuration.
1267
+ *
1268
+ * @code
1269
+ * SherpaOnnxOfflineRecognizerSetConfig(recognizer, &config);
1270
+ * @endcode
1271
+ */
1272
+ SHERPA_ONNX_API void SherpaOnnxOfflineRecognizerSetConfig(
1273
+ const SherpaOnnxOfflineRecognizer *recognizer,
1274
+ const SherpaOnnxOfflineRecognizerConfig *config);
1275
+
1276
+ /**
1277
+ * @brief Destroy a non-streaming recognizer.
1278
+ *
1279
+ * @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer().
1280
+ *
1281
+ * @code
1282
+ * SherpaOnnxDestroyOfflineRecognizer(recognizer);
1283
+ * recognizer = NULL;
1284
+ * @endcode
1285
+ * @see SherpaOnnxCreateOfflineRecognizer
1286
+ */
1287
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineRecognizer(
1288
+ const SherpaOnnxOfflineRecognizer *recognizer);
1289
+
1290
+ /**
1291
+ * @brief Create a non-streaming ASR input stream.
1292
+ *
1293
+ * @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer().
1294
+ * @return A newly created stream. The caller owns the returned object and must
1295
+ * free it with SherpaOnnxDestroyOfflineStream().
1296
+ *
1297
+ * @code
1298
+ * const SherpaOnnxWave *wave =
1299
+ * SherpaOnnxReadWave("./sherpa-onnx-whisper-tiny.en/test_wavs/0.wav");
1300
+ * const SherpaOnnxOfflineStream *stream =
1301
+ * SherpaOnnxCreateOfflineStream(recognizer);
1302
+ * @endcode
1303
+ * @see SherpaOnnxDestroyOfflineStream, SherpaOnnxAcceptWaveformOffline
1304
+ */
1305
+ SHERPA_ONNX_API const SherpaOnnxOfflineStream *SherpaOnnxCreateOfflineStream(
1306
+ const SherpaOnnxOfflineRecognizer *recognizer);
1307
+
1308
+ /**
1309
+ * @brief Create a non-streaming ASR input stream with per-stream hotwords.
1310
+ *
1311
+ * @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer().
1312
+ * @param hotwords Hotwords text to associate with the stream.
1313
+ * @return A newly created stream. The caller owns the returned object and must
1314
+ * free it with SherpaOnnxDestroyOfflineStream().
1315
+ *
1316
+ * @code
1317
+ * const SherpaOnnxOfflineStream *stream =
1318
+ * SherpaOnnxCreateOfflineStreamWithHotwords(recognizer,
1319
+ * "▁HELLO ▁WORLD");
1320
+ * @endcode
1321
+ */
1322
+ SHERPA_ONNX_API const SherpaOnnxOfflineStream *
1323
+ SherpaOnnxCreateOfflineStreamWithHotwords(
1324
+ const SherpaOnnxOfflineRecognizer *recognizer, const char *hotwords);
1325
+
1326
+ /**
1327
+ * @brief Destroy a non-streaming ASR stream.
1328
+ *
1329
+ * @param stream A pointer returned by SherpaOnnxCreateOfflineStream() or
1330
+ * SherpaOnnxCreateOfflineStreamWithHotwords().
1331
+ *
1332
+ * @code
1333
+ * SherpaOnnxDestroyOfflineStream(stream);
1334
+ * stream = NULL;
1335
+ * @endcode
1336
+ * @see SherpaOnnxCreateOfflineStream
1337
+ */
1338
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineStream(
1339
+ const SherpaOnnxOfflineStream *stream);
1340
+
1341
+ /**
1342
+ * @brief Provide the full utterance to an offline ASR stream.
1343
+ *
1344
+ * The input is mono floating-point PCM normalized to the range [-1, 1].
1345
+ * If @p sample_rate differs from the recognizer feature sample rate,
1346
+ * sherpa-onnx resamples internally.
1347
+ *
1348
+ * @warning Call this function at most once for each offline stream. Offline
1349
+ * recognition expects the entire utterance in a single call.
1350
+ *
1351
+ * @param stream A pointer returned by SherpaOnnxCreateOfflineStream().
1352
+ * @param sample_rate Sample rate of @p samples.
1353
+ * @param samples Pointer to @p n samples in the range [-1, 1].
1354
+ * @param n Number of samples.
1355
+ *
1356
+ * @code
1357
+ * const SherpaOnnxWave *wave =
1358
+ * SherpaOnnxReadWave("./sherpa-onnx-whisper-tiny.en/test_wavs/0.wav");
1359
+ * const SherpaOnnxOfflineStream *stream =
1360
+ * SherpaOnnxCreateOfflineStream(recognizer);
1361
+ * SherpaOnnxAcceptWaveformOffline(stream, wave->sample_rate,
1362
+ * wave->samples, wave->num_samples);
1363
+ * SherpaOnnxDecodeOfflineStream(recognizer, stream);
1364
+ * @endcode
1365
+ * @see SherpaOnnxCreateOfflineStream, SherpaOnnxDecodeOfflineStream
1366
+ */
1367
+ SHERPA_ONNX_API void SherpaOnnxAcceptWaveformOffline(
1368
+ const SherpaOnnxOfflineStream *stream, int32_t sample_rate,
1369
+ const float *samples, int32_t n);
1370
+
1371
+ /**
1372
+ * @brief Set a per-stream runtime option for offline ASR.
1373
+ *
1374
+ * @param stream A pointer returned by SherpaOnnxCreateOfflineStream().
1375
+ * @param key Option name.
1376
+ * @param value Option value represented as text.
1377
+ *
1378
+ * @code
1379
+ * SherpaOnnxOfflineStreamSetOption(stream, "language", "en");
1380
+ * @endcode
1381
+ */
1382
+ SHERPA_ONNX_API void SherpaOnnxOfflineStreamSetOption(
1383
+ const SherpaOnnxOfflineStream *stream, const char *key, const char *value);
1384
+
1385
+ /**
1386
+ * @brief Get a per-stream runtime option for offline ASR.
1387
+ *
1388
+ * @param stream A pointer returned by SherpaOnnxCreateOfflineStream().
1389
+ * @param key Option name.
1390
+ * @return The option value. The returned pointer is owned by the stream, must
1391
+ * not be freed by the caller, and may be invalidated if the option is
1392
+ * overwritten or the stream is destroyed.
1393
+ *
1394
+ * @code
1395
+ * const char *value = SherpaOnnxOfflineStreamGetOption(stream, "language");
1396
+ * @endcode
1397
+ */
1398
+ SHERPA_ONNX_API const char *SherpaOnnxOfflineStreamGetOption(
1399
+ const SherpaOnnxOfflineStream *stream, const char *key);
1400
+
1401
+ /**
1402
+ * @brief Check whether a per-stream runtime option exists.
1403
+ *
1404
+ * @param stream A pointer returned by SherpaOnnxCreateOfflineStream().
1405
+ * @param key Option name.
1406
+ * @return 1 if the option exists; otherwise 0.
1407
+ *
1408
+ * @code
1409
+ * int32_t has_language =
1410
+ * SherpaOnnxOfflineStreamHasOption(stream, "language");
1411
+ * @endcode
1412
+ */
1413
+ SHERPA_ONNX_API int32_t SherpaOnnxOfflineStreamHasOption(
1414
+ const SherpaOnnxOfflineStream *stream, const char *key);
1415
+
1416
+ /**
1417
+ * @brief Run offline ASR on one stream.
1418
+ *
1419
+ * Call this after SherpaOnnxAcceptWaveformOffline().
1420
+ *
1421
+ * @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer().
1422
+ * @param stream A pointer returned by SherpaOnnxCreateOfflineStream().
1423
+ *
1424
+ * @code
1425
+ * SherpaOnnxDecodeOfflineStream(recognizer, stream);
1426
+ * @endcode
1427
+ * @see SherpaOnnxAcceptWaveformOffline, SherpaOnnxGetOfflineStreamResult
1428
+ */
1429
+ SHERPA_ONNX_API void SherpaOnnxDecodeOfflineStream(
1430
+ const SherpaOnnxOfflineRecognizer *recognizer,
1431
+ const SherpaOnnxOfflineStream *stream);
1432
+
1433
+ /**
1434
+ * @brief Run offline ASR on multiple streams in parallel.
1435
+ *
1436
+ * The caller must have already provided one utterance to each stream via
1437
+ * SherpaOnnxAcceptWaveformOffline().
1438
+ *
1439
+ * @param recognizer A pointer returned by SherpaOnnxCreateOfflineRecognizer().
1440
+ * @param streams Array of @p n offline stream pointers.
1441
+ * @param n Number of streams in @p streams.
1442
+ *
1443
+ * @code
1444
+ * const SherpaOnnxOfflineStream *streams[2] = {stream1, stream2};
1445
+ * SherpaOnnxDecodeMultipleOfflineStreams(recognizer, streams, 2);
1446
+ * @endcode
1447
+ */
1448
+ SHERPA_ONNX_API void SherpaOnnxDecodeMultipleOfflineStreams(
1449
+ const SherpaOnnxOfflineRecognizer *recognizer,
1450
+ const SherpaOnnxOfflineStream **streams, int32_t n);
1451
+
1452
+ /**
1453
+ * @brief Recognition result for a non-streaming ASR stream.
1454
+ *
1455
+ * All pointers in this struct are owned by the result object returned from
1456
+ * SherpaOnnxGetOfflineStreamResult() and become invalid after
1457
+ * SherpaOnnxDestroyOfflineRecognizerResult() is called.
1458
+ * @see SherpaOnnxGetOfflineStreamResult, SherpaOnnxDestroyOfflineRecognizerResult
1459
+ */
1460
+ typedef struct SherpaOnnxOfflineRecognizerResult {
1461
+ /** Recognized text. */
1462
+ const char *text;
1463
+
1464
+ /**
1465
+ * Optional token timestamps in seconds.
1466
+ *
1467
+ * This field may be NULL when the model does not provide token timestamps.
1468
+ * When non-NULL, it contains @c count entries and is parallel to
1469
+ * @c tokens_arr.
1470
+ */
1471
+ float *timestamps;
1472
+
1473
+ /** Number of token entries in @c tokens_arr and related per-token arrays. */
1474
+ int32_t count;
1475
+
1476
+ /**
1477
+ * Contiguous memory block containing token strings separated by '\0'.
1478
+ *
1479
+ * Use @c tokens_arr for convenient indexed access.
1480
+ */
1481
+ const char *tokens;
1482
+
1483
+ /** Array of @c count pointers into @c tokens. */
1484
+ const char *const *tokens_arr;
1485
+
1486
+ /** JSON serialization of the result. */
1487
+ const char *json;
1488
+
1489
+ /** Optional recognized language label. */
1490
+ const char *lang;
1491
+
1492
+ /** Optional recognized emotion label. */
1493
+ const char *emotion;
1494
+
1495
+ /** Optional recognized event label. */
1496
+ const char *event;
1497
+
1498
+ /** Optional token durations in seconds, parallel to @c tokens_arr. */
1499
+ float *durations;
1500
+
1501
+ /** Optional token log probabilities, parallel to @c tokens_arr. */
1502
+ float *ys_log_probs;
1503
+
1504
+ /** Optional segment start times in seconds, parallel to @c segment_texts_arr.
1505
+ */
1506
+ const float *segment_timestamps;
1507
+
1508
+ /** Optional segment durations in seconds, parallel to @c segment_texts_arr.
1509
+ */
1510
+ const float *segment_durations;
1511
+
1512
+ /** Contiguous memory block containing segment texts separated by '\0'. */
1513
+ const char *segment_texts;
1514
+
1515
+ /** Array of @c segment_count pointers into @c segment_texts. */
1516
+ const char *const *segment_texts_arr;
1517
+
1518
+ /** Number of segment entries in the segment-level arrays. */
1519
+ int32_t segment_count;
1520
+ } SherpaOnnxOfflineRecognizerResult;
1521
+
1522
+ /**
1523
+ * @brief Get the recognition result for an offline ASR stream.
1524
+ *
1525
+ * Call this after SherpaOnnxDecodeOfflineStream() or
1526
+ * SherpaOnnxDecodeMultipleOfflineStreams().
1527
+ *
1528
+ * @param stream A pointer returned by SherpaOnnxCreateOfflineStream().
1529
+ * @return A newly allocated result snapshot. Free it with
1530
+ * SherpaOnnxDestroyOfflineRecognizerResult().
1531
+ *
1532
+ * @code
1533
+ * const SherpaOnnxOfflineRecognizerResult *r =
1534
+ * SherpaOnnxGetOfflineStreamResult(stream);
1535
+ * printf("%s\n", r->text);
1536
+ * if (r->timestamps) {
1537
+ * printf("First token starts at %.3f seconds\n", r->timestamps[0]);
1538
+ * }
1539
+ * SherpaOnnxDestroyOfflineRecognizerResult(r);
1540
+ * @endcode
1541
+ * @see SherpaOnnxDestroyOfflineRecognizerResult, SherpaOnnxDecodeOfflineStream
1542
+ */
1543
+ SHERPA_ONNX_API const SherpaOnnxOfflineRecognizerResult *
1544
+ SherpaOnnxGetOfflineStreamResult(const SherpaOnnxOfflineStream *stream);
1545
+
1546
+ /**
1547
+ * @brief Destroy a result returned by SherpaOnnxGetOfflineStreamResult().
1548
+ *
1549
+ * @param r A pointer returned by SherpaOnnxGetOfflineStreamResult().
1550
+ *
1551
+ * @code
1552
+ * SherpaOnnxDestroyOfflineRecognizerResult(r);
1553
+ * r = NULL;
1554
+ * @endcode
1555
+ * @see SherpaOnnxGetOfflineStreamResult
1556
+ */
1557
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineRecognizerResult(
1558
+ const SherpaOnnxOfflineRecognizerResult *r);
1559
+
1560
+ /**
1561
+ * @brief Get the offline ASR result as JSON.
1562
+ *
1563
+ * @param stream A pointer returned by SherpaOnnxCreateOfflineStream().
1564
+ * @return A newly allocated JSON string. Free it with
1565
+ * SherpaOnnxDestroyOfflineStreamResultJson().
1566
+ *
1567
+ * @code
1568
+ * const char *json = SherpaOnnxGetOfflineStreamResultAsJson(stream);
1569
+ * puts(json);
1570
+ * SherpaOnnxDestroyOfflineStreamResultJson(json);
1571
+ * @endcode
1572
+ */
1573
+ SHERPA_ONNX_API const char *SherpaOnnxGetOfflineStreamResultAsJson(
1574
+ const SherpaOnnxOfflineStream *stream);
1575
+
1576
+ /**
1577
+ * @brief Free a JSON string returned by
1578
+ * SherpaOnnxGetOfflineStreamResultAsJson().
1579
+ *
1580
+ * @param s A pointer returned by SherpaOnnxGetOfflineStreamResultAsJson().
1581
+ *
1582
+ * @code
1583
+ * SherpaOnnxDestroyOfflineStreamResultJson(json);
1584
+ * json = NULL;
1585
+ * @endcode
1586
+ */
1587
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineStreamResultJson(const char *s);
1588
+
1589
+ // ============================================================
1590
+ // For keyword spotting
1591
+ // ============================================================
1592
+ /**
1593
+ * @brief Snapshot of the current keyword spotting result.
1594
+ *
1595
+ * Free this object with SherpaOnnxDestroyKeywordResult().
1596
+ * @see SherpaOnnxGetKeywordResult
1597
+ */
1598
+ typedef struct SherpaOnnxKeywordResult {
1599
+ /**
1600
+ * Triggered keyword text.
1601
+ *
1602
+ * For English models this is usually space-separated words. For Chinese
1603
+ * models it is typically the surface form without spaces.
1604
+ */
1605
+ const char *keyword;
1606
+
1607
+ /**
1608
+ * Token sequence as a single string.
1609
+ *
1610
+ * For BPE-based models this contains the decoded BPE tokens.
1611
+ */
1612
+ const char *tokens;
1613
+
1614
+ /**
1615
+ * Token sequence as an array.
1616
+ *
1617
+ * The array length is @c count. Each string is owned by this result object.
1618
+ */
1619
+ const char *const *tokens_arr;
1620
+
1621
+ /** Number of decoded tokens in @c tokens_arr and @c timestamps. */
1622
+ int32_t count;
1623
+
1624
+ /**
1625
+ * Per-token timestamps in seconds.
1626
+ *
1627
+ * This array has @c count elements. Element @c i corresponds to
1628
+ * `tokens_arr[i]`.
1629
+ */
1630
+ float *timestamps;
1631
+
1632
+ /** Start time of the current segment in seconds. */
1633
+ float start_time;
1634
+
1635
+ /**
1636
+ * JSON representation of the result.
1637
+ *
1638
+ * The JSON includes `keyword`, `tokens`, `timestamps`, and `start_time`.
1639
+ */
1640
+ const char *json;
1641
+ } SherpaOnnxKeywordResult;
1642
+
1643
+ /**
1644
+ * @brief Configuration for keyword spotting.
1645
+ *
1646
+ * The acoustic model is configured through @c model_config. In practice this is
1647
+ * usually a streaming transducer model.
1648
+ *
1649
+ * Keyword definitions can be provided either through @c keywords_file or
1650
+ * through @c keywords_buf/@c keywords_buf_size. If both are set, the buffer is
1651
+ * used.
1652
+ *
1653
+ * Example using
1654
+ * `sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01-mobile`:
1655
+ *
1656
+ * @code
1657
+ * SherpaOnnxKeywordSpotterConfig config;
1658
+ * memset(&config, 0, sizeof(config));
1659
+ *
1660
+ * config.model_config.transducer.encoder =
1661
+ * "./sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01-mobile/"
1662
+ * "encoder-epoch-12-avg-2-chunk-16-left-64.int8.onnx";
1663
+ * config.model_config.transducer.decoder =
1664
+ * "./sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01-mobile/"
1665
+ * "decoder-epoch-12-avg-2-chunk-16-left-64.onnx";
1666
+ * config.model_config.transducer.joiner =
1667
+ * "./sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01-mobile/"
1668
+ * "joiner-epoch-12-avg-2-chunk-16-left-64.int8.onnx";
1669
+ * config.model_config.tokens =
1670
+ * "./sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01-mobile/"
1671
+ * "tokens.txt";
1672
+ * config.model_config.provider = "cpu";
1673
+ * config.model_config.num_threads = 1;
1674
+ *
1675
+ * config.keywords_file =
1676
+ * "./sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01-mobile/"
1677
+ * "test_wavs/test_keywords.txt";
1678
+ * config.max_active_paths = 4;
1679
+ * config.keywords_score = 3.0f;
1680
+ * config.keywords_threshold = 0.1f;
1681
+ * @endcode
1682
+ * @see SherpaOnnxCreateKeywordSpotter
1683
+ */
1684
+ typedef struct SherpaOnnxKeywordSpotterConfig {
1685
+ /** Feature extraction parameters. */
1686
+ SherpaOnnxFeatureConfig feat_config;
1687
+ /** Streaming acoustic model configuration. */
1688
+ SherpaOnnxOnlineModelConfig model_config;
1689
+ /** Maximum number of active decoding paths. */
1690
+ int32_t max_active_paths;
1691
+ /** Number of trailing blank symbols required before trigger finalization. */
1692
+ int32_t num_trailing_blanks;
1693
+ /** Bonus score applied to keywords during search. */
1694
+ float keywords_score;
1695
+ /** Detection threshold. Larger values are more conservative. */
1696
+ float keywords_threshold;
1697
+ /** Optional keyword file. */
1698
+ const char *keywords_file;
1699
+ /** Optional in-memory keyword data. If non-null, it overrides @c
1700
+ * keywords_file. */
1701
+ const char *keywords_buf;
1702
+ /** Size in bytes of @c keywords_buf, excluding any trailing `'\0'`. */
1703
+ int32_t keywords_buf_size;
1704
+ } SherpaOnnxKeywordSpotterConfig;
1705
+
1706
+ /** @brief Opaque keyword spotter handle. */
1707
+ typedef struct SherpaOnnxKeywordSpotter SherpaOnnxKeywordSpotter;
1708
+
1709
+ /**
1710
+ * @brief Create a keyword spotter.
1711
+ *
1712
+ * @param config Keyword spotter configuration.
1713
+ * @return A newly allocated keyword spotter on success, or NULL on error. Free
1714
+ * it with SherpaOnnxDestroyKeywordSpotter().
1715
+ * @see SherpaOnnxKeywordSpotterConfig, SherpaOnnxDestroyKeywordSpotter
1716
+ */
1717
+ SHERPA_ONNX_API const SherpaOnnxKeywordSpotter *SherpaOnnxCreateKeywordSpotter(
1718
+ const SherpaOnnxKeywordSpotterConfig *config);
1719
+
1720
+ /**
1721
+ * @brief Destroy a keyword spotter.
1722
+ *
1723
+ * @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
1724
+ * @see SherpaOnnxCreateKeywordSpotter
1725
+ */
1726
+ SHERPA_ONNX_API void SherpaOnnxDestroyKeywordSpotter(
1727
+ const SherpaOnnxKeywordSpotter *spotter);
1728
+
1729
+ /**
1730
+ * @brief Create a keyword spotting stream using the spotter's built-in keyword
1731
+ * list.
1732
+ *
1733
+ * @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
1734
+ * @return A newly allocated stream. Free it with
1735
+ * SherpaOnnxDestroyOnlineStream().
1736
+ */
1737
+ SHERPA_ONNX_API const SherpaOnnxOnlineStream *SherpaOnnxCreateKeywordStream(
1738
+ const SherpaOnnxKeywordSpotter *spotter);
1739
+
1740
+ /**
1741
+ * @brief Create a keyword spotting stream with extra or replacement keywords.
1742
+ *
1743
+ * The @p keywords string uses the same textual format as the keyword files used
1744
+ * by the examples. For instance:
1745
+ *
1746
+ * @code
1747
+ * const SherpaOnnxOnlineStream *stream =
1748
+ * SherpaOnnxCreateKeywordStreamWithKeywords(
1749
+ * kws, "y ǎn y uán @演员/zh ī m íng @知名");
1750
+ * @endcode
1751
+ *
1752
+ * @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
1753
+ * @param keywords Inline keyword definition string.
1754
+ * @return A newly allocated stream. Free it with
1755
+ * SherpaOnnxDestroyOnlineStream().
1756
+ */
1757
+ SHERPA_ONNX_API const SherpaOnnxOnlineStream *
1758
+ SherpaOnnxCreateKeywordStreamWithKeywords(
1759
+ const SherpaOnnxKeywordSpotter *spotter, const char *keywords);
1760
+
1761
+ /**
1762
+ * @brief Check whether a keyword stream has enough audio for decoding.
1763
+ *
1764
+ * @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
1765
+ * @param stream A pointer returned by SherpaOnnxCreateKeywordStream() or
1766
+ * SherpaOnnxCreateKeywordStreamWithKeywords().
1767
+ * @return 1 if the stream is ready to decode; otherwise 0.
1768
+ */
1769
+ SHERPA_ONNX_API int32_t
1770
+ SherpaOnnxIsKeywordStreamReady(const SherpaOnnxKeywordSpotter *spotter,
1771
+ const SherpaOnnxOnlineStream *stream);
1772
+
1773
+ /**
1774
+ * @brief Decode one ready keyword stream.
1775
+ *
1776
+ * Call this only when SherpaOnnxIsKeywordStreamReady() returns 1.
1777
+ *
1778
+ * @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
1779
+ * @param stream A pointer returned by SherpaOnnxCreateKeywordStream() or
1780
+ * SherpaOnnxCreateKeywordStreamWithKeywords().
1781
+ */
1782
+ SHERPA_ONNX_API void SherpaOnnxDecodeKeywordStream(
1783
+ const SherpaOnnxKeywordSpotter *spotter,
1784
+ const SherpaOnnxOnlineStream *stream);
1785
+
1786
+ /**
1787
+ * @brief Reset a keyword stream after a keyword is detected.
1788
+ *
1789
+ * The examples call this immediately after a successful trigger so the next
1790
+ * keyword can be detected independently.
1791
+ *
1792
+ * @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
1793
+ * @param stream A pointer returned by SherpaOnnxCreateKeywordStream() or
1794
+ * SherpaOnnxCreateKeywordStreamWithKeywords().
1795
+ */
1796
+ SHERPA_ONNX_API void SherpaOnnxResetKeywordStream(
1797
+ const SherpaOnnxKeywordSpotter *spotter,
1798
+ const SherpaOnnxOnlineStream *stream);
1799
+
1800
+ /**
1801
+ * @brief Decode multiple ready keyword streams in parallel.
1802
+ *
1803
+ * The caller must ensure every stream in @p streams is ready before calling
1804
+ * this function.
1805
+ *
1806
+ * @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
1807
+ * @param streams Array of ready streams.
1808
+ * @param n Number of elements in @p streams.
1809
+ */
1810
+ SHERPA_ONNX_API void SherpaOnnxDecodeMultipleKeywordStreams(
1811
+ const SherpaOnnxKeywordSpotter *spotter,
1812
+ const SherpaOnnxOnlineStream **streams, int32_t n);
1813
+
1814
+ /**
1815
+ * @brief Get the current keyword spotting result for a stream.
1816
+ *
1817
+ * The returned snapshot may represent either "no trigger yet" or a detected
1818
+ * keyword. A common pattern is to check whether `strlen(r->keyword) != 0`.
1819
+ *
1820
+ * @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
1821
+ * @param stream A pointer returned by SherpaOnnxCreateKeywordStream() or
1822
+ * SherpaOnnxCreateKeywordStreamWithKeywords().
1823
+ * @return A newly allocated result snapshot. Free it with
1824
+ * SherpaOnnxDestroyKeywordResult().
1825
+ *
1826
+ * @code
1827
+ * const SherpaOnnxKeywordResult *r = SherpaOnnxGetKeywordResult(kws, stream);
1828
+ * if (r && r->json && strlen(r->keyword)) {
1829
+ * fprintf(stderr, "Detected keyword: %s\n", r->json);
1830
+ * SherpaOnnxResetKeywordStream(kws, stream);
1831
+ * }
1832
+ * SherpaOnnxDestroyKeywordResult(r);
1833
+ * @endcode
1834
+ * @see SherpaOnnxDestroyKeywordResult
1835
+ */
1836
+ SHERPA_ONNX_API const SherpaOnnxKeywordResult *SherpaOnnxGetKeywordResult(
1837
+ const SherpaOnnxKeywordSpotter *spotter,
1838
+ const SherpaOnnxOnlineStream *stream);
1839
+
1840
+ /**
1841
+ * @brief Destroy a keyword result snapshot.
1842
+ *
1843
+ * @param r A pointer returned by SherpaOnnxGetKeywordResult().
1844
+ * @see SherpaOnnxGetKeywordResult
1845
+ */
1846
+ SHERPA_ONNX_API void SherpaOnnxDestroyKeywordResult(
1847
+ const SherpaOnnxKeywordResult *r);
1848
+
1849
+ /**
1850
+ * @brief Get the current keyword spotting result as JSON.
1851
+ *
1852
+ * @param spotter A pointer returned by SherpaOnnxCreateKeywordSpotter().
1853
+ * @param stream A pointer returned by SherpaOnnxCreateKeywordStream() or
1854
+ * SherpaOnnxCreateKeywordStreamWithKeywords().
1855
+ * @return A newly allocated JSON string. Free it with
1856
+ * SherpaOnnxFreeKeywordResultJson().
1857
+ */
1858
+ SHERPA_ONNX_API const char *SherpaOnnxGetKeywordResultAsJson(
1859
+ const SherpaOnnxKeywordSpotter *spotter,
1860
+ const SherpaOnnxOnlineStream *stream);
1861
+
1862
+ /**
1863
+ * @brief Free a JSON string returned by SherpaOnnxGetKeywordResultAsJson().
1864
+ *
1865
+ * @param s A pointer returned by SherpaOnnxGetKeywordResultAsJson().
1866
+ */
1867
+ SHERPA_ONNX_API void SherpaOnnxFreeKeywordResultJson(const char *s);
1868
+
1869
+ // ============================================================
1870
+ // For VAD
1871
+ // ============================================================
1872
+
1873
+ /** @brief Configuration for a Silero VAD model. */
1874
+ typedef struct SherpaOnnxSileroVadModelConfig {
1875
+ /** Path to `silero_vad.onnx`. */
1876
+ const char *model;
1877
+ /** Speech probability threshold. Frames above this value are speech. */
1878
+ float threshold;
1879
+ /** Minimum silence duration in seconds used to close a speech segment. */
1880
+ float min_silence_duration;
1881
+ /** Minimum speech duration in seconds to keep a detected segment. */
1882
+ float min_speech_duration;
1883
+ /** Input window size in samples. A common value is 512. */
1884
+ int32_t window_size;
1885
+ /**
1886
+ * Maximum speech duration in seconds.
1887
+ *
1888
+ * When a segment exceeds this value, the detector temporarily uses a higher
1889
+ * threshold to encourage a split.
1890
+ */
1891
+ float max_speech_duration;
1892
+ } SherpaOnnxSileroVadModelConfig;
1893
+
1894
+ /** @brief Configuration for a Ten VAD model. */
1895
+ typedef struct SherpaOnnxTenVadModelConfig {
1896
+ /** Path to `ten-vad.onnx`. */
1897
+ const char *model;
1898
+ /** Speech probability threshold. Frames above this value are speech. */
1899
+ float threshold;
1900
+ /** Minimum silence duration in seconds used to close a speech segment. */
1901
+ float min_silence_duration;
1902
+ /** Minimum speech duration in seconds to keep a detected segment. */
1903
+ float min_speech_duration;
1904
+ /** Input window size in samples. A common value is 256. */
1905
+ int32_t window_size;
1906
+ /**
1907
+ * Maximum speech duration in seconds.
1908
+ *
1909
+ * When a segment exceeds this value, the detector temporarily uses a higher
1910
+ * threshold to encourage a split.
1911
+ */
1912
+ float max_speech_duration;
1913
+ } SherpaOnnxTenVadModelConfig;
1914
+
1915
+ /**
1916
+ * @brief Configuration shared by voice activity detectors.
1917
+ *
1918
+ * Exactly one VAD model family should be configured. Set either
1919
+ * @c silero_vad.model or @c ten_vad.model.
1920
+ *
1921
+ * If both are configured, the implementation will choose one of them, and
1922
+ * which one is used is implementation-defined. Do not rely on any precedence
1923
+ * rule.
1924
+ *
1925
+ * Example model files:
1926
+ * - `./silero_vad.onnx`
1927
+ * - `./ten-vad.onnx`
1928
+ *
1929
+ * @code
1930
+ * SherpaOnnxVadModelConfig config;
1931
+ * memset(&config, 0, sizeof(config));
1932
+ *
1933
+ * config.silero_vad.model = "./silero_vad.onnx";
1934
+ * config.silero_vad.threshold = 0.25f;
1935
+ * config.silero_vad.min_silence_duration = 0.5f;
1936
+ * config.silero_vad.min_speech_duration = 0.5f;
1937
+ * config.silero_vad.max_speech_duration = 10.0f;
1938
+ * config.silero_vad.window_size = 512;
1939
+ *
1940
+ * config.sample_rate = 16000;
1941
+ * config.num_threads = 1;
1942
+ * config.provider = "cpu";
1943
+ * config.debug = 0;
1944
+ * @endcode
1945
+ * @see SherpaOnnxCreateVoiceActivityDetector
1946
+ */
1947
+ typedef struct SherpaOnnxVadModelConfig {
1948
+ /** Silero VAD configuration. */
1949
+ SherpaOnnxSileroVadModelConfig silero_vad;
1950
+ /** Input sample rate expected by the detector, usually 16000. */
1951
+ int32_t sample_rate;
1952
+ /** Number of backend threads. */
1953
+ int32_t num_threads;
1954
+ /** Execution provider, for example "cpu" or "cuda". */
1955
+ const char *provider;
1956
+ /** Non-zero to print debug information. */
1957
+ int32_t debug;
1958
+ /** Ten VAD configuration. */
1959
+ SherpaOnnxTenVadModelConfig ten_vad;
1960
+ } SherpaOnnxVadModelConfig;
1961
+
1962
+ /** @brief Opaque circular-buffer handle used by helper APIs. */
1963
+ typedef struct SherpaOnnxCircularBuffer SherpaOnnxCircularBuffer;
1964
+
1965
+ /**
1966
+ * @brief Create a floating-point circular buffer.
1967
+ *
1968
+ * @param capacity Maximum number of samples the buffer can keep.
1969
+ * @return A newly allocated buffer. Free it with
1970
+ * SherpaOnnxDestroyCircularBuffer().
1971
+ *
1972
+ * @code
1973
+ * const SherpaOnnxCircularBuffer *buffer =
1974
+ * SherpaOnnxCreateCircularBuffer(16000 * 30);
1975
+ * @endcode
1976
+ */
1977
+ SHERPA_ONNX_API const SherpaOnnxCircularBuffer *SherpaOnnxCreateCircularBuffer(
1978
+ int32_t capacity);
1979
+
1980
+ /**
1981
+ * @brief Destroy a circular buffer.
1982
+ *
1983
+ * @param buffer A pointer returned by SherpaOnnxCreateCircularBuffer().
1984
+ *
1985
+ * @code
1986
+ * SherpaOnnxDestroyCircularBuffer(buffer);
1987
+ * buffer = NULL;
1988
+ * @endcode
1989
+ */
1990
+ SHERPA_ONNX_API void SherpaOnnxDestroyCircularBuffer(
1991
+ const SherpaOnnxCircularBuffer *buffer);
1992
+
1993
+ /**
1994
+ * @brief Append samples to a circular buffer.
1995
+ *
1996
+ * @param buffer A pointer returned by SherpaOnnxCreateCircularBuffer().
1997
+ * @param p Pointer to @p n samples.
1998
+ * @param n Number of samples.
1999
+ *
2000
+ * @code
2001
+ * SherpaOnnxCircularBufferPush(buffer, wave->samples, wave->num_samples);
2002
+ * @endcode
2003
+ */
2004
+ SHERPA_ONNX_API void SherpaOnnxCircularBufferPush(
2005
+ const SherpaOnnxCircularBuffer *buffer, const float *p, int32_t n);
2006
+
2007
+ /**
2008
+ * @brief Copy out a slice of samples from a circular buffer.
2009
+ *
2010
+ * @param buffer A pointer returned by SherpaOnnxCreateCircularBuffer().
2011
+ * @param start_index Absolute start index in the buffer timeline.
2012
+ * @param n Number of samples to copy.
2013
+ * @return A newly allocated array containing @p n samples. Free it with
2014
+ * SherpaOnnxCircularBufferFree().
2015
+ *
2016
+ * @code
2017
+ * const float *samples = SherpaOnnxCircularBufferGet(buffer, start, 3200);
2018
+ * SherpaOnnxCircularBufferFree(samples);
2019
+ * @endcode
2020
+ */
2021
+ SHERPA_ONNX_API const float *SherpaOnnxCircularBufferGet(
2022
+ const SherpaOnnxCircularBuffer *buffer, int32_t start_index, int32_t n);
2023
+
2024
+ /** @brief Free an array returned by SherpaOnnxCircularBufferGet(). */
2025
+ SHERPA_ONNX_API void SherpaOnnxCircularBufferFree(const float *p);
2026
+
2027
+ /**
2028
+ * @brief Drop samples from the front of a circular buffer.
2029
+ *
2030
+ * @param buffer A pointer returned by SherpaOnnxCreateCircularBuffer().
2031
+ * @param n Number of samples to remove.
2032
+ */
2033
+ SHERPA_ONNX_API void SherpaOnnxCircularBufferPop(
2034
+ const SherpaOnnxCircularBuffer *buffer, int32_t n);
2035
+
2036
+ /**
2037
+ * @brief Return the number of currently stored samples.
2038
+ *
2039
+ * @param buffer A pointer returned by SherpaOnnxCreateCircularBuffer().
2040
+ * @return Number of samples currently in the buffer.
2041
+ */
2042
+ SHERPA_ONNX_API int32_t
2043
+ SherpaOnnxCircularBufferSize(const SherpaOnnxCircularBuffer *buffer);
2044
+
2045
+ /**
2046
+ * @brief Return the current head index of the buffer timeline.
2047
+ *
2048
+ * The value is monotonically non-decreasing until
2049
+ * SherpaOnnxCircularBufferReset() is called.
2050
+ *
2051
+ * @param buffer A pointer returned by SherpaOnnxCreateCircularBuffer().
2052
+ * @return The current head index.
2053
+ */
2054
+ SHERPA_ONNX_API int32_t
2055
+ SherpaOnnxCircularBufferHead(const SherpaOnnxCircularBuffer *buffer);
2056
+
2057
+ /**
2058
+ * @brief Clear a circular buffer and reset its head index.
2059
+ *
2060
+ * @param buffer A pointer returned by SherpaOnnxCreateCircularBuffer().
2061
+ */
2062
+ SHERPA_ONNX_API void SherpaOnnxCircularBufferReset(
2063
+ const SherpaOnnxCircularBuffer *buffer);
2064
+
2065
+ /**
2066
+ * @brief One detected speech segment returned by the VAD.
2067
+ *
2068
+ * The segment owns @c samples. Free the whole object with
2069
+ * SherpaOnnxDestroySpeechSegment().
2070
+ * @see SherpaOnnxVoiceActivityDetectorFront, SherpaOnnxDestroySpeechSegment
2071
+ */
2072
+ typedef struct SherpaOnnxSpeechSegment {
2073
+ /** Start index, in input samples, of this segment. */
2074
+ int32_t start;
2075
+ /** Newly allocated mono samples for this segment. */
2076
+ float *samples;
2077
+ /** Number of samples in @c samples. */
2078
+ int32_t n;
2079
+ } SherpaOnnxSpeechSegment;
2080
+
2081
+ /** @brief Opaque voice activity detector handle. */
2082
+ typedef struct SherpaOnnxVoiceActivityDetector SherpaOnnxVoiceActivityDetector;
2083
+
2084
+ /**
2085
+ * @brief Create a voice activity detector.
2086
+ *
2087
+ * Example model files are shown in `c-api-examples/vad-whisper-c-api.c`.
2088
+ *
2089
+ * @param config VAD configuration.
2090
+ * @param buffer_size_in_seconds Internal buffering capacity in seconds.
2091
+ * @return A newly allocated detector on success, or NULL on configuration
2092
+ * error. Free it with SherpaOnnxDestroyVoiceActivityDetector().
2093
+ *
2094
+ * @code
2095
+ * SherpaOnnxVadModelConfig config;
2096
+ * memset(&config, 0, sizeof(config));
2097
+ * config.silero_vad.model = "./silero_vad.onnx";
2098
+ * config.silero_vad.threshold = 0.25f;
2099
+ * config.silero_vad.min_silence_duration = 0.5f;
2100
+ * config.silero_vad.min_speech_duration = 0.5f;
2101
+ * config.silero_vad.max_speech_duration = 10.0f;
2102
+ * config.silero_vad.window_size = 512;
2103
+ * config.sample_rate = 16000;
2104
+ * config.num_threads = 1;
2105
+ *
2106
+ * const SherpaOnnxVoiceActivityDetector *vad =
2107
+ * SherpaOnnxCreateVoiceActivityDetector(&config, 30.0f);
2108
+ * @endcode
2109
+ * @see SherpaOnnxVadModelConfig, SherpaOnnxDestroyVoiceActivityDetector
2110
+ */
2111
+ SHERPA_ONNX_API const SherpaOnnxVoiceActivityDetector *
2112
+ SherpaOnnxCreateVoiceActivityDetector(const SherpaOnnxVadModelConfig *config,
2113
+ float buffer_size_in_seconds);
2114
+
2115
+ /**
2116
+ * @brief Destroy a voice activity detector.
2117
+ *
2118
+ * @param p A pointer returned by SherpaOnnxCreateVoiceActivityDetector().
2119
+ * @see SherpaOnnxCreateVoiceActivityDetector
2120
+ */
2121
+ SHERPA_ONNX_API void SherpaOnnxDestroyVoiceActivityDetector(
2122
+ const SherpaOnnxVoiceActivityDetector *p);
2123
+
2124
+ /**
2125
+ * @brief Feed audio samples to the VAD.
2126
+ *
2127
+ * Input samples are mono floating-point PCM in the range [-1, 1].
2128
+ *
2129
+ * @param p A pointer returned by SherpaOnnxCreateVoiceActivityDetector().
2130
+ * @param samples Pointer to @p n samples.
2131
+ * @param n Number of samples.
2132
+ *
2133
+ * @code
2134
+ * SherpaOnnxVoiceActivityDetectorAcceptWaveform(vad,
2135
+ * wave->samples + i,
2136
+ * window_size);
2137
+ * @endcode
2138
+ */
2139
+ SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorAcceptWaveform(
2140
+ const SherpaOnnxVoiceActivityDetector *p, const float *samples, int32_t n);
2141
+
2142
+ /**
2143
+ * @brief Check whether the detector currently has any completed speech segment.
2144
+ *
2145
+ * @param p A pointer returned by SherpaOnnxCreateVoiceActivityDetector().
2146
+ * @return 1 if no completed speech segment is available; otherwise 0.
2147
+ */
2148
+ SHERPA_ONNX_API int32_t
2149
+ SherpaOnnxVoiceActivityDetectorEmpty(const SherpaOnnxVoiceActivityDetector *p);
2150
+
2151
+ /**
2152
+ * @brief Check whether the detector is currently inside speech.
2153
+ *
2154
+ * @param p A pointer returned by SherpaOnnxCreateVoiceActivityDetector().
2155
+ * @return 1 if speech is currently detected; otherwise 0.
2156
+ */
2157
+ SHERPA_ONNX_API int32_t SherpaOnnxVoiceActivityDetectorDetected(
2158
+ const SherpaOnnxVoiceActivityDetector *p);
2159
+
2160
+ /**
2161
+ * @brief Remove the front speech segment from the detector queue.
2162
+ *
2163
+ * Call this after consuming the segment returned by
2164
+ * SherpaOnnxVoiceActivityDetectorFront().
2165
+ *
2166
+ * @param p A pointer returned by SherpaOnnxCreateVoiceActivityDetector().
2167
+ *
2168
+ * @code
2169
+ * const SherpaOnnxSpeechSegment *segment =
2170
+ * SherpaOnnxVoiceActivityDetectorFront(vad);
2171
+ * // ... use segment ...
2172
+ * SherpaOnnxDestroySpeechSegment(segment);
2173
+ * SherpaOnnxVoiceActivityDetectorPop(vad);
2174
+ * @endcode
2175
+ */
2176
+ SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorPop(
2177
+ const SherpaOnnxVoiceActivityDetector *p);
2178
+
2179
+ /**
2180
+ * @brief Remove all queued speech segments.
2181
+ *
2182
+ * @param p A pointer returned by SherpaOnnxCreateVoiceActivityDetector().
2183
+ */
2184
+ SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorClear(
2185
+ const SherpaOnnxVoiceActivityDetector *p);
2186
+
2187
+ /**
2188
+ * @brief Get the first queued speech segment.
2189
+ *
2190
+ * The returned segment is a copy owned by the caller. Free it with
2191
+ * SherpaOnnxDestroySpeechSegment().
2192
+ *
2193
+ * @param p A pointer returned by SherpaOnnxCreateVoiceActivityDetector().
2194
+ * @return The first queued speech segment, or NULL if none is available.
2195
+ *
2196
+ * @code
2197
+ * while (!SherpaOnnxVoiceActivityDetectorEmpty(vad)) {
2198
+ * const SherpaOnnxSpeechSegment *segment =
2199
+ * SherpaOnnxVoiceActivityDetectorFront(vad);
2200
+ * printf("start=%d, samples=%d\n", segment->start, segment->n);
2201
+ * SherpaOnnxDestroySpeechSegment(segment);
2202
+ * SherpaOnnxVoiceActivityDetectorPop(vad);
2203
+ * }
2204
+ * @endcode
2205
+ * @see SherpaOnnxSpeechSegment, SherpaOnnxDestroySpeechSegment
2206
+ */
2207
+ SHERPA_ONNX_API const SherpaOnnxSpeechSegment *
2208
+ SherpaOnnxVoiceActivityDetectorFront(const SherpaOnnxVoiceActivityDetector *p);
2209
+
2210
+ /**
2211
+ * @brief Destroy a speech segment returned by
2212
+ * SherpaOnnxVoiceActivityDetectorFront().
2213
+ *
2214
+ * @param p A pointer returned by SherpaOnnxVoiceActivityDetectorFront().
2215
+ * @see SherpaOnnxVoiceActivityDetectorFront
2216
+ */
2217
+ SHERPA_ONNX_API void SherpaOnnxDestroySpeechSegment(
2218
+ const SherpaOnnxSpeechSegment *p);
2219
+
2220
+ /**
2221
+ * @brief Reset a voice activity detector so it can process a new stream.
2222
+ *
2223
+ * @param p A pointer returned by SherpaOnnxCreateVoiceActivityDetector().
2224
+ */
2225
+ SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorReset(
2226
+ const SherpaOnnxVoiceActivityDetector *p);
2227
+
2228
+ /**
2229
+ * @brief Flush buffered tail samples and force final segmentation.
2230
+ *
2231
+ * Call this after the last chunk of input has been fed.
2232
+ *
2233
+ * @param p A pointer returned by SherpaOnnxCreateVoiceActivityDetector().
2234
+ *
2235
+ * @code
2236
+ * SherpaOnnxVoiceActivityDetectorFlush(vad);
2237
+ * @endcode
2238
+ */
2239
+ SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorFlush(
2240
+ const SherpaOnnxVoiceActivityDetector *p);
2241
+
2242
+ // ============================================================
2243
+ // For offline Text-to-Speech (i.e., non-streaming TTS)
2244
+ // ============================================================
2245
+
2246
+ /** @brief Configuration for a VITS TTS model. */
2247
+ typedef struct SherpaOnnxOfflineTtsVitsModelConfig {
2248
+ /** Path to the VITS ONNX model, for example `./vits-ljs.onnx`. */
2249
+ const char *model;
2250
+ /** Path to the lexicon file. Ignored if @c data_dir is provided. */
2251
+ const char *lexicon;
2252
+ /** Path to the tokens file. */
2253
+ const char *tokens;
2254
+ /** Optional path to espeak-ng-data. */
2255
+ const char *data_dir;
2256
+ /** VITS noise scale. */
2257
+ float noise_scale;
2258
+ /** VITS duration noise scale. */
2259
+ float noise_scale_w;
2260
+ /** Speech rate scale. Values < 1 are slower; values > 1 are faster. */
2261
+ float length_scale;
2262
+ /** Unused legacy field kept for ABI compatibility. */
2263
+ const char *dict_dir;
2264
+ } SherpaOnnxOfflineTtsVitsModelConfig;
2265
+
2266
+ /** @brief Configuration for a Matcha TTS model. */
2267
+ typedef struct SherpaOnnxOfflineTtsMatchaModelConfig {
2268
+ /** Path to the Matcha acoustic model. */
2269
+ const char *acoustic_model;
2270
+ /** Path to the vocoder model, for example `./vocos-22khz-univ.onnx`. */
2271
+ const char *vocoder;
2272
+ /** Path to the lexicon file. */
2273
+ const char *lexicon;
2274
+ /** Path to the tokens file. */
2275
+ const char *tokens;
2276
+ /** Optional path to espeak-ng-data. */
2277
+ const char *data_dir;
2278
+ /** Matcha noise scale. */
2279
+ float noise_scale;
2280
+ /** Speech rate scale. Values < 1 are slower; values > 1 are faster. */
2281
+ float length_scale;
2282
+ /** Unused legacy field kept for ABI compatibility. */
2283
+ const char *dict_dir;
2284
+ } SherpaOnnxOfflineTtsMatchaModelConfig;
2285
+
2286
+ /** @brief Configuration for a Kokoro TTS model. */
2287
+ typedef struct SherpaOnnxOfflineTtsKokoroModelConfig {
2288
+ /** Path to the Kokoro model, for example `./kokoro-en-v0_19/model.onnx`. */
2289
+ const char *model;
2290
+ /** Path to the Kokoro voices file. */
2291
+ const char *voices;
2292
+ /** Path to the tokens file. */
2293
+ const char *tokens;
2294
+ /** Optional path to espeak-ng-data. */
2295
+ const char *data_dir;
2296
+ /** Speech rate scale. Values < 1 are slower; values > 1 are faster. */
2297
+ float length_scale;
2298
+ /** Unused legacy field kept for ABI compatibility. */
2299
+ const char *dict_dir;
2300
+ /** Optional lexicon file. */
2301
+ const char *lexicon;
2302
+ /** Optional language hint. */
2303
+ const char *lang;
2304
+ } SherpaOnnxOfflineTtsKokoroModelConfig;
2305
+
2306
+ /** @brief Configuration for a Kitten TTS model. */
2307
+ typedef struct SherpaOnnxOfflineTtsKittenModelConfig {
2308
+ /** Path to the Kitten model. */
2309
+ const char *model;
2310
+ /** Path to the Kitten voices file. */
2311
+ const char *voices;
2312
+ /** Path to the tokens file. */
2313
+ const char *tokens;
2314
+ /** Optional path to espeak-ng-data. */
2315
+ const char *data_dir;
2316
+ /** Speech rate scale. Values < 1 are slower; values > 1 are faster. */
2317
+ float length_scale;
2318
+ } SherpaOnnxOfflineTtsKittenModelConfig;
2319
+
2320
+ /** @brief Configuration for a ZipVoice TTS model. */
2321
+ typedef struct SherpaOnnxOfflineTtsZipvoiceModelConfig {
2322
+ /** Path to the tokens file. */
2323
+ const char *tokens;
2324
+ /** Path to the ZipVoice encoder model. */
2325
+ const char *encoder;
2326
+ /** Path to the ZipVoice decoder model. */
2327
+ const char *decoder;
2328
+ /** Path to the vocoder model. */
2329
+ const char *vocoder;
2330
+ /** Optional path to espeak-ng-data. */
2331
+ const char *data_dir;
2332
+ /** Path to the lexicon file. */
2333
+ const char *lexicon;
2334
+ /** Feature scaling factor. */
2335
+ float feat_scale;
2336
+ /** Time shift parameter. */
2337
+ float t_shift;
2338
+ /** Target RMS parameter. */
2339
+ float target_rms;
2340
+ /** Guidance scale parameter. */
2341
+ float guidance_scale;
2342
+ } SherpaOnnxOfflineTtsZipvoiceModelConfig;
2343
+
2344
+ /** @brief Configuration for a Pocket TTS model. */
2345
+ typedef struct SherpaOnnxOfflineTtsPocketModelConfig {
2346
+ /** Path to `lm_flow*.onnx`. */
2347
+ const char *lm_flow;
2348
+ /** Path to `lm_main*.onnx`. */
2349
+ const char *lm_main;
2350
+ /** Path to the Pocket encoder model. */
2351
+ const char *encoder;
2352
+ /** Path to the Pocket decoder model. */
2353
+ const char *decoder;
2354
+ /** Path to the text conditioner model. */
2355
+ const char *text_conditioner;
2356
+ /** Path to `vocab.json`. */
2357
+ const char *vocab_json;
2358
+ /** Path to `token_scores.json`. */
2359
+ const char *token_scores_json;
2360
+ /** Voice embedding cache capacity. */
2361
+ int32_t voice_embedding_cache_capacity;
2362
+ } SherpaOnnxOfflineTtsPocketModelConfig;
2363
+
2364
+ /** @brief Configuration for a Supertonic TTS model. */
2365
+ typedef struct SherpaOnnxOfflineTtsSupertonicModelConfig {
2366
+ /** Path to the duration predictor model. */
2367
+ const char *duration_predictor;
2368
+ /** Path to the text encoder model. */
2369
+ const char *text_encoder;
2370
+ /** Path to the vector estimator model. */
2371
+ const char *vector_estimator;
2372
+ /** Path to the vocoder model. */
2373
+ const char *vocoder;
2374
+ /** Path to `tts.json`. */
2375
+ const char *tts_json;
2376
+ /** Path to the unicode indexer file. */
2377
+ const char *unicode_indexer;
2378
+ /** Path to the voice style file. */
2379
+ const char *voice_style;
2380
+ } SherpaOnnxOfflineTtsSupertonicModelConfig;
2381
+
2382
+ /**
2383
+ * @brief Configuration shared by offline TTS models.
2384
+ *
2385
+ * Exactly one TTS model family should be configured. For example, set only one
2386
+ * of @c vits, @c matcha, @c kokoro, @c kitten, @c zipvoice, @c pocket, or
2387
+ * @c supertonic.
2388
+ *
2389
+ * If multiple model families are configured at the same time, the
2390
+ * implementation will choose one of them, and which one is used is
2391
+ * implementation-defined. Do not rely on any precedence rule.
2392
+ *
2393
+ * Concrete example model packages in this repository include:
2394
+ * - `kokoro-en-v0_19`
2395
+ * - `sherpa-onnx-pocket-tts-int8-2026-01-26`
2396
+ * - `matcha-icefall-en_US-ljspeech`
2397
+ * - `sherpa-onnx-zipvoice-distill-int8-zh-en-emilia`
2398
+ */
2399
+ typedef struct SherpaOnnxOfflineTtsModelConfig {
2400
+ /** VITS configuration. */
2401
+ SherpaOnnxOfflineTtsVitsModelConfig vits;
2402
+ /** Number of backend threads. */
2403
+ int32_t num_threads;
2404
+ /** Non-zero to print debug information. */
2405
+ int32_t debug;
2406
+ /** Execution provider, for example "cpu" or "cuda". */
2407
+ const char *provider;
2408
+ /** Matcha configuration. */
2409
+ SherpaOnnxOfflineTtsMatchaModelConfig matcha;
2410
+ /** Kokoro configuration. */
2411
+ SherpaOnnxOfflineTtsKokoroModelConfig kokoro;
2412
+ /** Kitten configuration. */
2413
+ SherpaOnnxOfflineTtsKittenModelConfig kitten;
2414
+ /** ZipVoice configuration. */
2415
+ SherpaOnnxOfflineTtsZipvoiceModelConfig zipvoice;
2416
+ /** Pocket configuration. */
2417
+ SherpaOnnxOfflineTtsPocketModelConfig pocket;
2418
+ /** Supertonic configuration. */
2419
+ SherpaOnnxOfflineTtsSupertonicModelConfig supertonic;
2420
+ } SherpaOnnxOfflineTtsModelConfig;
2421
+
2422
+ /**
2423
+ * @brief Configuration for offline text-to-speech.
2424
+ *
2425
+ * @code
2426
+ * SherpaOnnxOfflineTtsConfig config;
2427
+ * memset(&config, 0, sizeof(config));
2428
+ *
2429
+ * config.model.kokoro.model = "./kokoro-en-v0_19/model.onnx";
2430
+ * config.model.kokoro.voices = "./kokoro-en-v0_19/voices.bin";
2431
+ * config.model.kokoro.tokens = "./kokoro-en-v0_19/tokens.txt";
2432
+ * config.model.kokoro.data_dir = "./kokoro-en-v0_19/espeak-ng-data";
2433
+ * config.model.num_threads = 2;
2434
+ * config.model.provider = "cpu";
2435
+ * config.model.debug = 0;
2436
+ * config.max_num_sentences = 2;
2437
+ * @endcode
2438
+ * @see SherpaOnnxCreateOfflineTts
2439
+ */
2440
+ typedef struct SherpaOnnxOfflineTtsConfig {
2441
+ /** TTS model configuration. */
2442
+ SherpaOnnxOfflineTtsModelConfig model;
2443
+ /** Optional comma-separated rule FST list. */
2444
+ const char *rule_fsts;
2445
+ /** Maximum number of sentences processed per chunk. */
2446
+ int32_t max_num_sentences;
2447
+ /** Optional FAR archives used by text normalization rules. */
2448
+ const char *rule_fars;
2449
+ /** Default silence scale between sentences. */
2450
+ float silence_scale;
2451
+ } SherpaOnnxOfflineTtsConfig;
2452
+
2453
+ /**
2454
+ * @brief Generated waveform returned by TTS APIs.
2455
+ *
2456
+ * The returned structure owns @c samples. Free the whole object with
2457
+ * SherpaOnnxDestroyOfflineTtsGeneratedAudio().
2458
+ * @see SherpaOnnxOfflineTtsGenerateWithConfig, SherpaOnnxDestroyOfflineTtsGeneratedAudio
2459
+ */
2460
+ typedef struct SherpaOnnxGeneratedAudio {
2461
+ /** Generated mono samples in the range [-1, 1]. */
2462
+ const float *samples;
2463
+ /** Number of samples in @c samples. */
2464
+ int32_t n;
2465
+ /** Output sample rate. */
2466
+ int32_t sample_rate;
2467
+ } SherpaOnnxGeneratedAudio;
2468
+
2469
+ /**
2470
+ * @brief Callback invoked during incremental generation.
2471
+ *
2472
+ * Return 1 to continue generation. Return 0 to stop early.
2473
+ *
2474
+ * The @p samples pointer is only valid during the callback. Copy the samples if
2475
+ * you need to keep them after the callback returns.
2476
+ */
2477
+ typedef int32_t (*SherpaOnnxGeneratedAudioCallback)(const float *samples,
2478
+ int32_t n);
2479
+
2480
+ /**
2481
+ * @brief Same as SherpaOnnxGeneratedAudioCallback but with an extra user
2482
+ * pointer.
2483
+ */
2484
+ typedef int32_t (*SherpaOnnxGeneratedAudioCallbackWithArg)(const float *samples,
2485
+ int32_t n,
2486
+ void *arg);
2487
+
2488
+ /**
2489
+ * @brief Progress callback invoked during incremental generation.
2490
+ *
2491
+ * @param samples Newly generated samples valid only during the callback.
2492
+ * @param n Number of samples in @p samples.
2493
+ * @param p Progress in the range [0, 1].
2494
+ * @return Return 1 to continue generation. Return 0 to stop early.
2495
+ */
2496
+ typedef int32_t (*SherpaOnnxGeneratedAudioProgressCallback)(
2497
+ const float *samples, int32_t n, float p);
2498
+
2499
+ /**
2500
+ * @brief Same as SherpaOnnxGeneratedAudioProgressCallback but with an extra
2501
+ * user pointer.
2502
+ */
2503
+ typedef int32_t (*SherpaOnnxGeneratedAudioProgressCallbackWithArg)(
2504
+ const float *samples, int32_t n, float p, void *arg);
2505
+
2506
+ /** @brief Opaque offline TTS handle. */
2507
+ typedef struct SherpaOnnxOfflineTts SherpaOnnxOfflineTts;
2508
+
2509
+ /**
2510
+ * @brief Create an offline TTS engine.
2511
+ *
2512
+ * @param config TTS configuration.
2513
+ * @return A newly allocated TTS engine on success, or NULL on configuration
2514
+ * error. Free it with SherpaOnnxDestroyOfflineTts().
2515
+ *
2516
+ * @code
2517
+ * SherpaOnnxOfflineTtsConfig config;
2518
+ * memset(&config, 0, sizeof(config));
2519
+ * config.model.kokoro.model = "./kokoro-en-v0_19/model.onnx";
2520
+ * config.model.kokoro.voices = "./kokoro-en-v0_19/voices.bin";
2521
+ * config.model.kokoro.tokens = "./kokoro-en-v0_19/tokens.txt";
2522
+ * config.model.kokoro.data_dir = "./kokoro-en-v0_19/espeak-ng-data";
2523
+ * config.model.num_threads = 2;
2524
+ *
2525
+ * const SherpaOnnxOfflineTts *tts = SherpaOnnxCreateOfflineTts(&config);
2526
+ * @endcode
2527
+ * @see SherpaOnnxOfflineTtsConfig, SherpaOnnxDestroyOfflineTts
2528
+ */
2529
+ SHERPA_ONNX_API const SherpaOnnxOfflineTts *SherpaOnnxCreateOfflineTts(
2530
+ const SherpaOnnxOfflineTtsConfig *config);
2531
+
2532
+ /**
2533
+ * @brief Destroy an offline TTS engine.
2534
+ *
2535
+ * @param tts A pointer returned by SherpaOnnxCreateOfflineTts().
2536
+ * @see SherpaOnnxCreateOfflineTts
2537
+ */
2538
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTts(
2539
+ const SherpaOnnxOfflineTts *tts);
2540
+
2541
+ /**
2542
+ * @brief Return the output sample rate of a TTS engine.
2543
+ *
2544
+ * @param tts A pointer returned by SherpaOnnxCreateOfflineTts().
2545
+ * @return Output sample rate in Hz.
2546
+ */
2547
+ SHERPA_ONNX_API int32_t
2548
+ SherpaOnnxOfflineTtsSampleRate(const SherpaOnnxOfflineTts *tts);
2549
+
2550
+ /**
2551
+ * @brief Return the number of available speaker IDs.
2552
+ *
2553
+ * Single-speaker models often return 1.
2554
+ *
2555
+ * @param tts A pointer returned by SherpaOnnxCreateOfflineTts().
2556
+ * @return Number of speakers supported by the model.
2557
+ */
2558
+ SHERPA_ONNX_API int32_t
2559
+ SherpaOnnxOfflineTtsNumSpeakers(const SherpaOnnxOfflineTts *tts);
2560
+
2561
+ /**
2562
+ * @brief Generate speech from text using the simple sid/speed interface.
2563
+ *
2564
+ * @deprecated Use SherpaOnnxOfflineTtsGenerateWithConfig() instead.
2565
+ *
2566
+ * @param tts A pointer returned by SherpaOnnxCreateOfflineTts().
2567
+ * @param text Input text.
2568
+ * @param sid Speaker ID for multi-speaker models.
2569
+ * @param speed Speech rate. Values > 1 are faster.
2570
+ * @return Generated audio, or NULL on error. Free it with
2571
+ * SherpaOnnxDestroyOfflineTtsGeneratedAudio().
2572
+ *
2573
+ * @code
2574
+ * const SherpaOnnxGeneratedAudio *audio =
2575
+ * SherpaOnnxOfflineTtsGenerate(tts, "Hello from sherpa-onnx!", 0, 1.0f);
2576
+ * SherpaOnnxWriteWave(audio->samples, audio->n, audio->sample_rate,
2577
+ * "./generated.wav");
2578
+ * SherpaOnnxDestroyOfflineTtsGeneratedAudio(audio);
2579
+ * @endcode
2580
+ * @see SherpaOnnxDestroyOfflineTtsGeneratedAudio, SherpaOnnxGenerationConfig
2581
+ */
2582
+ SHERPA_ONNX_API SHERPA_ONNX_DEPRECATED(
2583
+ "Use SherpaOnnxOfflineTtsGenerateWithConfig() instead") const
2584
+ SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerate(
2585
+ const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid,
2586
+ float speed);
2587
+
2588
+ /**
2589
+ * @brief Generate speech and receive incremental audio chunks through a
2590
+ * callback.
2591
+ *
2592
+ * @deprecated Use SherpaOnnxOfflineTtsGenerateWithConfig() instead.
2593
+ *
2594
+ * The callback receives newly generated samples. The sample pointer is valid
2595
+ * only for the duration of the callback.
2596
+ *
2597
+ * @param tts A pointer returned by SherpaOnnxCreateOfflineTts().
2598
+ * @param text Input text.
2599
+ * @param sid Speaker ID for multi-speaker models.
2600
+ * @param speed Speech rate. Values > 1 are faster.
2601
+ * @param callback Incremental callback. Return 0 to stop generation early.
2602
+ * @return Final generated audio, or NULL on error. Free it with
2603
+ * SherpaOnnxDestroyOfflineTtsGeneratedAudio().
2604
+ */
2605
+ SHERPA_ONNX_API SHERPA_ONNX_DEPRECATED(
2606
+ "Use SherpaOnnxOfflineTtsGenerateWithConfig() instead") const
2607
+ SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerateWithCallback(
2608
+ const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid,
2609
+ float speed, SherpaOnnxGeneratedAudioCallback callback);
2610
+
2611
+ /**
2612
+ * @brief Generate speech with a progress callback.
2613
+ *
2614
+ * @deprecated Use SherpaOnnxOfflineTtsGenerateWithConfig() instead.
2615
+ *
2616
+ * @param tts A pointer returned by SherpaOnnxCreateOfflineTts().
2617
+ * @param text Input text.
2618
+ * @param sid Speaker ID for multi-speaker models.
2619
+ * @param speed Speech rate. Values > 1 are faster.
2620
+ * @param callback Progress callback. Return 0 to stop generation early.
2621
+ * @return Final generated audio, or NULL on error. Free it with
2622
+ * SherpaOnnxDestroyOfflineTtsGeneratedAudio().
2623
+ *
2624
+ * @code
2625
+ * int32_t Progress(const float *samples, int32_t n, float p) {
2626
+ * fprintf(stderr, "Progress: %.2f%%\n", p * 100);
2627
+ * return 1;
2628
+ * }
2629
+ *
2630
+ * const SherpaOnnxGeneratedAudio *audio =
2631
+ * SherpaOnnxOfflineTtsGenerateWithProgressCallback(tts, text, 0, 1.0f,
2632
+ * Progress);
2633
+ * @endcode
2634
+ */
2635
+ SHERPA_ONNX_API SHERPA_ONNX_DEPRECATED(
2636
+ "Use SherpaOnnxOfflineTtsGenerateWithConfig() instead") const
2637
+ SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerateWithProgressCallback(
2638
+ const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid,
2639
+ float speed, SherpaOnnxGeneratedAudioProgressCallback callback);
2640
+
2641
+ /**
2642
+ * @brief Generate speech with a progress callback that receives a user pointer.
2643
+ *
2644
+ * @deprecated Use SherpaOnnxOfflineTtsGenerateWithConfig() instead.
2645
+ *
2646
+ * @param tts A pointer returned by SherpaOnnxCreateOfflineTts().
2647
+ * @param text Input text.
2648
+ * @param sid Speaker ID for multi-speaker models.
2649
+ * @param speed Speech rate. Values > 1 are faster.
2650
+ * @param callback Progress callback with user pointer. Return 0 to stop early.
2651
+ * @param arg User pointer forwarded to @p callback.
2652
+ * @return Final generated audio, or NULL on error. Free it with
2653
+ * SherpaOnnxDestroyOfflineTtsGeneratedAudio().
2654
+ */
2655
+ SHERPA_ONNX_API SHERPA_ONNX_DEPRECATED(
2656
+ "Use SherpaOnnxOfflineTtsGenerateWithConfig() instead") const
2657
+ SherpaOnnxGeneratedAudio
2658
+ *SherpaOnnxOfflineTtsGenerateWithProgressCallbackWithArg(
2659
+ const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid,
2660
+ float speed,
2661
+ SherpaOnnxGeneratedAudioProgressCallbackWithArg callback,
2662
+ void *arg);
2663
+
2664
+ /**
2665
+ * @brief Same as SherpaOnnxOfflineTtsGenerateWithCallback() but with a user
2666
+ * pointer.
2667
+ *
2668
+ * @deprecated Use SherpaOnnxOfflineTtsGenerateWithConfig() instead.
2669
+ *
2670
+ * @param tts A pointer returned by SherpaOnnxCreateOfflineTts().
2671
+ * @param text Input text.
2672
+ * @param sid Speaker ID for multi-speaker models.
2673
+ * @param speed Speech rate. Values > 1 are faster.
2674
+ * @param callback Incremental callback with user pointer.
2675
+ * @param arg User pointer forwarded to @p callback.
2676
+ * @return Final generated audio, or NULL on error. Free it with
2677
+ * SherpaOnnxDestroyOfflineTtsGeneratedAudio().
2678
+ */
2679
+ SHERPA_ONNX_API SHERPA_ONNX_DEPRECATED(
2680
+ "Use SherpaOnnxOfflineTtsGenerateWithConfig() instead") const
2681
+ SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerateWithCallbackWithArg(
2682
+ const SherpaOnnxOfflineTts *tts, const char *text, int32_t sid,
2683
+ float speed, SherpaOnnxGeneratedAudioCallbackWithArg callback,
2684
+ void *arg);
2685
+
2686
+ /**
2687
+ * @brief Deprecated ZipVoice-specific generation API.
2688
+ *
2689
+ * Use SherpaOnnxOfflineTtsGenerateWithConfig() instead.
2690
+ */
2691
+ SHERPA_ONNX_API SHERPA_ONNX_DEPRECATED(
2692
+ "Use SherpaOnnxOfflineTtsGenerateWithConfig() instead") const
2693
+ SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerateWithZipvoice(
2694
+ const SherpaOnnxOfflineTts *tts, const char *text,
2695
+ const char *prompt_text, const float *prompt_samples, int32_t n_prompt,
2696
+ int32_t prompt_sr, float speed, int32_t num_steps);
2697
+
2698
+ /**
2699
+ * @brief Generation-time parameters shared by advanced TTS APIs.
2700
+ *
2701
+ * This struct supports both simple multi-speaker synthesis and more advanced
2702
+ * zero-shot or reference-conditioned models.
2703
+ *
2704
+ * Example for Pocket TTS:
2705
+ *
2706
+ * @code
2707
+ * SherpaOnnxGenerationConfig cfg;
2708
+ * memset(&cfg, 0, sizeof(cfg));
2709
+ * cfg.speed = 1.0f;
2710
+ * cfg.reference_audio = wave->samples;
2711
+ * cfg.reference_audio_len = wave->num_samples;
2712
+ * cfg.reference_sample_rate = wave->sample_rate;
2713
+ * cfg.extra = "{\"max_reference_audio_len\": 10.0, \"seed\": 42}";
2714
+ * @endcode
2715
+ * @see SherpaOnnxOfflineTtsGenerateWithConfig
2716
+ */
2717
+ typedef struct SherpaOnnxGenerationConfig {
2718
+ /** Silence scale between sentences. */
2719
+ float silence_scale;
2720
+ /** Speech rate. Used only by models that support it. */
2721
+ float speed;
2722
+ /** Speaker ID for multi-speaker models. */
2723
+ int32_t sid;
2724
+ /** Optional reference audio for zero-shot or voice-cloning models. */
2725
+ const float *reference_audio;
2726
+ /** Length of @c reference_audio in samples. */
2727
+ int32_t reference_audio_len;
2728
+ /** Sample rate of @c reference_audio. */
2729
+ int32_t reference_sample_rate;
2730
+ /** Optional reference text associated with @c reference_audio. */
2731
+ const char *reference_text;
2732
+ /** Optional number of flow-matching steps. */
2733
+ int32_t num_steps;
2734
+ /** Optional model-specific JSON string with extra key/value pairs. */
2735
+ const char *extra;
2736
+ } SherpaOnnxGenerationConfig;
2737
+
2738
+ /**
2739
+ * @brief Generate speech using the advanced configuration interface.
2740
+ *
2741
+ * This is the preferred API for new integrations. It supports callback-based
2742
+ * progress reporting and model-specific options such as reference audio.
2743
+ *
2744
+ * @param tts A pointer returned by SherpaOnnxCreateOfflineTts().
2745
+ * @param text Input text.
2746
+ * @param config Generation-time configuration.
2747
+ * @param callback Optional progress callback with user pointer. Return 0 to
2748
+ * stop early.
2749
+ * @param arg User pointer forwarded to @p callback.
2750
+ * @return Generated audio, or NULL on error. Free it with
2751
+ * SherpaOnnxDestroyOfflineTtsGeneratedAudio().
2752
+ *
2753
+ * @code
2754
+ * SherpaOnnxGenerationConfig cfg;
2755
+ * memset(&cfg, 0, sizeof(cfg));
2756
+ * cfg.sid = 0;
2757
+ * cfg.speed = 1.0f;
2758
+ * cfg.silence_scale = 0.2f;
2759
+ *
2760
+ * const SherpaOnnxGeneratedAudio *audio =
2761
+ * SherpaOnnxOfflineTtsGenerateWithConfig(tts,
2762
+ * "Today as always, men fall into two groups.",
2763
+ * &cfg, NULL, NULL);
2764
+ * @endcode
2765
+ */
2766
+ SHERPA_ONNX_API const SherpaOnnxGeneratedAudio *
2767
+ SherpaOnnxOfflineTtsGenerateWithConfig(
2768
+ const SherpaOnnxOfflineTts *tts, const char *text,
2769
+ const SherpaOnnxGenerationConfig *config,
2770
+ SherpaOnnxGeneratedAudioProgressCallbackWithArg callback, void *arg);
2771
+
2772
+ /**
2773
+ * @brief Destroy audio returned by a TTS generation API.
2774
+ *
2775
+ * @param p A pointer returned by one of the SherpaOnnxOfflineTtsGenerate*
2776
+ * functions.
2777
+ * @see SherpaOnnxOfflineTtsGenerateWithConfig
2778
+ */
2779
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTtsGeneratedAudio(
2780
+ const SherpaOnnxGeneratedAudio *p);
2781
+
2782
+ /**
2783
+ * @brief Write floating-point PCM to a mono 16-bit WAVE file.
2784
+ *
2785
+ * @param samples Pointer to @p n samples in the range [-1, 1].
2786
+ * @param n Number of samples.
2787
+ * @param sample_rate Sample rate in Hz.
2788
+ * @param filename Output filename.
2789
+ * @return 1 on success; 0 on failure.
2790
+ *
2791
+ * @code
2792
+ * SherpaOnnxWriteWave(audio->samples, audio->n, audio->sample_rate,
2793
+ * "./generated-kokoro-en.wav");
2794
+ * @endcode
2795
+ * @see SherpaOnnxReadWave
2796
+ */
2797
+ SHERPA_ONNX_API int32_t SherpaOnnxWriteWave(const float *samples, int32_t n,
2798
+ int32_t sample_rate,
2799
+ const char *filename);
2800
+
2801
+ /**
2802
+ * @brief Return the number of bytes needed for a mono 16-bit WAVE file.
2803
+ *
2804
+ * @param n_samples Number of PCM samples.
2805
+ * @return Required buffer size in bytes.
2806
+ */
2807
+ SHERPA_ONNX_API int64_t SherpaOnnxWaveFileSize(int32_t n_samples);
2808
+
2809
+ /**
2810
+ * @brief Write a mono 16-bit WAVE file to a caller-provided buffer.
2811
+ *
2812
+ * Allocate at least SherpaOnnxWaveFileSize(@p n) bytes before calling.
2813
+ *
2814
+ * @param samples Pointer to @p n samples in the range [-1, 1].
2815
+ * @param n Number of samples.
2816
+ * @param sample_rate Sample rate in Hz.
2817
+ * @param buffer Output buffer.
2818
+ */
2819
+ SHERPA_ONNX_API void SherpaOnnxWriteWaveToBuffer(const float *samples,
2820
+ int32_t n, int32_t sample_rate,
2821
+ char *buffer);
2822
+
2823
+ /**
2824
+ * @brief Write multi-channel audio to a WAVE file (16-bit PCM).
2825
+ *
2826
+ * @param samples samples[c] is a pointer to channel c samples in [-1, 1].
2827
+ * @param n Number of samples per channel.
2828
+ * @param sample_rate Sample rate in Hz.
2829
+ * @param num_channels Number of channels.
2830
+ * @param filename Output filename.
2831
+ * @return 1 on success; 0 on failure.
2832
+ */
2833
+ SHERPA_ONNX_API int32_t SherpaOnnxWriteWaveMultiChannel(
2834
+ const float *const *samples, int32_t n, int32_t sample_rate,
2835
+ int32_t num_channels, const char *filename);
2836
+
2837
+ /**
2838
+ * @brief Decoded mono WAVE file content.
2839
+ *
2840
+ * Free this object with SherpaOnnxFreeWave().
2841
+ * @see SherpaOnnxReadWave, SherpaOnnxFreeWave
2842
+ */
2843
+ typedef struct SherpaOnnxWave {
2844
+ /** Samples normalized to the range [-1, 1]. */
2845
+ const float *samples;
2846
+ /** Sample rate in Hz. */
2847
+ int32_t sample_rate;
2848
+ /** Number of samples. */
2849
+ int32_t num_samples;
2850
+ } SherpaOnnxWave;
2851
+
2852
+ /**
2853
+ * @brief Read a mono 16-bit PCM WAVE file.
2854
+ *
2855
+ * @param filename Input WAVE filename.
2856
+ * @return A newly allocated wave object, or NULL on error. Free it with
2857
+ * SherpaOnnxFreeWave().
2858
+ *
2859
+ * @code
2860
+ * const SherpaOnnxWave *wave = SherpaOnnxReadWave("./Obama.wav");
2861
+ * if (wave) {
2862
+ * printf("sample_rate=%d, num_samples=%d\n",
2863
+ * wave->sample_rate, wave->num_samples);
2864
+ * SherpaOnnxFreeWave(wave);
2865
+ * }
2866
+ * @endcode
2867
+ * @see SherpaOnnxFreeWave, SherpaOnnxWave
2868
+ */
2869
+ SHERPA_ONNX_API const SherpaOnnxWave *SherpaOnnxReadWave(const char *filename);
2870
+
2871
+ /**
2872
+ * @brief Read a mono 16-bit PCM WAVE file from binary memory.
2873
+ *
2874
+ * @param data Pointer to the WAVE file bytes.
2875
+ * @param n Size of @p data in bytes.
2876
+ * @return A newly allocated wave object, or NULL on error. Free it with
2877
+ * SherpaOnnxFreeWave().
2878
+ */
2879
+ SHERPA_ONNX_API const SherpaOnnxWave *SherpaOnnxReadWaveFromBinaryData(
2880
+ const char *data, int32_t n);
2881
+
2882
+ /**
2883
+ * @brief Destroy a wave object returned by SherpaOnnxReadWave() or
2884
+ * SherpaOnnxReadWaveFromBinaryData().
2885
+ * @see SherpaOnnxReadWave
2886
+ */
2887
+ SHERPA_ONNX_API void SherpaOnnxFreeWave(const SherpaOnnxWave *wave);
2888
+
2889
+ /**
2890
+ * @brief Decoded multi-channel WAVE file content.
2891
+ *
2892
+ * Free this object with SherpaOnnxFreeMultiChannelWave().
2893
+ */
2894
+ typedef struct SherpaOnnxMultiChannelWave {
2895
+ /** samples[c] points to channel c samples normalized to [-1, 1].
2896
+ * Note: The sample data for all channels are stored in a single contiguous
2897
+ * memory block, one channel after another.
2898
+ * */
2899
+ const float *const *samples;
2900
+ /** Number of channels. */
2901
+ int32_t num_channels;
2902
+ /** Number of samples per channel. */
2903
+ int32_t num_samples;
2904
+ /** Sample rate in Hz. */
2905
+ int32_t sample_rate;
2906
+ } SherpaOnnxMultiChannelWave;
2907
+
2908
+ /**
2909
+ * @brief Read a multi-channel 16-bit PCM WAVE file.
2910
+ *
2911
+ * @param filename Input WAVE filename.
2912
+ * @return A newly allocated multi-channel wave object, or NULL on error.
2913
+ * Free it with SherpaOnnxFreeMultiChannelWave().
2914
+ */
2915
+ SHERPA_ONNX_API const SherpaOnnxMultiChannelWave *
2916
+ SherpaOnnxReadWaveMultiChannel(const char *filename);
2917
+
2918
+ /**
2919
+ * @brief Destroy a multi-channel wave object.
2920
+ *
2921
+ * @param wave A pointer returned by SherpaOnnxReadWaveMultiChannel().
2922
+ */
2923
+ SHERPA_ONNX_API void SherpaOnnxFreeMultiChannelWave(
2924
+ const SherpaOnnxMultiChannelWave *wave);
2925
+
2926
+ // ============================================================
2927
+ // For spoken language identification
2928
+ // ============================================================
2929
+
2930
+ /**
2931
+ * @brief Whisper-based model files for spoken language identification.
2932
+ *
2933
+ * Example:
2934
+ *
2935
+ * @code
2936
+ * SherpaOnnxSpokenLanguageIdentificationWhisperConfig whisper;
2937
+ * memset(&whisper, 0, sizeof(whisper));
2938
+ * whisper.encoder = "./sherpa-onnx-whisper-tiny/tiny-encoder.int8.onnx";
2939
+ * whisper.decoder = "./sherpa-onnx-whisper-tiny/tiny-decoder.int8.onnx";
2940
+ * @endcode
2941
+ */
2942
+ typedef struct SherpaOnnxSpokenLanguageIdentificationWhisperConfig {
2943
+ /** Whisper encoder model. */
2944
+ const char *encoder;
2945
+ /** Whisper decoder model. */
2946
+ const char *decoder;
2947
+ /** Optional tail padding in samples appended internally before inference. */
2948
+ int32_t tail_paddings;
2949
+ } SherpaOnnxSpokenLanguageIdentificationWhisperConfig;
2950
+
2951
+ /**
2952
+ * @brief Configuration for spoken language identification.
2953
+ *
2954
+ * The current implementation uses Whisper-based models.
2955
+ *
2956
+ * Example using `sherpa-onnx-whisper-tiny`:
2957
+ *
2958
+ * @code
2959
+ * SherpaOnnxSpokenLanguageIdentificationConfig config;
2960
+ * memset(&config, 0, sizeof(config));
2961
+ * config.whisper.encoder = "./sherpa-onnx-whisper-tiny/tiny-encoder.int8.onnx";
2962
+ * config.whisper.decoder = "./sherpa-onnx-whisper-tiny/tiny-decoder.int8.onnx";
2963
+ * config.num_threads = 1;
2964
+ * config.provider = "cpu";
2965
+ * @endcode
2966
+ */
2967
+ typedef struct SherpaOnnxSpokenLanguageIdentificationConfig {
2968
+ /** Whisper model configuration. */
2969
+ SherpaOnnxSpokenLanguageIdentificationWhisperConfig whisper;
2970
+ /** Number of inference threads. */
2971
+ int32_t num_threads;
2972
+ /** Non-zero to print debug information. */
2973
+ int32_t debug;
2974
+ /** Execution provider such as `"cpu"`. */
2975
+ const char *provider;
2976
+ } SherpaOnnxSpokenLanguageIdentificationConfig;
2977
+
2978
+ /** @brief Opaque spoken-language identification handle. */
2979
+ typedef struct SherpaOnnxSpokenLanguageIdentification
2980
+ SherpaOnnxSpokenLanguageIdentification;
2981
+
2982
+ /**
2983
+ * @brief Create a spoken-language identifier.
2984
+ *
2985
+ * @param config Spoken-language identification configuration.
2986
+ * @return A newly allocated identifier on success, or NULL on error. Free it
2987
+ * with SherpaOnnxDestroySpokenLanguageIdentification().
2988
+ * @see SherpaOnnxDestroySpokenLanguageIdentification
2989
+ */
2990
+ SHERPA_ONNX_API const SherpaOnnxSpokenLanguageIdentification *
2991
+ SherpaOnnxCreateSpokenLanguageIdentification(
2992
+ const SherpaOnnxSpokenLanguageIdentificationConfig *config);
2993
+
2994
+ /**
2995
+ * @brief Destroy a spoken-language identifier.
2996
+ *
2997
+ * @param slid A pointer returned by
2998
+ * SherpaOnnxCreateSpokenLanguageIdentification().
2999
+ * @see SherpaOnnxCreateSpokenLanguageIdentification
3000
+ */
3001
+ SHERPA_ONNX_API void SherpaOnnxDestroySpokenLanguageIdentification(
3002
+ const SherpaOnnxSpokenLanguageIdentification *slid);
3003
+
3004
+ /**
3005
+ * @brief Create an offline stream for spoken-language identification.
3006
+ *
3007
+ * Feed audio to the returned stream with SherpaOnnxAcceptWaveformOffline(), and
3008
+ * then call SherpaOnnxSpokenLanguageIdentificationCompute().
3009
+ *
3010
+ * @param slid A pointer returned by
3011
+ * SherpaOnnxCreateSpokenLanguageIdentification().
3012
+ * @return A newly allocated offline stream. Free it with
3013
+ * SherpaOnnxDestroyOfflineStream().
3014
+ */
3015
+ SHERPA_ONNX_API SherpaOnnxOfflineStream *
3016
+ SherpaOnnxSpokenLanguageIdentificationCreateOfflineStream(
3017
+ const SherpaOnnxSpokenLanguageIdentification *slid);
3018
+
3019
+ /**
3020
+ * @brief Result of spoken-language identification.
3021
+ *
3022
+ * Free this object with SherpaOnnxDestroySpokenLanguageIdentificationResult().
3023
+ */
3024
+ typedef struct SherpaOnnxSpokenLanguageIdentificationResult {
3025
+ /**
3026
+ * Predicted language code such as `"en"`, `"de"`, `"zh"`, or `"es"`.
3027
+ */
3028
+ const char *lang;
3029
+ } SherpaOnnxSpokenLanguageIdentificationResult;
3030
+
3031
+ /**
3032
+ * @brief Run spoken-language identification on an offline stream.
3033
+ *
3034
+ * Example:
3035
+ *
3036
+ * @code
3037
+ * SherpaOnnxOfflineStream *stream =
3038
+ * SherpaOnnxSpokenLanguageIdentificationCreateOfflineStream(slid);
3039
+ * SherpaOnnxAcceptWaveformOffline(stream, wave->sample_rate, wave->samples,
3040
+ * wave->num_samples);
3041
+ * const SherpaOnnxSpokenLanguageIdentificationResult *result =
3042
+ * SherpaOnnxSpokenLanguageIdentificationCompute(slid, stream);
3043
+ * printf("lang=%s\n", result->lang);
3044
+ * SherpaOnnxDestroySpokenLanguageIdentificationResult(result);
3045
+ * SherpaOnnxDestroyOfflineStream(stream);
3046
+ * @endcode
3047
+ *
3048
+ * @param slid A pointer returned by
3049
+ * SherpaOnnxCreateSpokenLanguageIdentification().
3050
+ * @param s A pointer returned by
3051
+ * SherpaOnnxSpokenLanguageIdentificationCreateOfflineStream().
3052
+ * @return A newly allocated result object. Free it with
3053
+ * SherpaOnnxDestroySpokenLanguageIdentificationResult().
3054
+ */
3055
+ SHERPA_ONNX_API const SherpaOnnxSpokenLanguageIdentificationResult *
3056
+ SherpaOnnxSpokenLanguageIdentificationCompute(
3057
+ const SherpaOnnxSpokenLanguageIdentification *slid,
3058
+ const SherpaOnnxOfflineStream *s);
3059
+
3060
+ /**
3061
+ * @brief Destroy a spoken-language identification result.
3062
+ *
3063
+ * @param r A pointer returned by
3064
+ * SherpaOnnxSpokenLanguageIdentificationCompute().
3065
+ */
3066
+ SHERPA_ONNX_API void SherpaOnnxDestroySpokenLanguageIdentificationResult(
3067
+ const SherpaOnnxSpokenLanguageIdentificationResult *r);
3068
+
3069
+ // ============================================================
3070
+ // For speaker embedding extraction
3071
+ // ============================================================
3072
+ /**
3073
+ * @brief Configuration for speaker embedding extraction.
3074
+ *
3075
+ * Example using
3076
+ * `3dspeaker_speech_campplus_sv_zh-cn_16k-common.onnx`:
3077
+ *
3078
+ * @code
3079
+ * SherpaOnnxSpeakerEmbeddingExtractorConfig config;
3080
+ * memset(&config, 0, sizeof(config));
3081
+ * config.model = "./3dspeaker_speech_campplus_sv_zh-cn_16k-common.onnx";
3082
+ * config.num_threads = 1;
3083
+ * config.provider = "cpu";
3084
+ * @endcode
3085
+ * @see SherpaOnnxCreateSpeakerEmbeddingExtractor
3086
+ */
3087
+ typedef struct SherpaOnnxSpeakerEmbeddingExtractorConfig {
3088
+ /** Speaker embedding model file. */
3089
+ const char *model;
3090
+ /** Number of inference threads. */
3091
+ int32_t num_threads;
3092
+ /** Non-zero to print debug information. */
3093
+ int32_t debug;
3094
+ /** Execution provider such as `"cpu"`. */
3095
+ const char *provider;
3096
+ } SherpaOnnxSpeakerEmbeddingExtractorConfig;
3097
+
3098
+ /** @brief Opaque speaker embedding extractor handle. */
3099
+ typedef struct SherpaOnnxSpeakerEmbeddingExtractor
3100
+ SherpaOnnxSpeakerEmbeddingExtractor;
3101
+
3102
+ /**
3103
+ * @brief Create a speaker embedding extractor.
3104
+ *
3105
+ * @param config Speaker embedding extractor configuration.
3106
+ * @return A newly allocated extractor on success, or NULL on error. Free it
3107
+ * with SherpaOnnxDestroySpeakerEmbeddingExtractor().
3108
+ * @see SherpaOnnxSpeakerEmbeddingExtractorConfig, SherpaOnnxDestroySpeakerEmbeddingExtractor
3109
+ */
3110
+ SHERPA_ONNX_API const SherpaOnnxSpeakerEmbeddingExtractor *
3111
+ SherpaOnnxCreateSpeakerEmbeddingExtractor(
3112
+ const SherpaOnnxSpeakerEmbeddingExtractorConfig *config);
3113
+
3114
+ /**
3115
+ * @brief Destroy a speaker embedding extractor.
3116
+ *
3117
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingExtractor().
3118
+ * @see SherpaOnnxCreateSpeakerEmbeddingExtractor
3119
+ */
3120
+ SHERPA_ONNX_API void SherpaOnnxDestroySpeakerEmbeddingExtractor(
3121
+ const SherpaOnnxSpeakerEmbeddingExtractor *p);
3122
+
3123
+ /**
3124
+ * @brief Return the embedding dimension produced by the extractor.
3125
+ *
3126
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingExtractor().
3127
+ * @return Embedding dimension.
3128
+ */
3129
+ SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingExtractorDim(
3130
+ const SherpaOnnxSpeakerEmbeddingExtractor *p);
3131
+
3132
+ /**
3133
+ * @brief Create a streaming feature buffer for embedding extraction.
3134
+ *
3135
+ * Feed samples with SherpaOnnxOnlineStreamAcceptWaveform(), then call
3136
+ * SherpaOnnxSpeakerEmbeddingExtractorIsReady() and
3137
+ * SherpaOnnxSpeakerEmbeddingExtractorComputeEmbedding().
3138
+ *
3139
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingExtractor().
3140
+ * @return A newly allocated online stream. Free it with
3141
+ * SherpaOnnxDestroyOnlineStream().
3142
+ */
3143
+ SHERPA_ONNX_API const SherpaOnnxOnlineStream *
3144
+ SherpaOnnxSpeakerEmbeddingExtractorCreateStream(
3145
+ const SherpaOnnxSpeakerEmbeddingExtractor *p);
3146
+
3147
+ /**
3148
+ * @brief Check whether enough audio has been provided to compute an embedding.
3149
+ *
3150
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingExtractor().
3151
+ * @param s A pointer returned by
3152
+ * SherpaOnnxSpeakerEmbeddingExtractorCreateStream().
3153
+ * @return 1 if the stream is ready; otherwise 0.
3154
+ */
3155
+ SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingExtractorIsReady(
3156
+ const SherpaOnnxSpeakerEmbeddingExtractor *p,
3157
+ const SherpaOnnxOnlineStream *s);
3158
+
3159
+ /**
3160
+ * @brief Compute the embedding for a stream.
3161
+ *
3162
+ * The returned vector has `SherpaOnnxSpeakerEmbeddingExtractorDim(p)` elements.
3163
+ * Free it with SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding().
3164
+ *
3165
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingExtractor().
3166
+ * @param s A pointer returned by
3167
+ * SherpaOnnxSpeakerEmbeddingExtractorCreateStream().
3168
+ * @return A newly allocated embedding vector.
3169
+ *
3170
+ * @code
3171
+ * const SherpaOnnxOnlineStream *stream =
3172
+ * SherpaOnnxSpeakerEmbeddingExtractorCreateStream(ex);
3173
+ * SherpaOnnxOnlineStreamAcceptWaveform(stream, wave->sample_rate,
3174
+ * wave->samples, wave->num_samples);
3175
+ * SherpaOnnxOnlineStreamInputFinished(stream);
3176
+ * if (SherpaOnnxSpeakerEmbeddingExtractorIsReady(ex, stream)) {
3177
+ * const float *v =
3178
+ * SherpaOnnxSpeakerEmbeddingExtractorComputeEmbedding(ex, stream);
3179
+ * SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding(v);
3180
+ * }
3181
+ * SherpaOnnxDestroyOnlineStream(stream);
3182
+ * @endcode
3183
+ */
3184
+ SHERPA_ONNX_API const float *
3185
+ SherpaOnnxSpeakerEmbeddingExtractorComputeEmbedding(
3186
+ const SherpaOnnxSpeakerEmbeddingExtractor *p,
3187
+ const SherpaOnnxOnlineStream *s);
3188
+
3189
+ /**
3190
+ * @brief Destroy an embedding vector returned by
3191
+ * SherpaOnnxSpeakerEmbeddingExtractorComputeEmbedding().
3192
+ *
3193
+ * @param v A pointer returned by
3194
+ * SherpaOnnxSpeakerEmbeddingExtractorComputeEmbedding().
3195
+ */
3196
+ SHERPA_ONNX_API void SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding(
3197
+ const float *v);
3198
+
3199
+ /**
3200
+ * @brief Opaque speaker embedding manager handle.
3201
+ *
3202
+ * @see SherpaOnnxCreateSpeakerEmbeddingManager
3203
+ */
3204
+ typedef struct SherpaOnnxSpeakerEmbeddingManager
3205
+ SherpaOnnxSpeakerEmbeddingManager;
3206
+
3207
+ /**
3208
+ * @brief Create a speaker embedding manager.
3209
+ *
3210
+ * The manager stores enrolled speaker embeddings and supports speaker search
3211
+ * and verification.
3212
+ *
3213
+ * @param dim Embedding dimension. This should match
3214
+ * SherpaOnnxSpeakerEmbeddingExtractorDim().
3215
+ * @return A newly allocated manager. Free it with
3216
+ * SherpaOnnxDestroySpeakerEmbeddingManager().
3217
+ * @see SherpaOnnxDestroySpeakerEmbeddingManager
3218
+ */
3219
+ SHERPA_ONNX_API const SherpaOnnxSpeakerEmbeddingManager *
3220
+ SherpaOnnxCreateSpeakerEmbeddingManager(int32_t dim);
3221
+
3222
+ /**
3223
+ * @brief Destroy a speaker embedding manager.
3224
+ *
3225
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3226
+ * @see SherpaOnnxCreateSpeakerEmbeddingManager
3227
+ */
3228
+ SHERPA_ONNX_API void SherpaOnnxDestroySpeakerEmbeddingManager(
3229
+ const SherpaOnnxSpeakerEmbeddingManager *p);
3230
+
3231
+ /**
3232
+ * @brief Add one enrollment embedding for a speaker.
3233
+ *
3234
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3235
+ * @param name Speaker name.
3236
+ * @param v Embedding vector with exactly `dim` elements.
3237
+ * @return 1 on success; 0 on error.
3238
+ */
3239
+ SHERPA_ONNX_API int32_t
3240
+ SherpaOnnxSpeakerEmbeddingManagerAdd(const SherpaOnnxSpeakerEmbeddingManager *p,
3241
+ const char *name, const float *v);
3242
+
3243
+ /**
3244
+ * @brief Add multiple enrollment embeddings for one speaker.
3245
+ *
3246
+ * @p v is a NULL-terminated array of embedding pointers:
3247
+ * `v[0]`, `v[1]`, ..., `v[n - 1]`, followed by `v[n] == NULL`.
3248
+ *
3249
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3250
+ * @param name Speaker name.
3251
+ * @param v NULL-terminated array of embedding pointers.
3252
+ * @return 1 on success; 0 on error.
3253
+ *
3254
+ * @code
3255
+ * const float *spk1_vec[4] = {e1, e2, e3, NULL};
3256
+ * SherpaOnnxSpeakerEmbeddingManagerAddList(manager, "fangjun", spk1_vec);
3257
+ * @endcode
3258
+ */
3259
+ SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerAddList(
3260
+ const SherpaOnnxSpeakerEmbeddingManager *p, const char *name,
3261
+ const float **v);
3262
+
3263
+ /**
3264
+ * @brief Add multiple enrollment embeddings packed in one flat array.
3265
+ *
3266
+ * The input contains @p n embeddings laid out consecutively, so the total
3267
+ * array length must be `n * dim`.
3268
+ *
3269
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3270
+ * @param name Speaker name.
3271
+ * @param v Flattened embedding array.
3272
+ * @param n Number of embeddings in @p v.
3273
+ * @return 1 on success; 0 on error.
3274
+ */
3275
+ SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerAddListFlattened(
3276
+ const SherpaOnnxSpeakerEmbeddingManager *p, const char *name,
3277
+ const float *v, int32_t n);
3278
+
3279
+ /**
3280
+ * @brief Remove a speaker from the manager.
3281
+ *
3282
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3283
+ * @param name Speaker name to remove.
3284
+ * @return 1 if removed; otherwise 0. Returns 0 if the speaker does not exist.
3285
+ */
3286
+ SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerRemove(
3287
+ const SherpaOnnxSpeakerEmbeddingManager *p, const char *name);
3288
+
3289
+ /**
3290
+ * @brief Search for the best matching enrolled speaker.
3291
+ *
3292
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3293
+ * @param v Query embedding vector.
3294
+ * @param threshold Minimum similarity threshold in the range [0, 1].
3295
+ * @return A newly allocated speaker name on match, or NULL if no speaker
3296
+ * passes the threshold. Free the returned name with
3297
+ * SherpaOnnxSpeakerEmbeddingManagerFreeSearch().
3298
+ */
3299
+ SHERPA_ONNX_API const char *SherpaOnnxSpeakerEmbeddingManagerSearch(
3300
+ const SherpaOnnxSpeakerEmbeddingManager *p, const float *v,
3301
+ float threshold);
3302
+
3303
+ /**
3304
+ * @brief Free a string returned by SherpaOnnxSpeakerEmbeddingManagerSearch().
3305
+ *
3306
+ * @param name A pointer returned by
3307
+ * SherpaOnnxSpeakerEmbeddingManagerSearch().
3308
+ */
3309
+ SHERPA_ONNX_API void SherpaOnnxSpeakerEmbeddingManagerFreeSearch(
3310
+ const char *name);
3311
+
3312
+ /**
3313
+ * @brief One speaker match returned by the best-matches API.
3314
+ */
3315
+ typedef struct SherpaOnnxSpeakerEmbeddingManagerSpeakerMatch {
3316
+ /** Similarity score. Larger means more similar. */
3317
+ float score;
3318
+ /** Speaker name. */
3319
+ const char *name;
3320
+ } SherpaOnnxSpeakerEmbeddingManagerSpeakerMatch;
3321
+
3322
+ /**
3323
+ * @brief Collection of best speaker matches.
3324
+ *
3325
+ * Free this object with SherpaOnnxSpeakerEmbeddingManagerFreeBestMatches().
3326
+ */
3327
+ typedef struct SherpaOnnxSpeakerEmbeddingManagerBestMatchesResult {
3328
+ /** Pointer to an array of @c count matches. */
3329
+ const SherpaOnnxSpeakerEmbeddingManagerSpeakerMatch *matches;
3330
+ /** Number of valid entries in @c matches. */
3331
+ int32_t count;
3332
+ } SherpaOnnxSpeakerEmbeddingManagerBestMatchesResult;
3333
+
3334
+ /**
3335
+ * @brief Return up to @p n best matches above a similarity threshold.
3336
+ *
3337
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3338
+ * @param v Query embedding vector.
3339
+ * @param threshold Minimum similarity threshold in the range [0, 1].
3340
+ * @param n Maximum number of matches to return.
3341
+ * @return A newly allocated result object, or NULL if no matches are found.
3342
+ * Free it with SherpaOnnxSpeakerEmbeddingManagerFreeBestMatches().
3343
+ */
3344
+ SHERPA_ONNX_API const SherpaOnnxSpeakerEmbeddingManagerBestMatchesResult *
3345
+ SherpaOnnxSpeakerEmbeddingManagerGetBestMatches(
3346
+ const SherpaOnnxSpeakerEmbeddingManager *p, const float *v, float threshold,
3347
+ int32_t n);
3348
+
3349
+ /**
3350
+ * @brief Destroy a best-matches result.
3351
+ *
3352
+ * @param r A pointer returned by
3353
+ * SherpaOnnxSpeakerEmbeddingManagerGetBestMatches().
3354
+ */
3355
+ SHERPA_ONNX_API void SherpaOnnxSpeakerEmbeddingManagerFreeBestMatches(
3356
+ const SherpaOnnxSpeakerEmbeddingManagerBestMatchesResult *r);
3357
+
3358
+ /**
3359
+ * @brief Verify whether a query embedding matches a named speaker.
3360
+ *
3361
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3362
+ * @param name Speaker name to compare against.
3363
+ * @param v Query embedding vector.
3364
+ * @param threshold Minimum similarity threshold in the range [0, 1].
3365
+ * @return 1 if the speaker matches; otherwise 0.
3366
+ */
3367
+ SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerVerify(
3368
+ const SherpaOnnxSpeakerEmbeddingManager *p, const char *name,
3369
+ const float *v, float threshold);
3370
+
3371
+ /**
3372
+ * @brief Check whether a speaker is enrolled.
3373
+ *
3374
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3375
+ * @param name Speaker name.
3376
+ * @return 1 if the speaker exists; otherwise 0.
3377
+ */
3378
+ SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerContains(
3379
+ const SherpaOnnxSpeakerEmbeddingManager *p, const char *name);
3380
+
3381
+ /**
3382
+ * @brief Return the number of enrolled speakers.
3383
+ *
3384
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3385
+ * @return Number of enrolled speakers.
3386
+ */
3387
+ SHERPA_ONNX_API int32_t SherpaOnnxSpeakerEmbeddingManagerNumSpeakers(
3388
+ const SherpaOnnxSpeakerEmbeddingManager *p);
3389
+
3390
+ /**
3391
+ * @brief Return all enrolled speaker names.
3392
+ *
3393
+ * The returned array is NULL-terminated. If no speakers are enrolled, the
3394
+ * returned array still exists and its first element is NULL.
3395
+ *
3396
+ * @param p A pointer returned by SherpaOnnxCreateSpeakerEmbeddingManager().
3397
+ * @return A newly allocated NULL-terminated array of speaker names. Free it
3398
+ * with SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers().
3399
+ */
3400
+ SHERPA_ONNX_API const char *const *
3401
+ SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakers(
3402
+ const SherpaOnnxSpeakerEmbeddingManager *p);
3403
+
3404
+ /**
3405
+ * @brief Free an array returned by
3406
+ * SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakers().
3407
+ *
3408
+ * @param names A pointer returned by
3409
+ * SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakers().
3410
+ */
3411
+ SHERPA_ONNX_API void SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers(
3412
+ const char *const *names);
3413
+
3414
+ // ============================================================
3415
+ // For audio tagging
3416
+ // ============================================================
3417
+ /** @brief Zipformer audio-tagging model configuration. */
3418
+ typedef struct SherpaOnnxOfflineZipformerAudioTaggingModelConfig {
3419
+ /** Model filename. */
3420
+ const char *model;
3421
+ } SherpaOnnxOfflineZipformerAudioTaggingModelConfig;
3422
+
3423
+ /**
3424
+ * @brief Audio-tagging model configuration.
3425
+ *
3426
+ * Configure exactly one model family. If multiple model families are provided,
3427
+ * one of them will be used and the choice is implementation-defined.
3428
+ *
3429
+ * Example using
3430
+ * `sherpa-onnx-zipformer-audio-tagging-2024-04-09`:
3431
+ *
3432
+ * @code
3433
+ * SherpaOnnxAudioTaggingModelConfig model;
3434
+ * memset(&model, 0, sizeof(model));
3435
+ * model.zipformer.model =
3436
+ * "./sherpa-onnx-zipformer-audio-tagging-2024-04-09/model.int8.onnx";
3437
+ * model.num_threads = 1;
3438
+ * model.provider = "cpu";
3439
+ * @endcode
3440
+ */
3441
+ typedef struct SherpaOnnxAudioTaggingModelConfig {
3442
+ /** Zipformer model configuration. */
3443
+ SherpaOnnxOfflineZipformerAudioTaggingModelConfig zipformer;
3444
+ /** Alternative CED model file. */
3445
+ const char *ced;
3446
+ /** Number of inference threads. */
3447
+ int32_t num_threads;
3448
+ /** Non-zero to print debug information. */
3449
+ int32_t debug;
3450
+ /** Execution provider such as `"cpu"`. */
3451
+ const char *provider;
3452
+ } SherpaOnnxAudioTaggingModelConfig;
3453
+
3454
+ /**
3455
+ * @brief Configuration for audio tagging.
3456
+ *
3457
+ * @code
3458
+ * SherpaOnnxAudioTaggingConfig config;
3459
+ * memset(&config, 0, sizeof(config));
3460
+ * config.model.zipformer.model =
3461
+ * "./sherpa-onnx-zipformer-audio-tagging-2024-04-09/model.int8.onnx";
3462
+ * config.model.num_threads = 1;
3463
+ * config.model.provider = "cpu";
3464
+ * config.labels =
3465
+ * "./sherpa-onnx-zipformer-audio-tagging-2024-04-09/class_labels_indices.csv";
3466
+ * config.top_k = 5;
3467
+ * @endcode
3468
+ * @see SherpaOnnxCreateAudioTagging
3469
+ */
3470
+ typedef struct SherpaOnnxAudioTaggingConfig {
3471
+ /** Acoustic model configuration. */
3472
+ SherpaOnnxAudioTaggingModelConfig model;
3473
+ /** CSV file containing class labels. */
3474
+ const char *labels;
3475
+ /** Default number of results to return when `top_k == -1` at inference time.
3476
+ */
3477
+ int32_t top_k;
3478
+ } SherpaOnnxAudioTaggingConfig;
3479
+
3480
+ /**
3481
+ * @brief One audio-tagging prediction.
3482
+ */
3483
+ typedef struct SherpaOnnxAudioEvent {
3484
+ /** Event label. */
3485
+ const char *name;
3486
+ /** Integer label index. */
3487
+ int32_t index;
3488
+ /** Probability or confidence score. */
3489
+ float prob;
3490
+ } SherpaOnnxAudioEvent;
3491
+
3492
+ /** @brief Opaque audio tagger handle. */
3493
+ typedef struct SherpaOnnxAudioTagging SherpaOnnxAudioTagging;
3494
+
3495
+ /**
3496
+ * @brief Create an audio tagger.
3497
+ *
3498
+ * @param config Audio-tagging configuration.
3499
+ * @return A newly allocated audio tagger on success, or NULL on error. Free it
3500
+ * with SherpaOnnxDestroyAudioTagging().
3501
+ * @see SherpaOnnxAudioTaggingConfig, SherpaOnnxDestroyAudioTagging
3502
+ */
3503
+ SHERPA_ONNX_API const SherpaOnnxAudioTagging *SherpaOnnxCreateAudioTagging(
3504
+ const SherpaOnnxAudioTaggingConfig *config);
3505
+
3506
+ /**
3507
+ * @brief Destroy an audio tagger.
3508
+ *
3509
+ * @param tagger A pointer returned by SherpaOnnxCreateAudioTagging().
3510
+ * @see SherpaOnnxCreateAudioTagging
3511
+ */
3512
+ SHERPA_ONNX_API void SherpaOnnxDestroyAudioTagging(
3513
+ const SherpaOnnxAudioTagging *tagger);
3514
+
3515
+ /**
3516
+ * @brief Create an offline stream for audio tagging.
3517
+ *
3518
+ * @param tagger A pointer returned by SherpaOnnxCreateAudioTagging().
3519
+ * @return A newly allocated offline stream. Free it with
3520
+ * SherpaOnnxDestroyOfflineStream().
3521
+ */
3522
+ SHERPA_ONNX_API const SherpaOnnxOfflineStream *
3523
+ SherpaOnnxAudioTaggingCreateOfflineStream(const SherpaOnnxAudioTagging *tagger);
3524
+
3525
+ /**
3526
+ * @brief Run audio tagging on an offline stream.
3527
+ *
3528
+ * The returned array is NULL-terminated. If @p top_k is -1, the value stored in
3529
+ * `config.top_k` is used instead.
3530
+ *
3531
+ * @param tagger A pointer returned by SherpaOnnxCreateAudioTagging().
3532
+ * @param s A pointer returned by SherpaOnnxAudioTaggingCreateOfflineStream().
3533
+ * @param top_k Number of top results to return, or -1 to use the configured
3534
+ * default.
3535
+ * @return A newly allocated NULL-terminated array of result pointers ordered by
3536
+ * descending probability. Free it with
3537
+ * SherpaOnnxAudioTaggingFreeResults().
3538
+ *
3539
+ * @code
3540
+ * const SherpaOnnxAudioEvent *const *results =
3541
+ * SherpaOnnxAudioTaggingCompute(tagger, stream, 5);
3542
+ * for (int32_t i = 0; results[i] != NULL; ++i) {
3543
+ * printf("%d %.3f %s\n", results[i]->index, results[i]->prob,
3544
+ * results[i]->name);
3545
+ * }
3546
+ * SherpaOnnxAudioTaggingFreeResults(results);
3547
+ * @endcode
3548
+ */
3549
+ SHERPA_ONNX_API const SherpaOnnxAudioEvent *const *
3550
+ SherpaOnnxAudioTaggingCompute(const SherpaOnnxAudioTagging *tagger,
3551
+ const SherpaOnnxOfflineStream *s, int32_t top_k);
3552
+
3553
+ /**
3554
+ * @brief Destroy results returned by SherpaOnnxAudioTaggingCompute().
3555
+ *
3556
+ * @param p A pointer returned by SherpaOnnxAudioTaggingCompute().
3557
+ */
3558
+ SHERPA_ONNX_API void SherpaOnnxAudioTaggingFreeResults(
3559
+ const SherpaOnnxAudioEvent *const *p);
3560
+
3561
+ // ============================================================
3562
+ // For punctuation
3563
+ // ============================================================
3564
+
3565
+ /**
3566
+ * @brief Offline punctuation model configuration.
3567
+ *
3568
+ * Example:
3569
+ *
3570
+ * @code
3571
+ * SherpaOnnxOfflinePunctuationModelConfig model;
3572
+ * memset(&model, 0, sizeof(model));
3573
+ * model.ct_transformer =
3574
+ * "./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx";
3575
+ * model.num_threads = 1;
3576
+ * model.provider = "cpu";
3577
+ * @endcode
3578
+ */
3579
+ typedef struct SherpaOnnxOfflinePunctuationModelConfig {
3580
+ /** Offline punctuation model file. */
3581
+ const char *ct_transformer;
3582
+ /** Number of inference threads. */
3583
+ int32_t num_threads;
3584
+ /** Non-zero to print debug information. */
3585
+ int32_t debug;
3586
+ /** Execution provider such as `"cpu"`. */
3587
+ const char *provider;
3588
+ } SherpaOnnxOfflinePunctuationModelConfig;
3589
+
3590
+ /** @brief Configuration for offline punctuation. */
3591
+ typedef struct SherpaOnnxOfflinePunctuationConfig {
3592
+ /** Model configuration. */
3593
+ SherpaOnnxOfflinePunctuationModelConfig model;
3594
+ } SherpaOnnxOfflinePunctuationConfig;
3595
+
3596
+ /** @brief Opaque offline punctuation handle. */
3597
+ typedef struct SherpaOnnxOfflinePunctuation SherpaOnnxOfflinePunctuation;
3598
+
3599
+ /**
3600
+ * @brief Create an offline punctuation processor.
3601
+ *
3602
+ * @param config Offline punctuation configuration.
3603
+ * @return A newly allocated punctuation processor on success, or NULL on
3604
+ * error. Free it with SherpaOnnxDestroyOfflinePunctuation().
3605
+ * @see SherpaOnnxDestroyOfflinePunctuation, SherpaOfflinePunctuationAddPunct
3606
+ */
3607
+ SHERPA_ONNX_API const SherpaOnnxOfflinePunctuation *
3608
+ SherpaOnnxCreateOfflinePunctuation(
3609
+ const SherpaOnnxOfflinePunctuationConfig *config);
3610
+
3611
+ /**
3612
+ * @brief Destroy an offline punctuation processor.
3613
+ *
3614
+ * @param punct A pointer returned by SherpaOnnxCreateOfflinePunctuation().
3615
+ * @see SherpaOnnxCreateOfflinePunctuation
3616
+ */
3617
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflinePunctuation(
3618
+ const SherpaOnnxOfflinePunctuation *punct);
3619
+
3620
+ /**
3621
+ * @brief Add punctuation to a complete input text.
3622
+ *
3623
+ * @param punct A pointer returned by SherpaOnnxCreateOfflinePunctuation().
3624
+ * @param text Input text without punctuation.
3625
+ * @return A newly allocated punctuated string. Free it with
3626
+ * SherpaOfflinePunctuationFreeText().
3627
+ * @see SherpaOfflinePunctuationFreeText
3628
+ */
3629
+ SHERPA_ONNX_API const char *SherpaOfflinePunctuationAddPunct(
3630
+ const SherpaOnnxOfflinePunctuation *punct, const char *text);
3631
+
3632
+ /**
3633
+ * @brief Free a string returned by SherpaOfflinePunctuationAddPunct().
3634
+ *
3635
+ * @param text A pointer returned by SherpaOfflinePunctuationAddPunct().
3636
+ * @see SherpaOfflinePunctuationAddPunct
3637
+ */
3638
+ SHERPA_ONNX_API void SherpaOfflinePunctuationFreeText(const char *text);
3639
+
3640
+ /**
3641
+ * @brief Online punctuation model configuration.
3642
+ *
3643
+ * Example using `sherpa-onnx-online-punct-en-2024-08-06`:
3644
+ *
3645
+ * @code
3646
+ * SherpaOnnxOnlinePunctuationModelConfig model;
3647
+ * memset(&model, 0, sizeof(model));
3648
+ * model.cnn_bilstm =
3649
+ * "./sherpa-onnx-online-punct-en-2024-08-06/model.int8.onnx"; model.bpe_vocab =
3650
+ * "./sherpa-onnx-online-punct-en-2024-08-06/bpe.vocab"; model.num_threads = 1;
3651
+ * model.provider = "cpu";
3652
+ * @endcode
3653
+ */
3654
+ typedef struct SherpaOnnxOnlinePunctuationModelConfig {
3655
+ /** Online punctuation model file. */
3656
+ const char *cnn_bilstm;
3657
+ /** BPE vocabulary used by the model. */
3658
+ const char *bpe_vocab;
3659
+ /** Number of inference threads. */
3660
+ int32_t num_threads;
3661
+ /** Non-zero to print debug information. */
3662
+ int32_t debug;
3663
+ /** Execution provider such as `"cpu"`. */
3664
+ const char *provider;
3665
+ } SherpaOnnxOnlinePunctuationModelConfig;
3666
+
3667
+ /** @brief Configuration for online punctuation. */
3668
+ typedef struct SherpaOnnxOnlinePunctuationConfig {
3669
+ /** Model configuration. */
3670
+ SherpaOnnxOnlinePunctuationModelConfig model;
3671
+ } SherpaOnnxOnlinePunctuationConfig;
3672
+
3673
+ /** @brief Opaque online punctuation handle. */
3674
+ typedef struct SherpaOnnxOnlinePunctuation SherpaOnnxOnlinePunctuation;
3675
+
3676
+ /**
3677
+ * @brief Create an online punctuation processor.
3678
+ *
3679
+ * @param config Online punctuation configuration.
3680
+ * @return A newly allocated punctuation processor on success, or NULL on
3681
+ * error. Free it with SherpaOnnxDestroyOnlinePunctuation().
3682
+ */
3683
+ SHERPA_ONNX_API const SherpaOnnxOnlinePunctuation *
3684
+ SherpaOnnxCreateOnlinePunctuation(
3685
+ const SherpaOnnxOnlinePunctuationConfig *config);
3686
+
3687
+ /**
3688
+ * @brief Destroy an online punctuation processor.
3689
+ *
3690
+ * @param punctuation A pointer returned by SherpaOnnxCreateOnlinePunctuation().
3691
+ */
3692
+ SHERPA_ONNX_API void SherpaOnnxDestroyOnlinePunctuation(
3693
+ const SherpaOnnxOnlinePunctuation *punctuation);
3694
+
3695
+ /**
3696
+ * @brief Add punctuation to one text chunk using the online punctuation model.
3697
+ *
3698
+ * @param punctuation A pointer returned by SherpaOnnxCreateOnlinePunctuation().
3699
+ * @param text Input text chunk.
3700
+ * @return A newly allocated punctuated string. Free it with
3701
+ * SherpaOnnxOnlinePunctuationFreeText().
3702
+ *
3703
+ * @code
3704
+ * const char *out =
3705
+ * SherpaOnnxOnlinePunctuationAddPunct(punct,
3706
+ * "how are you i am fine thank you");
3707
+ * printf("%s\n", out);
3708
+ * SherpaOnnxOnlinePunctuationFreeText(out);
3709
+ * @endcode
3710
+ */
3711
+ SHERPA_ONNX_API const char *SherpaOnnxOnlinePunctuationAddPunct(
3712
+ const SherpaOnnxOnlinePunctuation *punctuation, const char *text);
3713
+
3714
+ /**
3715
+ * @brief Free a string returned by SherpaOnnxOnlinePunctuationAddPunct().
3716
+ *
3717
+ * @param text A pointer returned by SherpaOnnxOnlinePunctuationAddPunct().
3718
+ */
3719
+ SHERPA_ONNX_API void SherpaOnnxOnlinePunctuationFreeText(const char *text);
3720
+
3721
+ // For resampling
3722
+ /** @brief Opaque linear resampler handle. */
3723
+ typedef struct SherpaOnnxLinearResampler SherpaOnnxLinearResampler;
3724
+
3725
+ /**
3726
+ * @brief Create a linear resampler.
3727
+ *
3728
+ * If @p filter_cutoff_hz or @p num_zeros is 0, the following defaults
3729
+ * are used (same convention as alsa-play.cc):
3730
+ *
3731
+ * @code
3732
+ * float min_freq = samp_rate_in_hz < samp_rate_out_hz ? samp_rate_in_hz
3733
+ * : samp_rate_out_hz;
3734
+ * float filter_cutoff_hz = 0.99f * 0.5f * min_freq;
3735
+ * int32_t num_zeros = 6;
3736
+ * @endcode
3737
+ *
3738
+ * @param samp_rate_in_hz Input sample rate in Hz. Must be > 0.
3739
+ * @param samp_rate_out_hz Output sample rate in Hz. Must be > 0.
3740
+ * @param filter_cutoff_hz Low-pass cutoff frequency in Hz. Pass 0 to use
3741
+ * the default formula above. Must be >= 0.
3742
+ * @param num_zeros Low-pass filter width control parameter. Pass 0 to use
3743
+ * the default value of 6. Must be >= 0.
3744
+ * @return A newly allocated resampler, or nullptr on invalid input. Free it
3745
+ * with SherpaOnnxDestroyLinearResampler().
3746
+ */
3747
+ SHERPA_ONNX_API const SherpaOnnxLinearResampler *
3748
+ SherpaOnnxCreateLinearResampler(int32_t samp_rate_in_hz,
3749
+ int32_t samp_rate_out_hz,
3750
+ float filter_cutoff_hz, int32_t num_zeros);
3751
+
3752
+ /**
3753
+ * @brief Destroy a linear resampler.
3754
+ *
3755
+ * @param p A pointer returned by SherpaOnnxCreateLinearResampler().
3756
+ */
3757
+ SHERPA_ONNX_API void SherpaOnnxDestroyLinearResampler(
3758
+ const SherpaOnnxLinearResampler *p);
3759
+
3760
+ /**
3761
+ * @brief Reset a linear resampler to its initial state.
3762
+ *
3763
+ * @param p A pointer returned by SherpaOnnxCreateLinearResampler().
3764
+ */
3765
+ SHERPA_ONNX_API void SherpaOnnxLinearResamplerReset(
3766
+ const SherpaOnnxLinearResampler *p);
3767
+
3768
+ /**
3769
+ * @brief Output chunk returned by SherpaOnnxLinearResamplerResample().
3770
+ *
3771
+ * Free this object with SherpaOnnxLinearResamplerResampleFree().
3772
+ */
3773
+ typedef struct SherpaOnnxResampleOut {
3774
+ /** Output samples. */
3775
+ const float *samples;
3776
+ /** Number of output samples. */
3777
+ int32_t n;
3778
+ } SherpaOnnxResampleOut;
3779
+
3780
+ /**
3781
+ * @brief Resample one chunk of input audio.
3782
+ *
3783
+ * Set @p flush to 1 for the final chunk so buffered samples are emitted.
3784
+ *
3785
+ * @param p A pointer returned by SherpaOnnxCreateLinearResampler().
3786
+ * @param input Input sample array.
3787
+ * @param input_dim Number of input samples.
3788
+ * @param flush 1 if this is the final chunk; otherwise 0.
3789
+ * @return A newly allocated output chunk. Free it with
3790
+ * SherpaOnnxLinearResamplerResampleFree().
3791
+ */
3792
+ SHERPA_ONNX_API const SherpaOnnxResampleOut *SherpaOnnxLinearResamplerResample(
3793
+ const SherpaOnnxLinearResampler *p, const float *input, int32_t input_dim,
3794
+ int32_t flush);
3795
+
3796
+ /**
3797
+ * @brief Destroy a resampler output chunk.
3798
+ *
3799
+ * @param p A pointer returned by SherpaOnnxLinearResamplerResample().
3800
+ */
3801
+ SHERPA_ONNX_API void SherpaOnnxLinearResamplerResampleFree(
3802
+ const SherpaOnnxResampleOut *p);
3803
+
3804
+ /**
3805
+ * @brief Return the resampler input sample rate.
3806
+ *
3807
+ * @param p A pointer returned by SherpaOnnxCreateLinearResampler().
3808
+ * @return Input sample rate in Hz.
3809
+ */
3810
+ SHERPA_ONNX_API int32_t SherpaOnnxLinearResamplerResampleGetInputSampleRate(
3811
+ const SherpaOnnxLinearResampler *p);
3812
+
3813
+ /**
3814
+ * @brief Return the resampler output sample rate.
3815
+ *
3816
+ * @param p A pointer returned by SherpaOnnxCreateLinearResampler().
3817
+ * @return Output sample rate in Hz.
3818
+ */
3819
+ SHERPA_ONNX_API int32_t SherpaOnnxLinearResamplerResampleGetOutputSampleRate(
3820
+ const SherpaOnnxLinearResampler *p);
3821
+
3822
+ // =========================================================================
3823
+ // For offline speaker diarization (i.e., non-streaming speaker diarization)
3824
+ // =========================================================================
3825
+ /** @brief Pyannote speaker-segmentation model configuration. */
3826
+ typedef struct SherpaOnnxOfflineSpeakerSegmentationPyannoteModelConfig {
3827
+ /** Segmentation model filename. */
3828
+ const char *model;
3829
+ } SherpaOnnxOfflineSpeakerSegmentationPyannoteModelConfig;
3830
+
3831
+ /**
3832
+ * @brief Segmentation model configuration for offline speaker diarization.
3833
+ *
3834
+ * Configure exactly one model family. If multiple model families are provided,
3835
+ * one is chosen and the choice is implementation-defined.
3836
+ */
3837
+ typedef struct SherpaOnnxOfflineSpeakerSegmentationModelConfig {
3838
+ /** Pyannote segmentation model configuration. */
3839
+ SherpaOnnxOfflineSpeakerSegmentationPyannoteModelConfig pyannote;
3840
+ /** Number of inference threads. */
3841
+ int32_t num_threads;
3842
+ /** Non-zero to print debug information. */
3843
+ int32_t debug;
3844
+ /** Execution provider such as `"cpu"`. */
3845
+ const char *provider;
3846
+ } SherpaOnnxOfflineSpeakerSegmentationModelConfig;
3847
+
3848
+ /**
3849
+ * @brief Fast clustering configuration.
3850
+ *
3851
+ * If @c num_clusters is greater than 0, @c threshold is ignored. When the
3852
+ * number of speakers is known in advance, setting @c num_clusters is strongly
3853
+ * recommended.
3854
+ */
3855
+ typedef struct SherpaOnnxFastClusteringConfig {
3856
+ /** Known number of speakers. If > 0, threshold-based clustering is bypassed.
3857
+ */
3858
+ int32_t num_clusters;
3859
+ /** Distance threshold used when the number of speakers is unknown. */
3860
+ float threshold;
3861
+ } SherpaOnnxFastClusteringConfig;
3862
+
3863
+ /**
3864
+ * @brief Configuration for offline speaker diarization.
3865
+ *
3866
+ * Example based on `offline-sepaker-diarization-c-api.c`:
3867
+ *
3868
+ * @code
3869
+ * SherpaOnnxOfflineSpeakerDiarizationConfig config;
3870
+ * memset(&config, 0, sizeof(config));
3871
+ * config.segmentation.pyannote.model =
3872
+ * "./sherpa-onnx-pyannote-segmentation-3-0/model.onnx";
3873
+ * config.embedding.model =
3874
+ * "./3dspeaker_speech_eres2net_base_sv_zh-cn_3dspeaker_16k.onnx";
3875
+ * config.clustering.num_clusters = 4;
3876
+ * @endcode
3877
+ */
3878
+ typedef struct SherpaOnnxOfflineSpeakerDiarizationConfig {
3879
+ /** Speaker segmentation model configuration. */
3880
+ SherpaOnnxOfflineSpeakerSegmentationModelConfig segmentation;
3881
+ /** Speaker embedding extractor configuration. */
3882
+ SherpaOnnxSpeakerEmbeddingExtractorConfig embedding;
3883
+ /** Clustering configuration. */
3884
+ SherpaOnnxFastClusteringConfig clustering;
3885
+ /** Segments shorter than this duration in seconds are discarded. */
3886
+ float min_duration_on;
3887
+ /** Small gaps shorter than this duration in seconds may be merged. */
3888
+ float min_duration_off;
3889
+ } SherpaOnnxOfflineSpeakerDiarizationConfig;
3890
+
3891
+ /** @brief Opaque offline speaker diarization handle. */
3892
+ typedef struct SherpaOnnxOfflineSpeakerDiarization
3893
+ SherpaOnnxOfflineSpeakerDiarization;
3894
+
3895
+ /**
3896
+ * @brief Create an offline speaker diarization pipeline.
3897
+ *
3898
+ * @param config Offline speaker diarization configuration.
3899
+ * @return A newly allocated diarizer on success, or NULL on error. Free it
3900
+ * with SherpaOnnxDestroyOfflineSpeakerDiarization().
3901
+ * @see SherpaOnnxDestroyOfflineSpeakerDiarization
3902
+ */
3903
+ SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarization *
3904
+ SherpaOnnxCreateOfflineSpeakerDiarization(
3905
+ const SherpaOnnxOfflineSpeakerDiarizationConfig *config);
3906
+
3907
+ /**
3908
+ * @brief Destroy an offline speaker diarizer.
3909
+ *
3910
+ * @param sd A pointer returned by SherpaOnnxCreateOfflineSpeakerDiarization().
3911
+ * @see SherpaOnnxCreateOfflineSpeakerDiarization
3912
+ */
3913
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineSpeakerDiarization(
3914
+ const SherpaOnnxOfflineSpeakerDiarization *sd);
3915
+
3916
+ /**
3917
+ * @brief Return the expected input sample rate.
3918
+ *
3919
+ * @param sd A pointer returned by SherpaOnnxCreateOfflineSpeakerDiarization().
3920
+ * @return Required input sample rate in Hz.
3921
+ */
3922
+ SHERPA_ONNX_API int32_t SherpaOnnxOfflineSpeakerDiarizationGetSampleRate(
3923
+ const SherpaOnnxOfflineSpeakerDiarization *sd);
3924
+
3925
+ /**
3926
+ * @brief Update clustering-related settings of an existing diarizer.
3927
+ *
3928
+ * Only `config->clustering` is used. Other fields are ignored.
3929
+ *
3930
+ * @param sd A pointer returned by SherpaOnnxCreateOfflineSpeakerDiarization().
3931
+ * @param config Configuration whose `clustering` field will be applied.
3932
+ */
3933
+ SHERPA_ONNX_API void SherpaOnnxOfflineSpeakerDiarizationSetConfig(
3934
+ const SherpaOnnxOfflineSpeakerDiarization *sd,
3935
+ const SherpaOnnxOfflineSpeakerDiarizationConfig *config);
3936
+
3937
+ /** @brief Opaque offline speaker diarization result. */
3938
+ typedef struct SherpaOnnxOfflineSpeakerDiarizationResult
3939
+ SherpaOnnxOfflineSpeakerDiarizationResult;
3940
+
3941
+ /**
3942
+ * @brief One diarization segment.
3943
+ */
3944
+ typedef struct SherpaOnnxOfflineSpeakerDiarizationSegment {
3945
+ /** Segment start time in seconds. */
3946
+ float start;
3947
+ /** Segment end time in seconds. */
3948
+ float end;
3949
+ /** Speaker label, typically an integer cluster ID. */
3950
+ int32_t speaker;
3951
+ } SherpaOnnxOfflineSpeakerDiarizationSegment;
3952
+
3953
+ /**
3954
+ * @brief Return the number of speakers in a diarization result.
3955
+ *
3956
+ * @param r A pointer returned by one of the
3957
+ * SherpaOnnxOfflineSpeakerDiarizationProcess*() functions.
3958
+ * @return Number of speaker clusters.
3959
+ */
3960
+ SHERPA_ONNX_API int32_t SherpaOnnxOfflineSpeakerDiarizationResultGetNumSpeakers(
3961
+ const SherpaOnnxOfflineSpeakerDiarizationResult *r);
3962
+
3963
+ /**
3964
+ * @brief Return the number of diarization segments.
3965
+ *
3966
+ * @param r A pointer returned by one of the
3967
+ * SherpaOnnxOfflineSpeakerDiarizationProcess*() functions.
3968
+ * @return Number of segments.
3969
+ */
3970
+ SHERPA_ONNX_API int32_t SherpaOnnxOfflineSpeakerDiarizationResultGetNumSegments(
3971
+ const SherpaOnnxOfflineSpeakerDiarizationResult *r);
3972
+
3973
+ /**
3974
+ * @brief Return segments sorted by start time.
3975
+ *
3976
+ * The returned array contains exactly
3977
+ * SherpaOnnxOfflineSpeakerDiarizationResultGetNumSegments() entries.
3978
+ *
3979
+ * @param r A pointer returned by one of the
3980
+ * SherpaOnnxOfflineSpeakerDiarizationProcess*() functions.
3981
+ * @return A newly allocated segment array. Free it with
3982
+ * SherpaOnnxOfflineSpeakerDiarizationDestroySegment().
3983
+ */
3984
+ SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarizationSegment *
3985
+ SherpaOnnxOfflineSpeakerDiarizationResultSortByStartTime(
3986
+ const SherpaOnnxOfflineSpeakerDiarizationResult *r);
3987
+
3988
+ /**
3989
+ * @brief Destroy a segment array returned by
3990
+ * SherpaOnnxOfflineSpeakerDiarizationResultSortByStartTime().
3991
+ *
3992
+ * @param s A pointer returned by
3993
+ * SherpaOnnxOfflineSpeakerDiarizationResultSortByStartTime().
3994
+ */
3995
+ SHERPA_ONNX_API void SherpaOnnxOfflineSpeakerDiarizationDestroySegment(
3996
+ const SherpaOnnxOfflineSpeakerDiarizationSegment *s);
3997
+
3998
+ /**
3999
+ * @brief Progress callback for offline speaker diarization.
4000
+ *
4001
+ * The current implementation reports progress but ignores the callback's
4002
+ * return value.
4003
+ */
4004
+ typedef int32_t (*SherpaOnnxOfflineSpeakerDiarizationProgressCallback)(
4005
+ int32_t num_processed_chunks, int32_t num_total_chunks, void *arg);
4006
+
4007
+ /**
4008
+ * @brief Same as SherpaOnnxOfflineSpeakerDiarizationProgressCallback but
4009
+ * without a user pointer.
4010
+ */
4011
+ typedef int32_t (*SherpaOnnxOfflineSpeakerDiarizationProgressCallbackNoArg)(
4012
+ int32_t num_processed_chunks, int32_t num_total_chunks);
4013
+
4014
+ /**
4015
+ * @brief Run offline speaker diarization.
4016
+ *
4017
+ * @param sd A pointer returned by SherpaOnnxCreateOfflineSpeakerDiarization().
4018
+ * @param samples Input mono PCM samples normalized to [-1, 1].
4019
+ * @param n Number of input samples.
4020
+ * @return A newly allocated diarization result. Free it with
4021
+ * SherpaOnnxOfflineSpeakerDiarizationDestroyResult().
4022
+ */
4023
+ SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarizationResult *
4024
+ SherpaOnnxOfflineSpeakerDiarizationProcess(
4025
+ const SherpaOnnxOfflineSpeakerDiarization *sd, const float *samples,
4026
+ int32_t n);
4027
+
4028
+ /**
4029
+ * @brief Run offline speaker diarization with a progress callback.
4030
+ *
4031
+ * @param sd A pointer returned by SherpaOnnxCreateOfflineSpeakerDiarization().
4032
+ * @param samples Input mono PCM samples normalized to [-1, 1].
4033
+ * @param n Number of input samples.
4034
+ * @param callback Progress callback.
4035
+ * @param arg User pointer forwarded to @p callback.
4036
+ * @return A newly allocated diarization result. Free it with
4037
+ * SherpaOnnxOfflineSpeakerDiarizationDestroyResult().
4038
+ *
4039
+ * @code
4040
+ * static int32_t ProgressCallback(int32_t done, int32_t total, void *arg) {
4041
+ * fprintf(stderr, "progress %.2f%%\n", 100.0f * done / total);
4042
+ * return 0;
4043
+ * }
4044
+ * @endcode
4045
+ */
4046
+ SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarizationResult *
4047
+ SherpaOnnxOfflineSpeakerDiarizationProcessWithCallback(
4048
+ const SherpaOnnxOfflineSpeakerDiarization *sd, const float *samples,
4049
+ int32_t n, SherpaOnnxOfflineSpeakerDiarizationProgressCallback callback,
4050
+ void *arg);
4051
+
4052
+ /**
4053
+ * @brief Run offline speaker diarization with a progress callback that has no
4054
+ * user pointer.
4055
+ *
4056
+ * @param sd A pointer returned by SherpaOnnxCreateOfflineSpeakerDiarization().
4057
+ * @param samples Input mono PCM samples normalized to [-1, 1].
4058
+ * @param n Number of input samples.
4059
+ * @param callback Progress callback.
4060
+ * @return A newly allocated diarization result. Free it with
4061
+ * SherpaOnnxOfflineSpeakerDiarizationDestroyResult().
4062
+ */
4063
+ SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarizationResult *
4064
+ SherpaOnnxOfflineSpeakerDiarizationProcessWithCallbackNoArg(
4065
+ const SherpaOnnxOfflineSpeakerDiarization *sd, const float *samples,
4066
+ int32_t n,
4067
+ SherpaOnnxOfflineSpeakerDiarizationProgressCallbackNoArg callback);
4068
+
4069
+ /**
4070
+ * @brief Destroy a diarization result.
4071
+ *
4072
+ * @param r A pointer returned by one of the
4073
+ * SherpaOnnxOfflineSpeakerDiarizationProcess*() functions.
4074
+ */
4075
+ SHERPA_ONNX_API void SherpaOnnxOfflineSpeakerDiarizationDestroyResult(
4076
+ const SherpaOnnxOfflineSpeakerDiarizationResult *r);
4077
+
4078
+ // =========================================================================
4079
+ // For offline speech enhancement
4080
+ // =========================================================================
4081
+ /** @brief GTCRN offline denoiser model configuration. */
4082
+ typedef struct SherpaOnnxOfflineSpeechDenoiserGtcrnModelConfig {
4083
+ /** Model filename. */
4084
+ const char *model;
4085
+ } SherpaOnnxOfflineSpeechDenoiserGtcrnModelConfig;
4086
+
4087
+ /** @brief DPDFNet offline denoiser model configuration. */
4088
+ typedef struct SherpaOnnxOfflineSpeechDenoiserDpdfNetModelConfig {
4089
+ /** Model filename. */
4090
+ const char *model;
4091
+ } SherpaOnnxOfflineSpeechDenoiserDpdfNetModelConfig;
4092
+
4093
+ /**
4094
+ * @brief Speech denoiser model configuration shared by offline and online APIs.
4095
+ *
4096
+ * Configure exactly one model family. If multiple model families are provided,
4097
+ * one is chosen and the choice is implementation-defined.
4098
+ */
4099
+ typedef struct SherpaOnnxOfflineSpeechDenoiserModelConfig {
4100
+ /** GTCRN model configuration. */
4101
+ SherpaOnnxOfflineSpeechDenoiserGtcrnModelConfig gtcrn;
4102
+ /** Number of inference threads. */
4103
+ int32_t num_threads;
4104
+ /** Non-zero to print debug information. */
4105
+ int32_t debug;
4106
+ /** Execution provider such as `"cpu"`. */
4107
+ const char *provider;
4108
+ /** DPDFNet model configuration. */
4109
+ SherpaOnnxOfflineSpeechDenoiserDpdfNetModelConfig dpdfnet;
4110
+ } SherpaOnnxOfflineSpeechDenoiserModelConfig;
4111
+
4112
+ /** @brief Configuration for offline speech denoising. */
4113
+ typedef struct SherpaOnnxOfflineSpeechDenoiserConfig {
4114
+ /** Model configuration. */
4115
+ SherpaOnnxOfflineSpeechDenoiserModelConfig model;
4116
+ } SherpaOnnxOfflineSpeechDenoiserConfig;
4117
+
4118
+ /** @brief Opaque offline speech denoiser handle. */
4119
+ typedef struct SherpaOnnxOfflineSpeechDenoiser SherpaOnnxOfflineSpeechDenoiser;
4120
+
4121
+ /**
4122
+ * @brief Create an offline speech denoiser.
4123
+ *
4124
+ * Example using `gtcrn_simple.onnx`:
4125
+ *
4126
+ * @code
4127
+ * SherpaOnnxOfflineSpeechDenoiserConfig config;
4128
+ * memset(&config, 0, sizeof(config));
4129
+ * config.model.gtcrn.model = "./gtcrn_simple.onnx";
4130
+ * @endcode
4131
+ *
4132
+ * @param config Offline denoiser configuration.
4133
+ * @return A newly allocated denoiser on success, or NULL on error. Free it
4134
+ * with SherpaOnnxDestroyOfflineSpeechDenoiser().
4135
+ * @see SherpaOnnxDestroyOfflineSpeechDenoiser
4136
+ */
4137
+ SHERPA_ONNX_API const SherpaOnnxOfflineSpeechDenoiser *
4138
+ SherpaOnnxCreateOfflineSpeechDenoiser(
4139
+ const SherpaOnnxOfflineSpeechDenoiserConfig *config);
4140
+
4141
+ /**
4142
+ * @brief Destroy an offline speech denoiser.
4143
+ *
4144
+ * @param sd A pointer returned by SherpaOnnxCreateOfflineSpeechDenoiser().
4145
+ * @see SherpaOnnxCreateOfflineSpeechDenoiser
4146
+ */
4147
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineSpeechDenoiser(
4148
+ const SherpaOnnxOfflineSpeechDenoiser *sd);
4149
+
4150
+ /**
4151
+ * @brief Return the expected sample rate for the denoiser.
4152
+ *
4153
+ * @param sd A pointer returned by SherpaOnnxCreateOfflineSpeechDenoiser().
4154
+ * @return Required input sample rate in Hz.
4155
+ */
4156
+ SHERPA_ONNX_API int32_t SherpaOnnxOfflineSpeechDenoiserGetSampleRate(
4157
+ const SherpaOnnxOfflineSpeechDenoiser *sd);
4158
+
4159
+ /**
4160
+ * @brief Denoised audio returned by offline or online speech enhancement APIs.
4161
+ *
4162
+ * Free this object with SherpaOnnxDestroyDenoisedAudio().
4163
+ */
4164
+ typedef struct SherpaOnnxDenoisedAudio {
4165
+ /** Output samples in the range [-1, 1]. */
4166
+ const float *samples;
4167
+ /** Number of output samples. */
4168
+ int32_t n;
4169
+ /** Output sample rate in Hz. */
4170
+ int32_t sample_rate;
4171
+ } SherpaOnnxDenoisedAudio;
4172
+
4173
+ /**
4174
+ * @brief Run offline speech denoising on a complete waveform.
4175
+ *
4176
+ * @param sd A pointer returned by SherpaOnnxCreateOfflineSpeechDenoiser().
4177
+ * @param samples Input mono PCM samples normalized to [-1, 1].
4178
+ * @param n Number of input samples.
4179
+ * @param sample_rate Input sample rate in Hz.
4180
+ * @return A newly allocated denoised waveform. Free it with
4181
+ * SherpaOnnxDestroyDenoisedAudio().
4182
+ *
4183
+ * @code
4184
+ * const SherpaOnnxDenoisedAudio *denoised =
4185
+ * SherpaOnnxOfflineSpeechDenoiserRun(sd, wave->samples, wave->num_samples,
4186
+ * wave->sample_rate);
4187
+ * SherpaOnnxWriteWave(denoised->samples, denoised->n, denoised->sample_rate,
4188
+ * "./enhanced.wav");
4189
+ * SherpaOnnxDestroyDenoisedAudio(denoised);
4190
+ * @endcode
4191
+ */
4192
+ SHERPA_ONNX_API const SherpaOnnxDenoisedAudio *
4193
+ SherpaOnnxOfflineSpeechDenoiserRun(const SherpaOnnxOfflineSpeechDenoiser *sd,
4194
+ const float *samples, int32_t n,
4195
+ int32_t sample_rate);
4196
+
4197
+ /**
4198
+ * @brief Destroy denoised audio returned by a speech enhancement API.
4199
+ *
4200
+ * @param p A pointer returned by SherpaOnnxOfflineSpeechDenoiserRun(),
4201
+ * SherpaOnnxOnlineSpeechDenoiserRun(), or
4202
+ * SherpaOnnxOnlineSpeechDenoiserFlush().
4203
+ */
4204
+ SHERPA_ONNX_API void SherpaOnnxDestroyDenoisedAudio(
4205
+ const SherpaOnnxDenoisedAudio *p);
4206
+
4207
+ // =========================================================================
4208
+ // For streaming speech enhancement
4209
+ // =========================================================================
4210
+ /** @brief Configuration for streaming speech denoising. */
4211
+ typedef struct SherpaOnnxOnlineSpeechDenoiserConfig {
4212
+ /** Model configuration. */
4213
+ SherpaOnnxOfflineSpeechDenoiserModelConfig model;
4214
+ } SherpaOnnxOnlineSpeechDenoiserConfig;
4215
+
4216
+ /** @brief Opaque online speech denoiser handle. */
4217
+ typedef struct SherpaOnnxOnlineSpeechDenoiser SherpaOnnxOnlineSpeechDenoiser;
4218
+
4219
+ /**
4220
+ * @brief Create an online speech denoiser.
4221
+ *
4222
+ * @param config Online denoiser configuration.
4223
+ * @return A newly allocated denoiser on success, or NULL on error. Free it
4224
+ * with SherpaOnnxDestroyOnlineSpeechDenoiser().
4225
+ * @see SherpaOnnxDestroyOnlineSpeechDenoiser
4226
+ */
4227
+ SHERPA_ONNX_API const SherpaOnnxOnlineSpeechDenoiser *
4228
+ SherpaOnnxCreateOnlineSpeechDenoiser(
4229
+ const SherpaOnnxOnlineSpeechDenoiserConfig *config);
4230
+
4231
+ /**
4232
+ * @brief Destroy an online speech denoiser.
4233
+ *
4234
+ * @param sd A pointer returned by SherpaOnnxCreateOnlineSpeechDenoiser().
4235
+ * @see SherpaOnnxCreateOnlineSpeechDenoiser
4236
+ */
4237
+ SHERPA_ONNX_API void SherpaOnnxDestroyOnlineSpeechDenoiser(
4238
+ const SherpaOnnxOnlineSpeechDenoiser *sd);
4239
+
4240
+ /**
4241
+ * @brief Return the expected input sample rate for the online denoiser.
4242
+ *
4243
+ * @param sd A pointer returned by SherpaOnnxCreateOnlineSpeechDenoiser().
4244
+ * @return Required input sample rate in Hz.
4245
+ */
4246
+ SHERPA_ONNX_API int32_t SherpaOnnxOnlineSpeechDenoiserGetSampleRate(
4247
+ const SherpaOnnxOnlineSpeechDenoiser *sd);
4248
+
4249
+ /**
4250
+ * @brief Return the recommended chunk size in samples for streaming input.
4251
+ *
4252
+ * Example programs feed audio to the online denoiser in this chunk size.
4253
+ *
4254
+ * @param sd A pointer returned by SherpaOnnxCreateOnlineSpeechDenoiser().
4255
+ * @return Frame shift in samples.
4256
+ */
4257
+ SHERPA_ONNX_API int32_t SherpaOnnxOnlineSpeechDenoiserGetFrameShiftInSamples(
4258
+ const SherpaOnnxOnlineSpeechDenoiser *sd);
4259
+
4260
+ /**
4261
+ * @brief Process one chunk of streaming audio.
4262
+ *
4263
+ * This function is not thread-safe. It may return NULL when not enough input
4264
+ * has been accumulated to produce denoised output yet.
4265
+ *
4266
+ * @param sd A pointer returned by SherpaOnnxCreateOnlineSpeechDenoiser().
4267
+ * @param samples Input chunk normalized to [-1, 1].
4268
+ * @param n Number of input samples.
4269
+ * @param sample_rate Input sample rate in Hz.
4270
+ * @return A newly allocated denoised chunk, or NULL if no output is available
4271
+ * yet. Free non-NULL results with SherpaOnnxDestroyDenoisedAudio().
4272
+ */
4273
+ SHERPA_ONNX_API const SherpaOnnxDenoisedAudio *
4274
+ SherpaOnnxOnlineSpeechDenoiserRun(const SherpaOnnxOnlineSpeechDenoiser *sd,
4275
+ const float *samples, int32_t n,
4276
+ int32_t sample_rate);
4277
+
4278
+ /**
4279
+ * @brief Flush buffered samples and reset the online denoiser.
4280
+ *
4281
+ * This also resets the denoiser so it can be reused for a new utterance.
4282
+ *
4283
+ * @param sd A pointer returned by SherpaOnnxCreateOnlineSpeechDenoiser().
4284
+ * @return A newly allocated denoised chunk, or NULL if no buffered output
4285
+ * remains. Free non-NULL results with SherpaOnnxDestroyDenoisedAudio().
4286
+ */
4287
+ SHERPA_ONNX_API const SherpaOnnxDenoisedAudio *
4288
+ SherpaOnnxOnlineSpeechDenoiserFlush(const SherpaOnnxOnlineSpeechDenoiser *sd);
4289
+
4290
+ /**
4291
+ * @brief Reset an online denoiser so it can process a new stream.
4292
+ *
4293
+ * @param sd A pointer returned by SherpaOnnxCreateOnlineSpeechDenoiser().
4294
+ */
4295
+ SHERPA_ONNX_API void SherpaOnnxOnlineSpeechDenoiserReset(
4296
+ const SherpaOnnxOnlineSpeechDenoiser *sd);
4297
+
4298
+ // =========================================================================
4299
+ // Source separation
4300
+ // =========================================================================
4301
+
4302
+ /** @brief Spleeter source-separation model configuration. */
4303
+ typedef struct SherpaOnnxOfflineSourceSeparationSpleeterModelConfig {
4304
+ /** Path to the vocals ONNX model. */
4305
+ const char *vocals;
4306
+ /** Path to the accompaniment ONNX model. */
4307
+ const char *accompaniment;
4308
+ } SherpaOnnxOfflineSourceSeparationSpleeterModelConfig;
4309
+
4310
+ /** @brief UVR (MDX-Net) source-separation model configuration. */
4311
+ typedef struct SherpaOnnxOfflineSourceSeparationUvrModelConfig {
4312
+ /** Path to the UVR ONNX model. */
4313
+ const char *model;
4314
+ } SherpaOnnxOfflineSourceSeparationUvrModelConfig;
4315
+
4316
+ /** @brief Source-separation model configuration. */
4317
+ typedef struct SherpaOnnxOfflineSourceSeparationModelConfig {
4318
+ SherpaOnnxOfflineSourceSeparationSpleeterModelConfig spleeter;
4319
+ SherpaOnnxOfflineSourceSeparationUvrModelConfig uvr;
4320
+ int32_t num_threads;
4321
+ int32_t debug;
4322
+ const char *provider;
4323
+ } SherpaOnnxOfflineSourceSeparationModelConfig;
4324
+
4325
+ /** @brief Top-level source-separation configuration. */
4326
+ typedef struct SherpaOnnxOfflineSourceSeparationConfig {
4327
+ SherpaOnnxOfflineSourceSeparationModelConfig model;
4328
+ } SherpaOnnxOfflineSourceSeparationConfig;
4329
+
4330
+ /** @brief Opaque source-separation engine handle. */
4331
+ typedef struct SherpaOnnxOfflineSourceSeparation
4332
+ SherpaOnnxOfflineSourceSeparation;
4333
+
4334
+ /**
4335
+ * @brief Create a source-separation engine.
4336
+ *
4337
+ * @param config Source-separation configuration.
4338
+ * @return A newly allocated engine on success, or NULL on error. Free it
4339
+ * with SherpaOnnxDestroyOfflineSourceSeparation().
4340
+ * @see SherpaOnnxDestroyOfflineSourceSeparation
4341
+ */
4342
+ SHERPA_ONNX_API const SherpaOnnxOfflineSourceSeparation *
4343
+ SherpaOnnxCreateOfflineSourceSeparation(
4344
+ const SherpaOnnxOfflineSourceSeparationConfig *config);
4345
+
4346
+ /**
4347
+ * @brief Destroy a source-separation engine.
4348
+ *
4349
+ * @param ss A pointer returned by SherpaOnnxCreateOfflineSourceSeparation().
4350
+ * @see SherpaOnnxCreateOfflineSourceSeparation
4351
+ */
4352
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineSourceSeparation(
4353
+ const SherpaOnnxOfflineSourceSeparation *ss);
4354
+
4355
+ /**
4356
+ * @brief Return the output sample rate of the source-separation engine.
4357
+ *
4358
+ * @param ss A pointer returned by SherpaOnnxCreateOfflineSourceSeparation().
4359
+ * @return Output sample rate in Hz.
4360
+ */
4361
+ SHERPA_ONNX_API int32_t SherpaOnnxOfflineSourceSeparationGetOutputSampleRate(
4362
+ const SherpaOnnxOfflineSourceSeparation *ss);
4363
+
4364
+ /**
4365
+ * @brief Return the number of stems produced by the engine.
4366
+ *
4367
+ * For Spleeter 2-stems this returns 2 (vocals + accompaniment).
4368
+ *
4369
+ * @param ss A pointer returned by SherpaOnnxCreateOfflineSourceSeparation().
4370
+ * @return Number of output stems.
4371
+ */
4372
+ SHERPA_ONNX_API int32_t SherpaOnnxOfflineSourceSeparationGetNumberOfStems(
4373
+ const SherpaOnnxOfflineSourceSeparation *ss);
4374
+
4375
+ /** @brief A single stem (one output track) with one or more channels. */
4376
+ typedef struct SherpaOnnxSourceSeparationStem {
4377
+ /** samples[c] points to the heap-allocated sample array for channel c. */
4378
+ float **samples;
4379
+ /** Number of channels in this stem. */
4380
+ int32_t num_channels;
4381
+ /** Number of samples per channel. */
4382
+ int32_t n;
4383
+ } SherpaOnnxSourceSeparationStem;
4384
+
4385
+ /** @brief Output of a source-separation run. */
4386
+ typedef struct SherpaOnnxSourceSeparationOutput {
4387
+ /** Heap-allocated array of stems (length num_stems). */
4388
+ const SherpaOnnxSourceSeparationStem *stems;
4389
+ /** Number of stems. */
4390
+ int32_t num_stems;
4391
+ /** Sample rate of every stem in Hz. */
4392
+ int32_t sample_rate;
4393
+ } SherpaOnnxSourceSeparationOutput;
4394
+
4395
+ /**
4396
+ * @brief Run source separation on multi-channel audio.
4397
+ *
4398
+ * All input channels must have the same number of samples.
4399
+ *
4400
+ * @param ss A pointer returned by
4401
+ * SherpaOnnxCreateOfflineSourceSeparation().
4402
+ * @param samples samples[c] is a float array for channel c, values in
4403
+ * [-1, 1].
4404
+ * @param num_channels Number of input channels.
4405
+ * @param num_samples Number of samples per channel (all channels must have
4406
+ * the same length).
4407
+ * @param sample_rate Input sample rate in Hz.
4408
+ * @return A newly allocated output on success, or NULL on error. Free it
4409
+ * with SherpaOnnxDestroySourceSeparationOutput().
4410
+ */
4411
+ SHERPA_ONNX_API const SherpaOnnxSourceSeparationOutput *
4412
+ SherpaOnnxOfflineSourceSeparationProcess(
4413
+ const SherpaOnnxOfflineSourceSeparation *ss, const float *const *samples,
4414
+ int32_t num_channels, int32_t num_samples, int32_t sample_rate);
4415
+
4416
+ /**
4417
+ * @brief Destroy the output of a source-separation run.
4418
+ *
4419
+ * @param p A pointer returned by SherpaOnnxOfflineSourceSeparationProcess().
4420
+ */
4421
+ SHERPA_ONNX_API void SherpaOnnxDestroySourceSeparationOutput(
4422
+ const SherpaOnnxSourceSeparationOutput *p);
4423
+
4424
+ #ifdef __OHOS__
4425
+
4426
+ /**
4427
+ * @brief HarmonyOS native resource manager type.
4428
+ *
4429
+ * Pass the resource manager provided by the HarmonyOS application runtime when
4430
+ * using the `*OHOS()` constructors below.
4431
+ */
4432
+ typedef struct NativeResourceManager NativeResourceManager;
4433
+
4434
+ /**
4435
+ * @brief Create an offline speech denoiser on HarmonyOS.
4436
+ *
4437
+ * This is the HarmonyOS counterpart of SherpaOnnxCreateOfflineSpeechDenoiser().
4438
+ *
4439
+ * @param config Offline denoiser configuration.
4440
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4441
+ * @return A newly allocated denoiser, or NULL on error. Free it with
4442
+ * SherpaOnnxDestroyOfflineSpeechDenoiser().
4443
+ */
4444
+ SHERPA_ONNX_API const SherpaOnnxOfflineSpeechDenoiser *
4445
+ SherpaOnnxCreateOfflineSpeechDenoiserOHOS(
4446
+ const SherpaOnnxOfflineSpeechDenoiserConfig *config,
4447
+ NativeResourceManager *mgr);
4448
+
4449
+ /**
4450
+ * @brief Create an online speech denoiser on HarmonyOS.
4451
+ *
4452
+ * This is the HarmonyOS counterpart of SherpaOnnxCreateOnlineSpeechDenoiser().
4453
+ *
4454
+ * @param config Online denoiser configuration.
4455
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4456
+ * @return A newly allocated denoiser, or NULL on error. Free it with
4457
+ * SherpaOnnxDestroyOnlineSpeechDenoiser().
4458
+ */
4459
+ SHERPA_ONNX_API const SherpaOnnxOnlineSpeechDenoiser *
4460
+ SherpaOnnxCreateOnlineSpeechDenoiserOHOS(
4461
+ const SherpaOnnxOnlineSpeechDenoiserConfig *config,
4462
+ NativeResourceManager *mgr);
4463
+
4464
+ /**
4465
+ * @brief Create an online recognizer on HarmonyOS.
4466
+ *
4467
+ * This is the HarmonyOS counterpart of SherpaOnnxCreateOnlineRecognizer().
4468
+ *
4469
+ * @param config Recognizer configuration.
4470
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4471
+ * @return A newly allocated recognizer, or NULL on error. Free it with
4472
+ * SherpaOnnxDestroyOnlineRecognizer().
4473
+ */
4474
+ SHERPA_ONNX_API const SherpaOnnxOnlineRecognizer *
4475
+ SherpaOnnxCreateOnlineRecognizerOHOS(
4476
+ const SherpaOnnxOnlineRecognizerConfig *config, NativeResourceManager *mgr);
4477
+
4478
+ /**
4479
+ * @brief Create an offline recognizer on HarmonyOS.
4480
+ *
4481
+ * This is the HarmonyOS counterpart of SherpaOnnxCreateOfflineRecognizer().
4482
+ *
4483
+ * @param config Recognizer configuration.
4484
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4485
+ * @return A newly allocated recognizer, or NULL on error. Free it with
4486
+ * SherpaOnnxDestroyOfflineRecognizer().
4487
+ */
4488
+ SHERPA_ONNX_API const SherpaOnnxOfflineRecognizer *
4489
+ SherpaOnnxCreateOfflineRecognizerOHOS(
4490
+ const SherpaOnnxOfflineRecognizerConfig *config,
4491
+ NativeResourceManager *mgr);
4492
+
4493
+ /**
4494
+ * @brief Create a voice activity detector on HarmonyOS.
4495
+ *
4496
+ * This is the HarmonyOS counterpart of SherpaOnnxCreateVoiceActivityDetector().
4497
+ *
4498
+ * @param config VAD model configuration.
4499
+ * @param buffer_size_in_seconds Internal buffer duration in seconds.
4500
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4501
+ * @return A newly allocated VAD instance, or NULL on error. Free it with
4502
+ * SherpaOnnxDestroyVoiceActivityDetector().
4503
+ */
4504
+ SHERPA_ONNX_API const SherpaOnnxVoiceActivityDetector *
4505
+ SherpaOnnxCreateVoiceActivityDetectorOHOS(
4506
+ const SherpaOnnxVadModelConfig *config, float buffer_size_in_seconds,
4507
+ NativeResourceManager *mgr);
4508
+
4509
+ /**
4510
+ * @brief Create an offline TTS engine on HarmonyOS.
4511
+ *
4512
+ * This is the HarmonyOS counterpart of SherpaOnnxCreateOfflineTts().
4513
+ *
4514
+ * @param config Offline TTS configuration.
4515
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4516
+ * @return A newly allocated TTS engine, or NULL on error. Free it with
4517
+ * SherpaOnnxDestroyOfflineTts().
4518
+ */
4519
+ SHERPA_ONNX_API const SherpaOnnxOfflineTts *SherpaOnnxCreateOfflineTtsOHOS(
4520
+ const SherpaOnnxOfflineTtsConfig *config, NativeResourceManager *mgr);
4521
+
4522
+ /**
4523
+ * @brief Create an offline punctuation processor on HarmonyOS.
4524
+ *
4525
+ * This is the HarmonyOS counterpart of SherpaOnnxCreateOfflinePunctuation().
4526
+ *
4527
+ * @param config Offline punctuation configuration.
4528
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4529
+ * @return A newly allocated punctuation processor, or NULL on error. Free it
4530
+ * with SherpaOnnxDestroyOfflinePunctuation().
4531
+ */
4532
+ SHERPA_ONNX_API const SherpaOnnxOfflinePunctuation *
4533
+ SherpaOnnxCreateOfflinePunctuationOHOS(
4534
+ const SherpaOnnxOfflinePunctuationConfig *config,
4535
+ NativeResourceManager *mgr);
4536
+
4537
+ /**
4538
+ * @brief Create an online punctuation processor on HarmonyOS.
4539
+ *
4540
+ * This is the HarmonyOS counterpart of SherpaOnnxCreateOnlinePunctuation().
4541
+ *
4542
+ * @param config Online punctuation configuration.
4543
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4544
+ * @return A newly allocated punctuation processor, or NULL on error. Free it
4545
+ * with SherpaOnnxDestroyOnlinePunctuation().
4546
+ */
4547
+ SHERPA_ONNX_API const SherpaOnnxOnlinePunctuation *
4548
+ SherpaOnnxCreateOnlinePunctuationOHOS(
4549
+ const SherpaOnnxOnlinePunctuationConfig *config,
4550
+ NativeResourceManager *mgr);
4551
+
4552
+ /**
4553
+ * @brief Create a speaker embedding extractor on HarmonyOS.
4554
+ *
4555
+ * This is the HarmonyOS counterpart of
4556
+ * SherpaOnnxCreateSpeakerEmbeddingExtractor().
4557
+ *
4558
+ * @param config Speaker embedding extractor configuration.
4559
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4560
+ * @return A newly allocated extractor, or NULL on error. Free it with
4561
+ * SherpaOnnxDestroySpeakerEmbeddingExtractor().
4562
+ */
4563
+ SHERPA_ONNX_API const SherpaOnnxSpeakerEmbeddingExtractor *
4564
+ SherpaOnnxCreateSpeakerEmbeddingExtractorOHOS(
4565
+ const SherpaOnnxSpeakerEmbeddingExtractorConfig *config,
4566
+ NativeResourceManager *mgr);
4567
+
4568
+ /**
4569
+ * @brief Create a keyword spotter on HarmonyOS.
4570
+ *
4571
+ * This is the HarmonyOS counterpart of SherpaOnnxCreateKeywordSpotter().
4572
+ *
4573
+ * @param config Keyword spotter configuration.
4574
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4575
+ * @return A newly allocated keyword spotter, or NULL on error. Free it with
4576
+ * SherpaOnnxDestroyKeywordSpotter().
4577
+ */
4578
+ SHERPA_ONNX_API const SherpaOnnxKeywordSpotter *
4579
+ SherpaOnnxCreateKeywordSpotterOHOS(const SherpaOnnxKeywordSpotterConfig *config,
4580
+ NativeResourceManager *mgr);
4581
+
4582
+ /**
4583
+ * @brief Create an offline speaker diarizer on HarmonyOS.
4584
+ *
4585
+ * This is the HarmonyOS counterpart of
4586
+ * SherpaOnnxCreateOfflineSpeakerDiarization().
4587
+ *
4588
+ * @param config Offline speaker diarization configuration.
4589
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4590
+ * @return A newly allocated diarizer, or NULL on error. Free it with
4591
+ * SherpaOnnxDestroyOfflineSpeakerDiarization().
4592
+ */
4593
+ SHERPA_ONNX_API const SherpaOnnxOfflineSpeakerDiarization *
4594
+ SherpaOnnxCreateOfflineSpeakerDiarizationOHOS(
4595
+ const SherpaOnnxOfflineSpeakerDiarizationConfig *config,
4596
+ NativeResourceManager *mgr);
4597
+
4598
+ /**
4599
+ * @brief Create a source separation engine on HarmonyOS.
4600
+ *
4601
+ * This is the HarmonyOS counterpart of
4602
+ * SherpaOnnxCreateOfflineSourceSeparation().
4603
+ *
4604
+ * @param config Source separation configuration.
4605
+ * @param mgr HarmonyOS resource manager used to resolve bundled assets.
4606
+ * @return A newly allocated source separation engine, or NULL on error. Free it
4607
+ * with SherpaOnnxDestroyOfflineSourceSeparation().
4608
+ */
4609
+ SHERPA_ONNX_API const SherpaOnnxOfflineSourceSeparation *
4610
+ SherpaOnnxCreateOfflineSourceSeparationOHOS(
4611
+ const SherpaOnnxOfflineSourceSeparationConfig *config,
4612
+ NativeResourceManager *mgr);
4613
+ #endif
4614
+
4615
+ // ============================================================
4616
+ // For diacritization
4617
+ // ============================================================
4618
+
4619
+ /**
4620
+ * @brief Offline diacritization model configuration.
4621
+ */
4622
+ typedef struct SherpaOnnxOfflineDiacritizationModelConfig {
4623
+ /** Offline diacritization encoder model file. */
4624
+ const char *catt_encoder;
4625
+ /** Offline diacritization decoder model file. */
4626
+ const char *catt_decoder;
4627
+ /** Number of inference threads. */
4628
+ int32_t num_threads;
4629
+ /** Non-zero to print debug information. */
4630
+ int32_t debug;
4631
+ /** Execution provider such as `"cpu"`. */
4632
+ const char *provider;
4633
+ } SherpaOnnxOfflineDiacritizationModelConfig;
4634
+
4635
+ /** @brief Configuration for offline diacritization. */
4636
+ typedef struct SherpaOnnxOfflineDiacritizationConfig {
4637
+ /** Model configuration. */
4638
+ SherpaOnnxOfflineDiacritizationModelConfig model;
4639
+ } SherpaOnnxOfflineDiacritizationConfig;
4640
+
4641
+ /** @brief Opaque offline diacritization handle. */
4642
+ typedef struct SherpaOnnxOfflineDiacritization SherpaOnnxOfflineDiacritization;
4643
+
4644
+ /**
4645
+ * @brief Create an offline diacritization processor.
4646
+ *
4647
+ * @param config Offline diacritization configuration.
4648
+ * @return A newly allocated diacritization processor on success, or NULL on
4649
+ * error. Free it with SherpaOnnxDestroyOfflineDiacritization().
4650
+ */
4651
+ SHERPA_ONNX_API const SherpaOnnxOfflineDiacritization *
4652
+ SherpaOnnxCreateOfflineDiacritization(
4653
+ const SherpaOnnxOfflineDiacritizationConfig *config);
4654
+
4655
+ /**
4656
+ * @brief Destroy an offline diacritization processor.
4657
+ *
4658
+ * @param diacrt A pointer returned by SherpaOnnxCreateOfflineDiacritization().
4659
+ */
4660
+ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineDiacritization(
4661
+ const SherpaOnnxOfflineDiacritization *diacrt);
4662
+
4663
+ /**
4664
+ * @brief Add diacritics to a complete input text.
4665
+ *
4666
+ * @param diacrt A pointer returned by SherpaOnnxCreateOfflineDiacritization().
4667
+ * @param text Input text without diacritics.
4668
+ * @return A newly allocated diacritized string. Free it with
4669
+ * SherpaOfflineDiacritizationFreeText().
4670
+ */
4671
+ SHERPA_ONNX_API const char *SherpaOfflineDiacritizationAddDiacritics(
4672
+ const SherpaOnnxOfflineDiacritization *diacrt, const char *text);
4673
+
4674
+ /**
4675
+ * @brief Free a string returned by SherpaOfflineDiacritizationAddDiacritics().
4676
+ *
4677
+ * @param text A pointer returned by SherpaOfflineDiacritizationAddDiacritics().
4678
+ */
4679
+ SHERPA_ONNX_API void SherpaOfflineDiacritizationFreeText(const char *text);
4680
+
4681
+ #if defined(__GNUC__)
4682
+ #pragma GCC diagnostic pop
4683
+ #endif
4684
+
4685
+ #ifdef __cplusplus
4686
+ } /* extern "C" */
4687
+ #endif
4688
+
4689
+ #endif // SHERPA_ONNX_C_API_C_API_H_