react-native-nitro-onnx 0.1.0

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 (91) hide show
  1. package/NOTICE +241 -0
  2. package/NitroOnnxSpeech.podspec +51 -0
  3. package/Package.swift +52 -0
  4. package/README.md +398 -0
  5. package/android/CMakeLists.txt +117 -0
  6. package/android/build.gradle +65 -0
  7. package/android/src/main/AndroidManifest.xml +6 -0
  8. package/android/src/main/assets/silero_vad.onnx +0 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +24 -0
  10. package/android/src/main/java/com/margelo/nitro/onnx/speech/OnnxSpeechPackage.kt +67 -0
  11. package/assets/silero_vad.onnx +0 -0
  12. package/cpp/AndroidPthreadCompat.cpp +16 -0
  13. package/cpp/AsrEngine.cpp +277 -0
  14. package/cpp/AsrEngine.hpp +110 -0
  15. package/cpp/AudioFileReader.cpp +177 -0
  16. package/cpp/AudioFileReader.hpp +26 -0
  17. package/cpp/AudioUtils.cpp +28 -0
  18. package/cpp/AudioUtils.hpp +38 -0
  19. package/cpp/ModelSingleton.hpp +51 -0
  20. package/cpp/NitroOnnxSpeech.cpp +68 -0
  21. package/cpp/NitroOnnxSpeech.hpp +42 -0
  22. package/cpp/OfflineAsr.cpp +81 -0
  23. package/cpp/OfflineAsr.hpp +33 -0
  24. package/cpp/ResourceDir.cpp +29 -0
  25. package/cpp/ResourceDir.hpp +18 -0
  26. package/cpp/SpeakerEngine.cpp +170 -0
  27. package/cpp/SpeakerEngine.hpp +70 -0
  28. package/cpp/SpeakerManager.cpp +93 -0
  29. package/cpp/SpeakerManager.hpp +43 -0
  30. package/cpp/StreamingAsr.cpp +123 -0
  31. package/cpp/StreamingAsr.hpp +55 -0
  32. package/cpp/ThreadPool.cpp +41 -0
  33. package/cpp/ThreadPool.hpp +62 -0
  34. package/cpp/Tts.cpp +132 -0
  35. package/cpp/Tts.hpp +38 -0
  36. package/cpp/TtsEngine.cpp +222 -0
  37. package/cpp/TtsEngine.hpp +77 -0
  38. package/cpp/Vad.cpp +126 -0
  39. package/cpp/Vad.hpp +62 -0
  40. package/cpp/VadEngine.cpp +217 -0
  41. package/cpp/VadEngine.hpp +126 -0
  42. package/ios/OnnxSpeechInitializer.mm +37 -0
  43. package/ios/PrivacyInfo.xcprivacy +14 -0
  44. package/lib/index.d.ts +11 -0
  45. package/lib/index.d.ts.map +1 -0
  46. package/lib/index.js +19 -0
  47. package/lib/index.js.map +1 -0
  48. package/lib/specs/OnnxSpeech.nitro.d.ts +264 -0
  49. package/lib/specs/OnnxSpeech.nitro.d.ts.map +1 -0
  50. package/lib/specs/OnnxSpeech.nitro.js +6 -0
  51. package/lib/specs/OnnxSpeech.nitro.js.map +1 -0
  52. package/nitro.json +19 -0
  53. package/nitrogen/generated/.gitattributes +1 -0
  54. package/nitrogen/generated/android/NitroOnnxSpeech+autolinking.cmake +86 -0
  55. package/nitrogen/generated/android/NitroOnnxSpeech+autolinking.gradle +27 -0
  56. package/nitrogen/generated/android/NitroOnnxSpeechOnLoad.cpp +49 -0
  57. package/nitrogen/generated/android/NitroOnnxSpeechOnLoad.hpp +34 -0
  58. package/nitrogen/generated/android/kotlin/com/margelo/nitro/onnx/speech/NitroOnnxSpeechOnLoad.kt +35 -0
  59. package/nitrogen/generated/ios/NitroOnnxSpeech+autolinking.rb +62 -0
  60. package/nitrogen/generated/ios/NitroOnnxSpeech-Swift-Cxx-Bridge.cpp +17 -0
  61. package/nitrogen/generated/ios/NitroOnnxSpeech-Swift-Cxx-Bridge.hpp +27 -0
  62. package/nitrogen/generated/ios/NitroOnnxSpeech-Swift-Cxx-Umbrella.hpp +38 -0
  63. package/nitrogen/generated/ios/NitroOnnxSpeechAutolinking.mm +35 -0
  64. package/nitrogen/generated/ios/NitroOnnxSpeechAutolinking.swift +16 -0
  65. package/nitrogen/generated/shared/c++/AsrModelConfig.hpp +142 -0
  66. package/nitrogen/generated/shared/c++/AsrModelType.hpp +112 -0
  67. package/nitrogen/generated/shared/c++/AsrResult.hpp +105 -0
  68. package/nitrogen/generated/shared/c++/HybridOfflineAsrSpec.cpp +25 -0
  69. package/nitrogen/generated/shared/c++/HybridOfflineAsrSpec.hpp +73 -0
  70. package/nitrogen/generated/shared/c++/HybridOnnxSpeechSpec.cpp +27 -0
  71. package/nitrogen/generated/shared/c++/HybridOnnxSpeechSpec.hpp +82 -0
  72. package/nitrogen/generated/shared/c++/HybridSpeakerManagerSpec.cpp +28 -0
  73. package/nitrogen/generated/shared/c++/HybridSpeakerManagerSpec.hpp +77 -0
  74. package/nitrogen/generated/shared/c++/HybridStreamingAsrSpec.cpp +32 -0
  75. package/nitrogen/generated/shared/c++/HybridStreamingAsrSpec.hpp +81 -0
  76. package/nitrogen/generated/shared/c++/HybridTtsSpec.cpp +26 -0
  77. package/nitrogen/generated/shared/c++/HybridTtsSpec.hpp +74 -0
  78. package/nitrogen/generated/shared/c++/HybridVadSpec.cpp +31 -0
  79. package/nitrogen/generated/shared/c++/HybridVadSpec.hpp +81 -0
  80. package/nitrogen/generated/shared/c++/RegisteredSpeaker.hpp +91 -0
  81. package/nitrogen/generated/shared/c++/SpeakerEmbeddingConfig.hpp +91 -0
  82. package/nitrogen/generated/shared/c++/TtsModelConfig.hpp +178 -0
  83. package/nitrogen/generated/shared/c++/TtsModelType.hpp +88 -0
  84. package/nitrogen/generated/shared/c++/TtsResult.hpp +91 -0
  85. package/nitrogen/generated/shared/c++/VadConfig.hpp +100 -0
  86. package/nitrogen/generated/shared/c++/VadSegment.hpp +91 -0
  87. package/package.json +62 -0
  88. package/scripts/prepare-sherpa-onnx.js +236 -0
  89. package/scripts/test-cpp.js +24 -0
  90. package/src/index.ts +45 -0
  91. package/src/specs/OnnxSpeech.nitro.ts +326 -0
@@ -0,0 +1,49 @@
1
+ ///
2
+ /// NitroOnnxSpeechOnLoad.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #ifndef BUILDING_NITROONNXSPEECH_WITH_GENERATED_CMAKE_PROJECT
9
+ #error NitroOnnxSpeechOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
10
+ #endif
11
+
12
+ #include "NitroOnnxSpeechOnLoad.hpp"
13
+
14
+ #include <jni.h>
15
+ #include <fbjni/fbjni.h>
16
+ #include <NitroModules/HybridObjectRegistry.hpp>
17
+
18
+ #include "NitroOnnxSpeech.hpp"
19
+
20
+ namespace margelo::nitro::onnx::speech {
21
+
22
+ int initialize(JavaVM* vm) {
23
+ return facebook::jni::initialize(vm, []() {
24
+ ::margelo::nitro::onnx::speech::registerAllNatives();
25
+ });
26
+ }
27
+
28
+
29
+
30
+ void registerAllNatives() {
31
+ using namespace margelo::nitro;
32
+ using namespace margelo::nitro::onnx::speech;
33
+
34
+ // Register native JNI methods
35
+
36
+
37
+ // Register Nitro Hybrid Objects
38
+ HybridObjectRegistry::registerHybridObjectConstructor(
39
+ "NitroOnnxSpeech",
40
+ []() -> std::shared_ptr<HybridObject> {
41
+ static_assert(std::is_default_constructible_v<NitroOnnxSpeech>,
42
+ "The HybridObject \"NitroOnnxSpeech\" is not default-constructible! "
43
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
44
+ return std::make_shared<NitroOnnxSpeech>();
45
+ }
46
+ );
47
+ }
48
+
49
+ } // namespace margelo::nitro::onnx::speech
@@ -0,0 +1,34 @@
1
+ ///
2
+ /// NitroOnnxSpeechOnLoad.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include <jni.h>
9
+ #include <functional>
10
+ #include <NitroModules/NitroDefines.hpp>
11
+
12
+ namespace margelo::nitro::onnx::speech {
13
+
14
+ [[deprecated("Use registerNatives() instead.")]]
15
+ int initialize(JavaVM* vm);
16
+
17
+ /**
18
+ * Register the native (C++) part of NitroOnnxSpeech, and autolinks all Hybrid Objects.
19
+ * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
20
+ * inside a `facebook::jni::initialize(vm, ...)` call.
21
+ * Example:
22
+ * ```cpp (cpp-adapter.cpp)
23
+ * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
24
+ * return facebook::jni::initialize(vm, []() {
25
+ * // register all NitroOnnxSpeech HybridObjects
26
+ * margelo::nitro::onnx::speech::registerNatives();
27
+ * // any other custom registrations go here.
28
+ * });
29
+ * }
30
+ * ```
31
+ */
32
+ void registerAllNatives();
33
+
34
+ } // namespace margelo::nitro::onnx::speech
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// NitroOnnxSpeechOnLoad.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.onnx.speech
9
+
10
+ import android.util.Log
11
+
12
+ internal class NitroOnnxSpeechOnLoad {
13
+ companion object {
14
+ private const val TAG = "NitroOnnxSpeechOnLoad"
15
+ private var didLoad = false
16
+ /**
17
+ * Initializes the native part of "NitroOnnxSpeech".
18
+ * This method is idempotent and can be called more than once.
19
+ */
20
+ @JvmStatic
21
+ fun initializeNative() {
22
+ if (didLoad) return
23
+ try {
24
+ Log.i(TAG, "Loading NitroOnnxSpeech C++ library...")
25
+ System.loadLibrary("NitroOnnxSpeech")
26
+ Log.i(TAG, "Successfully loaded NitroOnnxSpeech C++ library!")
27
+ didLoad = true
28
+ } catch (e: Error) {
29
+ Log.e(TAG, "Failed to load NitroOnnxSpeech C++ library! Is it properly installed and linked? " +
30
+ "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
31
+ throw e
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,62 @@
1
+ #
2
+ # NitroOnnxSpeech+autolinking.rb
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © Marc Rousavy @ Margelo
6
+ #
7
+
8
+ # This is a Ruby script that adds all files generated by Nitrogen
9
+ # to the given podspec.
10
+ #
11
+ # To use it, add this to your .podspec:
12
+ # ```ruby
13
+ # Pod::Spec.new do |spec|
14
+ # # ...
15
+ #
16
+ # # Add all files generated by Nitrogen
17
+ # load 'nitrogen/generated/ios/NitroOnnxSpeech+autolinking.rb'
18
+ # add_nitrogen_files(spec)
19
+ # end
20
+ # ```
21
+
22
+ def add_nitrogen_files(spec)
23
+ Pod::UI.puts "[NitroModules] 🔥 NitroOnnxSpeech is boosted by nitro!"
24
+
25
+ spec.dependency "NitroModules"
26
+
27
+ current_source_files = Array(spec.attributes_hash['source_files'])
28
+ spec.source_files = current_source_files + [
29
+ # Generated cross-platform specs
30
+ "nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
31
+ # Generated bridges for the cross-platform specs
32
+ "nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
33
+ ]
34
+
35
+ current_public_header_files = Array(spec.attributes_hash['public_header_files'])
36
+ spec.public_header_files = current_public_header_files + [
37
+ # Generated specs
38
+ "nitrogen/generated/shared/**/*.{h,hpp}",
39
+ # Swift to C++ bridging helpers
40
+ "nitrogen/generated/ios/NitroOnnxSpeech-Swift-Cxx-Bridge.hpp"
41
+ ]
42
+
43
+ current_private_header_files = Array(spec.attributes_hash['private_header_files'])
44
+ spec.private_header_files = current_private_header_files + [
45
+ # iOS specific specs
46
+ "nitrogen/generated/ios/c++/**/*.{h,hpp}",
47
+ # Views are framework-specific and should be private
48
+ "nitrogen/generated/shared/**/views/**/*"
49
+ ]
50
+
51
+ current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
52
+ spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
53
+ # Use C++ 20
54
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
55
+ # Enables C++ <-> Swift interop (by default it's only ObjC)
56
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
+ # Enables stricter modular headers
58
+ "DEFINES_MODULE" => "YES",
59
+ # Disable auto-generated ObjC header for Swift (Static linkage on Xcode 26.4 breaks here)
60
+ "SWIFT_INSTALL_OBJC_HEADER" => "NO",
61
+ })
62
+ end
@@ -0,0 +1,17 @@
1
+ ///
2
+ /// NitroOnnxSpeech-Swift-Cxx-Bridge.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "NitroOnnxSpeech-Swift-Cxx-Bridge.hpp"
9
+
10
+ // Include C++ implementation defined types
11
+
12
+
13
+ namespace margelo::nitro::onnx::speech::bridge::swift {
14
+
15
+
16
+
17
+ } // namespace margelo::nitro::onnx::speech::bridge::swift
@@ -0,0 +1,27 @@
1
+ ///
2
+ /// NitroOnnxSpeech-Swift-Cxx-Bridge.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+
12
+
13
+ // Forward declarations of Swift defined types
14
+
15
+
16
+ // Include C++ defined types
17
+
18
+
19
+ /**
20
+ * Contains specialized versions of C++ templated types so they can be accessed from Swift,
21
+ * as well as helper functions to interact with those C++ types from Swift.
22
+ */
23
+ namespace margelo::nitro::onnx::speech::bridge::swift {
24
+
25
+
26
+
27
+ } // namespace margelo::nitro::onnx::speech::bridge::swift
@@ -0,0 +1,38 @@
1
+ ///
2
+ /// NitroOnnxSpeech-Swift-Cxx-Umbrella.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+
12
+
13
+ // Include C++ defined types
14
+
15
+
16
+ // C++ helpers for Swift
17
+ #include "NitroOnnxSpeech-Swift-Cxx-Bridge.hpp"
18
+
19
+ // Common C++ types used in Swift
20
+ #include <NitroModules/ArrayBufferHolder.hpp>
21
+ #include <NitroModules/AnyMapUtils.hpp>
22
+ #include <NitroModules/RuntimeError.hpp>
23
+ #include <NitroModules/DateToChronoDate.hpp>
24
+
25
+ // Forward declarations of Swift defined types
26
+
27
+
28
+ // Include Swift defined types
29
+ #if __has_include("NitroOnnxSpeech-Swift.h")
30
+ // This header is generated by Xcode/Swift on every app build.
31
+ // If it cannot be found, make sure the Swift module's name (= podspec name) is actually "NitroOnnxSpeech".
32
+ #include "NitroOnnxSpeech-Swift.h"
33
+ // Same as above, but used when building with frameworks (`use_frameworks`)
34
+ #elif __has_include(<NitroOnnxSpeech/NitroOnnxSpeech-Swift.h>)
35
+ #include <NitroOnnxSpeech/NitroOnnxSpeech-Swift.h>
36
+ #else
37
+ #error NitroOnnxSpeech's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "NitroOnnxSpeech", and try building the app first.
38
+ #endif
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// NitroOnnxSpeechAutolinking.mm
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+
11
+ #import <type_traits>
12
+
13
+ #include "NitroOnnxSpeech.hpp"
14
+
15
+ @interface NitroOnnxSpeechAutolinking : NSObject
16
+ @end
17
+
18
+ @implementation NitroOnnxSpeechAutolinking
19
+
20
+ + (void) load {
21
+ using namespace margelo::nitro;
22
+ using namespace margelo::nitro::onnx::speech;
23
+
24
+ HybridObjectRegistry::registerHybridObjectConstructor(
25
+ "NitroOnnxSpeech",
26
+ []() -> std::shared_ptr<HybridObject> {
27
+ static_assert(std::is_default_constructible_v<NitroOnnxSpeech>,
28
+ "The HybridObject \"NitroOnnxSpeech\" is not default-constructible! "
29
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
30
+ return std::make_shared<NitroOnnxSpeech>();
31
+ }
32
+ );
33
+ }
34
+
35
+ @end
@@ -0,0 +1,16 @@
1
+ ///
2
+ /// NitroOnnxSpeechAutolinking.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ // TODO: Use empty enums once Swift supports exporting them as namespaces
11
+ // See: https://github.com/swiftlang/swift/pull/83616
12
+ public final class NitroOnnxSpeechAutolinking {
13
+ public typealias bridge = margelo.nitro.onnx.speech.bridge.swift
14
+
15
+
16
+ }
@@ -0,0 +1,142 @@
1
+ ///
2
+ /// AsrModelConfig.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `AsrModelType` to properly resolve imports.
32
+ namespace margelo::nitro::onnx::speech { enum class AsrModelType; }
33
+
34
+ #include "AsrModelType.hpp"
35
+ #include <string>
36
+ #include <optional>
37
+
38
+ namespace margelo::nitro::onnx::speech {
39
+
40
+ /**
41
+ * A struct which can be represented as a JavaScript object (AsrModelConfig).
42
+ */
43
+ struct AsrModelConfig final {
44
+ public:
45
+ AsrModelType type SWIFT_PRIVATE;
46
+ std::string modelDir SWIFT_PRIVATE;
47
+ std::string tokensPath SWIFT_PRIVATE;
48
+ std::optional<std::string> whisperEncoder SWIFT_PRIVATE;
49
+ std::optional<std::string> whisperDecoder SWIFT_PRIVATE;
50
+ std::optional<std::string> encoder SWIFT_PRIVATE;
51
+ std::optional<std::string> decoder SWIFT_PRIVATE;
52
+ std::optional<std::string> joiner SWIFT_PRIVATE;
53
+ std::optional<std::string> model SWIFT_PRIVATE;
54
+ std::optional<std::string> config SWIFT_PRIVATE;
55
+ std::optional<double> numThreads SWIFT_PRIVATE;
56
+ std::optional<std::string> decodingMethod SWIFT_PRIVATE;
57
+ std::optional<double> maxActivePaths SWIFT_PRIVATE;
58
+ std::optional<std::string> language SWIFT_PRIVATE;
59
+ std::optional<bool> useItn SWIFT_PRIVATE;
60
+
61
+ public:
62
+ AsrModelConfig() = default;
63
+ explicit AsrModelConfig(AsrModelType type, std::string modelDir, std::string tokensPath, std::optional<std::string> whisperEncoder, std::optional<std::string> whisperDecoder, std::optional<std::string> encoder, std::optional<std::string> decoder, std::optional<std::string> joiner, std::optional<std::string> model, std::optional<std::string> config, std::optional<double> numThreads, std::optional<std::string> decodingMethod, std::optional<double> maxActivePaths, std::optional<std::string> language, std::optional<bool> useItn): type(type), modelDir(modelDir), tokensPath(tokensPath), whisperEncoder(whisperEncoder), whisperDecoder(whisperDecoder), encoder(encoder), decoder(decoder), joiner(joiner), model(model), config(config), numThreads(numThreads), decodingMethod(decodingMethod), maxActivePaths(maxActivePaths), language(language), useItn(useItn) {}
64
+
65
+ public:
66
+ friend bool operator==(const AsrModelConfig& lhs, const AsrModelConfig& rhs) = default;
67
+ };
68
+
69
+ } // namespace margelo::nitro::onnx::speech
70
+
71
+ namespace margelo::nitro {
72
+
73
+ // C++ AsrModelConfig <> JS AsrModelConfig (object)
74
+ template <>
75
+ struct JSIConverter<margelo::nitro::onnx::speech::AsrModelConfig> final {
76
+ static inline margelo::nitro::onnx::speech::AsrModelConfig fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
77
+ jsi::Object obj = arg.asObject(runtime);
78
+ return margelo::nitro::onnx::speech::AsrModelConfig(
79
+ JSIConverter<margelo::nitro::onnx::speech::AsrModelType>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type"))),
80
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modelDir"))),
81
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "tokensPath"))),
82
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "whisperEncoder"))),
83
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "whisperDecoder"))),
84
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "encoder"))),
85
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "decoder"))),
86
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "joiner"))),
87
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "model"))),
88
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "config"))),
89
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "numThreads"))),
90
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "decodingMethod"))),
91
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxActivePaths"))),
92
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "language"))),
93
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "useItn")))
94
+ );
95
+ }
96
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::onnx::speech::AsrModelConfig& arg) {
97
+ jsi::Object obj(runtime);
98
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "type"), JSIConverter<margelo::nitro::onnx::speech::AsrModelType>::toJSI(runtime, arg.type));
99
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "modelDir"), JSIConverter<std::string>::toJSI(runtime, arg.modelDir));
100
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "tokensPath"), JSIConverter<std::string>::toJSI(runtime, arg.tokensPath));
101
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "whisperEncoder"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.whisperEncoder));
102
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "whisperDecoder"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.whisperDecoder));
103
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "encoder"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.encoder));
104
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "decoder"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.decoder));
105
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "joiner"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.joiner));
106
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "model"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.model));
107
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "config"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.config));
108
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "numThreads"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.numThreads));
109
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "decodingMethod"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.decodingMethod));
110
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxActivePaths"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxActivePaths));
111
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "language"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.language));
112
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "useItn"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.useItn));
113
+ return obj;
114
+ }
115
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
116
+ if (!value.isObject()) {
117
+ return false;
118
+ }
119
+ jsi::Object obj = value.getObject(runtime);
120
+ if (!nitro::isPlainObject(runtime, obj)) {
121
+ return false;
122
+ }
123
+ if (!JSIConverter<margelo::nitro::onnx::speech::AsrModelType>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type")))) return false;
124
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modelDir")))) return false;
125
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "tokensPath")))) return false;
126
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "whisperEncoder")))) return false;
127
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "whisperDecoder")))) return false;
128
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "encoder")))) return false;
129
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "decoder")))) return false;
130
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "joiner")))) return false;
131
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "model")))) return false;
132
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "config")))) return false;
133
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "numThreads")))) return false;
134
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "decodingMethod")))) return false;
135
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxActivePaths")))) return false;
136
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "language")))) return false;
137
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "useItn")))) return false;
138
+ return true;
139
+ }
140
+ };
141
+
142
+ } // namespace margelo::nitro
@@ -0,0 +1,112 @@
1
+ ///
2
+ /// AsrModelType.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::onnx::speech {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (AsrModelType).
30
+ */
31
+ enum class AsrModelType {
32
+ WHISPER SWIFT_NAME(whisper) = 0,
33
+ TRANSDUCER SWIFT_NAME(transducer) = 1,
34
+ PARAFORMER SWIFT_NAME(paraformer) = 2,
35
+ ZIPFORMER SWIFT_NAME(zipformer) = 3,
36
+ CONFORMER SWIFT_NAME(conformer) = 4,
37
+ WENET SWIFT_NAME(wenet) = 5,
38
+ TELESPEECH SWIFT_NAME(telespeech) = 6,
39
+ MOONSHINE SWIFT_NAME(moonshine) = 7,
40
+ DOLPHIN SWIFT_NAME(dolphin) = 8,
41
+ NEMO SWIFT_NAME(nemo) = 9,
42
+ SENSE_VOICE SWIFT_NAME(senseVoice) = 10,
43
+ } CLOSED_ENUM;
44
+
45
+ } // namespace margelo::nitro::onnx::speech
46
+
47
+ namespace margelo::nitro {
48
+
49
+ // C++ AsrModelType <> JS AsrModelType (union)
50
+ template <>
51
+ struct JSIConverter<margelo::nitro::onnx::speech::AsrModelType> final {
52
+ static inline margelo::nitro::onnx::speech::AsrModelType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
53
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
54
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
55
+ case hashString("whisper"): return margelo::nitro::onnx::speech::AsrModelType::WHISPER;
56
+ case hashString("transducer"): return margelo::nitro::onnx::speech::AsrModelType::TRANSDUCER;
57
+ case hashString("paraformer"): return margelo::nitro::onnx::speech::AsrModelType::PARAFORMER;
58
+ case hashString("zipformer"): return margelo::nitro::onnx::speech::AsrModelType::ZIPFORMER;
59
+ case hashString("conformer"): return margelo::nitro::onnx::speech::AsrModelType::CONFORMER;
60
+ case hashString("wenet"): return margelo::nitro::onnx::speech::AsrModelType::WENET;
61
+ case hashString("telespeech"): return margelo::nitro::onnx::speech::AsrModelType::TELESPEECH;
62
+ case hashString("moonshine"): return margelo::nitro::onnx::speech::AsrModelType::MOONSHINE;
63
+ case hashString("dolphin"): return margelo::nitro::onnx::speech::AsrModelType::DOLPHIN;
64
+ case hashString("nemo"): return margelo::nitro::onnx::speech::AsrModelType::NEMO;
65
+ case hashString("sense_voice"): return margelo::nitro::onnx::speech::AsrModelType::SENSE_VOICE;
66
+ default: [[unlikely]]
67
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum AsrModelType - invalid value!");
68
+ }
69
+ }
70
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::onnx::speech::AsrModelType arg) {
71
+ switch (arg) {
72
+ case margelo::nitro::onnx::speech::AsrModelType::WHISPER: return JSIConverter<std::string>::toJSI(runtime, "whisper");
73
+ case margelo::nitro::onnx::speech::AsrModelType::TRANSDUCER: return JSIConverter<std::string>::toJSI(runtime, "transducer");
74
+ case margelo::nitro::onnx::speech::AsrModelType::PARAFORMER: return JSIConverter<std::string>::toJSI(runtime, "paraformer");
75
+ case margelo::nitro::onnx::speech::AsrModelType::ZIPFORMER: return JSIConverter<std::string>::toJSI(runtime, "zipformer");
76
+ case margelo::nitro::onnx::speech::AsrModelType::CONFORMER: return JSIConverter<std::string>::toJSI(runtime, "conformer");
77
+ case margelo::nitro::onnx::speech::AsrModelType::WENET: return JSIConverter<std::string>::toJSI(runtime, "wenet");
78
+ case margelo::nitro::onnx::speech::AsrModelType::TELESPEECH: return JSIConverter<std::string>::toJSI(runtime, "telespeech");
79
+ case margelo::nitro::onnx::speech::AsrModelType::MOONSHINE: return JSIConverter<std::string>::toJSI(runtime, "moonshine");
80
+ case margelo::nitro::onnx::speech::AsrModelType::DOLPHIN: return JSIConverter<std::string>::toJSI(runtime, "dolphin");
81
+ case margelo::nitro::onnx::speech::AsrModelType::NEMO: return JSIConverter<std::string>::toJSI(runtime, "nemo");
82
+ case margelo::nitro::onnx::speech::AsrModelType::SENSE_VOICE: return JSIConverter<std::string>::toJSI(runtime, "sense_voice");
83
+ default: [[unlikely]]
84
+ throw std::invalid_argument("Cannot convert AsrModelType to JS - invalid value: "
85
+ + std::to_string(static_cast<int>(arg)) + "!");
86
+ }
87
+ }
88
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
89
+ if (!value.isString()) {
90
+ return false;
91
+ }
92
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
93
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
94
+ case hashString("whisper"):
95
+ case hashString("transducer"):
96
+ case hashString("paraformer"):
97
+ case hashString("zipformer"):
98
+ case hashString("conformer"):
99
+ case hashString("wenet"):
100
+ case hashString("telespeech"):
101
+ case hashString("moonshine"):
102
+ case hashString("dolphin"):
103
+ case hashString("nemo"):
104
+ case hashString("sense_voice"):
105
+ return true;
106
+ default:
107
+ return false;
108
+ }
109
+ }
110
+ };
111
+
112
+ } // namespace margelo::nitro