@gmessier/nitro-speech 0.0.1
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.
- package/NitroSpeech.podspec +31 -0
- package/README.md +55 -0
- package/android/CMakeLists.txt +29 -0
- package/android/build.gradle +148 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/nitrospeech/HybridNitroSpeech.kt +12 -0
- package/android/src/main/java/com/margelo/nitro/nitrospeech/NitroSpeechPackage.kt +20 -0
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/AudioPermissionRequester.kt +39 -0
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/AutoStopper.kt +35 -0
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/HybridRecognizer.kt +181 -0
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/RecognitionListenerSession.kt +106 -0
- package/ios/AppStateObserver.swift +31 -0
- package/ios/AutoStopper.swift +57 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridNitroSpeech.swift +6 -0
- package/ios/HybridRecognizer.swift +201 -0
- package/lib/commonjs/index.js +10 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/NitroSpeech.nitro.js +6 -0
- package/lib/commonjs/specs/NitroSpeech.nitro.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/specs/NitroSpeech.nitro.js +4 -0
- package/lib/module/specs/NitroSpeech.nitro.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/specs/NitroSpeech.nitro.d.ts +108 -0
- package/lib/typescript/specs/NitroSpeech.nitro.d.ts.map +1 -0
- package/nitro.json +24 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroSpeech+autolinking.cmake +83 -0
- package/nitrogen/generated/android/NitroSpeech+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroSpeechOnLoad.cpp +54 -0
- package/nitrogen/generated/android/NitroSpeechOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_std__string_.hpp +95 -0
- package/nitrogen/generated/android/c++/JHybridNitroSpeechSpec.cpp +59 -0
- package/nitrogen/generated/android/c++/JHybridNitroSpeechSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JHybridRecognizerSpec.cpp +167 -0
- package/nitrogen/generated/android/c++/JHybridRecognizerSpec.hpp +77 -0
- package/nitrogen/generated/android/c++/JSpeechToTextParams.hpp +109 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/Func_void.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/Func_void_double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/Func_void_std__string.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/Func_void_std__vector_std__string_.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/HybridNitroSpeechSpec.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/HybridRecognizerSpec.kt +143 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/NitroSpeechOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/SpeechToTextParams.kt +62 -0
- package/nitrogen/generated/ios/NitroSpeech+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Bridge.cpp +82 -0
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Bridge.hpp +291 -0
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Umbrella.hpp +55 -0
- package/nitrogen/generated/ios/NitroSpeechAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroSpeechAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridNitroSpeechSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroSpeechSpecSwift.hpp +77 -0
- package/nitrogen/generated/ios/c++/HybridRecognizerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridRecognizerSpecSwift.hpp +126 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__string_.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridNitroSpeechSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridNitroSpeechSpec_cxx.swift +137 -0
- package/nitrogen/generated/ios/swift/HybridRecognizerSpec.swift +62 -0
- package/nitrogen/generated/ios/swift/HybridRecognizerSpec_cxx.swift +337 -0
- package/nitrogen/generated/ios/swift/SpeechToTextParams.swift +300 -0
- package/nitrogen/generated/shared/c++/HybridNitroSpeechSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridNitroSpeechSpec.hpp +65 -0
- package/nitrogen/generated/shared/c++/HybridRecognizerSpec.cpp +34 -0
- package/nitrogen/generated/shared/c++/HybridRecognizerSpec.hpp +79 -0
- package/nitrogen/generated/shared/c++/SpeechToTextParams.hpp +109 -0
- package/package.json +123 -0
- package/react-native.config.js +16 -0
- package/src/index.ts +8 -0
- package/src/specs/NitroSpeech.nitro.ts +113 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroSpeechSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `HybridRecognizerSpec` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitrospeech { class HybridRecognizerSpec; }
|
|
18
|
+
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include "HybridRecognizerSpec.hpp"
|
|
21
|
+
|
|
22
|
+
namespace margelo::nitro::nitrospeech {
|
|
23
|
+
|
|
24
|
+
using namespace margelo::nitro;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An abstract base class for `NitroSpeech`
|
|
28
|
+
* Inherit this class to create instances of `HybridNitroSpeechSpec` in C++.
|
|
29
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
30
|
+
* @example
|
|
31
|
+
* ```cpp
|
|
32
|
+
* class HybridNitroSpeech: public HybridNitroSpeechSpec {
|
|
33
|
+
* public:
|
|
34
|
+
* HybridNitroSpeech(...): HybridObject(TAG) { ... }
|
|
35
|
+
* // ...
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
class HybridNitroSpeechSpec: public virtual HybridObject {
|
|
40
|
+
public:
|
|
41
|
+
// Constructor
|
|
42
|
+
explicit HybridNitroSpeechSpec(): HybridObject(TAG) { }
|
|
43
|
+
|
|
44
|
+
// Destructor
|
|
45
|
+
~HybridNitroSpeechSpec() override = default;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
// Properties
|
|
49
|
+
virtual std::shared_ptr<HybridRecognizerSpec> getRecognizer() = 0;
|
|
50
|
+
virtual void setRecognizer(const std::shared_ptr<HybridRecognizerSpec>& recognizer) = 0;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Methods
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
protected:
|
|
57
|
+
// Hybrid Setup
|
|
58
|
+
void loadHybridMethods() override;
|
|
59
|
+
|
|
60
|
+
protected:
|
|
61
|
+
// Tag for logging
|
|
62
|
+
static constexpr auto TAG = "NitroSpeech";
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro::nitrospeech
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRecognizerSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridRecognizerSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::nitrospeech {
|
|
11
|
+
|
|
12
|
+
void HybridRecognizerSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("onReadyForSpeech", &HybridRecognizerSpec::getOnReadyForSpeech);
|
|
18
|
+
prototype.registerHybridSetter("onReadyForSpeech", &HybridRecognizerSpec::setOnReadyForSpeech);
|
|
19
|
+
prototype.registerHybridGetter("onRecordingStopped", &HybridRecognizerSpec::getOnRecordingStopped);
|
|
20
|
+
prototype.registerHybridSetter("onRecordingStopped", &HybridRecognizerSpec::setOnRecordingStopped);
|
|
21
|
+
prototype.registerHybridGetter("onResult", &HybridRecognizerSpec::getOnResult);
|
|
22
|
+
prototype.registerHybridSetter("onResult", &HybridRecognizerSpec::setOnResult);
|
|
23
|
+
prototype.registerHybridGetter("onAutoFinishProgress", &HybridRecognizerSpec::getOnAutoFinishProgress);
|
|
24
|
+
prototype.registerHybridSetter("onAutoFinishProgress", &HybridRecognizerSpec::setOnAutoFinishProgress);
|
|
25
|
+
prototype.registerHybridGetter("onError", &HybridRecognizerSpec::getOnError);
|
|
26
|
+
prototype.registerHybridSetter("onError", &HybridRecognizerSpec::setOnError);
|
|
27
|
+
prototype.registerHybridGetter("onPermissionDenied", &HybridRecognizerSpec::getOnPermissionDenied);
|
|
28
|
+
prototype.registerHybridSetter("onPermissionDenied", &HybridRecognizerSpec::setOnPermissionDenied);
|
|
29
|
+
prototype.registerHybridMethod("startListening", &HybridRecognizerSpec::startListening);
|
|
30
|
+
prototype.registerHybridMethod("stopListening", &HybridRecognizerSpec::stopListening);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
} // namespace margelo::nitro::nitrospeech
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRecognizerSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `SpeechToTextParams` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitrospeech { struct SpeechToTextParams; }
|
|
18
|
+
|
|
19
|
+
#include <functional>
|
|
20
|
+
#include <optional>
|
|
21
|
+
#include <string>
|
|
22
|
+
#include <vector>
|
|
23
|
+
#include "SpeechToTextParams.hpp"
|
|
24
|
+
|
|
25
|
+
namespace margelo::nitro::nitrospeech {
|
|
26
|
+
|
|
27
|
+
using namespace margelo::nitro;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An abstract base class for `Recognizer`
|
|
31
|
+
* Inherit this class to create instances of `HybridRecognizerSpec` in C++.
|
|
32
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
33
|
+
* @example
|
|
34
|
+
* ```cpp
|
|
35
|
+
* class HybridRecognizer: public HybridRecognizerSpec {
|
|
36
|
+
* public:
|
|
37
|
+
* HybridRecognizer(...): HybridObject(TAG) { ... }
|
|
38
|
+
* // ...
|
|
39
|
+
* };
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
class HybridRecognizerSpec: public virtual HybridObject {
|
|
43
|
+
public:
|
|
44
|
+
// Constructor
|
|
45
|
+
explicit HybridRecognizerSpec(): HybridObject(TAG) { }
|
|
46
|
+
|
|
47
|
+
// Destructor
|
|
48
|
+
~HybridRecognizerSpec() override = default;
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
// Properties
|
|
52
|
+
virtual std::optional<std::function<void()>> getOnReadyForSpeech() = 0;
|
|
53
|
+
virtual void setOnReadyForSpeech(const std::optional<std::function<void()>>& onReadyForSpeech) = 0;
|
|
54
|
+
virtual std::optional<std::function<void()>> getOnRecordingStopped() = 0;
|
|
55
|
+
virtual void setOnRecordingStopped(const std::optional<std::function<void()>>& onRecordingStopped) = 0;
|
|
56
|
+
virtual std::optional<std::function<void(const std::vector<std::string>& /* resultBatches */)>> getOnResult() = 0;
|
|
57
|
+
virtual void setOnResult(const std::optional<std::function<void(const std::vector<std::string>& /* resultBatches */)>>& onResult) = 0;
|
|
58
|
+
virtual std::optional<std::function<void(double /* timeLeftMs */)>> getOnAutoFinishProgress() = 0;
|
|
59
|
+
virtual void setOnAutoFinishProgress(const std::optional<std::function<void(double /* timeLeftMs */)>>& onAutoFinishProgress) = 0;
|
|
60
|
+
virtual std::optional<std::function<void(const std::string& /* message */)>> getOnError() = 0;
|
|
61
|
+
virtual void setOnError(const std::optional<std::function<void(const std::string& /* message */)>>& onError) = 0;
|
|
62
|
+
virtual std::optional<std::function<void()>> getOnPermissionDenied() = 0;
|
|
63
|
+
virtual void setOnPermissionDenied(const std::optional<std::function<void()>>& onPermissionDenied) = 0;
|
|
64
|
+
|
|
65
|
+
public:
|
|
66
|
+
// Methods
|
|
67
|
+
virtual void startListening(const SpeechToTextParams& params) = 0;
|
|
68
|
+
virtual void stopListening() = 0;
|
|
69
|
+
|
|
70
|
+
protected:
|
|
71
|
+
// Hybrid Setup
|
|
72
|
+
void loadHybridMethods() override;
|
|
73
|
+
|
|
74
|
+
protected:
|
|
75
|
+
// Tag for logging
|
|
76
|
+
static constexpr auto TAG = "Recognizer";
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
} // namespace margelo::nitro::nitrospeech
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// SpeechToTextParams.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 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
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#include <string>
|
|
29
|
+
#include <optional>
|
|
30
|
+
#include <vector>
|
|
31
|
+
|
|
32
|
+
namespace margelo::nitro::nitrospeech {
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A struct which can be represented as a JavaScript object (SpeechToTextParams).
|
|
36
|
+
*/
|
|
37
|
+
struct SpeechToTextParams {
|
|
38
|
+
public:
|
|
39
|
+
std::optional<std::string> locale SWIFT_PRIVATE;
|
|
40
|
+
std::optional<double> autoFinishRecognitionMs SWIFT_PRIVATE;
|
|
41
|
+
std::optional<bool> disableRepeatingFilter SWIFT_PRIVATE;
|
|
42
|
+
std::optional<std::vector<std::string>> contextualStrings SWIFT_PRIVATE;
|
|
43
|
+
std::optional<bool> androidMaskOffensiveWords SWIFT_PRIVATE;
|
|
44
|
+
std::optional<bool> androidFormattingPreferQuality SWIFT_PRIVATE;
|
|
45
|
+
std::optional<bool> androidUseWebSearchModel SWIFT_PRIVATE;
|
|
46
|
+
std::optional<bool> androidDisableBatchHandling SWIFT_PRIVATE;
|
|
47
|
+
std::optional<bool> iosAddPunctuation SWIFT_PRIVATE;
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
SpeechToTextParams() = default;
|
|
51
|
+
explicit SpeechToTextParams(std::optional<std::string> locale, std::optional<double> autoFinishRecognitionMs, std::optional<bool> disableRepeatingFilter, std::optional<std::vector<std::string>> contextualStrings, std::optional<bool> androidMaskOffensiveWords, std::optional<bool> androidFormattingPreferQuality, std::optional<bool> androidUseWebSearchModel, std::optional<bool> androidDisableBatchHandling, std::optional<bool> iosAddPunctuation): locale(locale), autoFinishRecognitionMs(autoFinishRecognitionMs), disableRepeatingFilter(disableRepeatingFilter), contextualStrings(contextualStrings), androidMaskOffensiveWords(androidMaskOffensiveWords), androidFormattingPreferQuality(androidFormattingPreferQuality), androidUseWebSearchModel(androidUseWebSearchModel), androidDisableBatchHandling(androidDisableBatchHandling), iosAddPunctuation(iosAddPunctuation) {}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
} // namespace margelo::nitro::nitrospeech
|
|
55
|
+
|
|
56
|
+
namespace margelo::nitro {
|
|
57
|
+
|
|
58
|
+
// C++ SpeechToTextParams <> JS SpeechToTextParams (object)
|
|
59
|
+
template <>
|
|
60
|
+
struct JSIConverter<margelo::nitro::nitrospeech::SpeechToTextParams> final {
|
|
61
|
+
static inline margelo::nitro::nitrospeech::SpeechToTextParams fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
62
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
63
|
+
return margelo::nitro::nitrospeech::SpeechToTextParams(
|
|
64
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "locale")),
|
|
65
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "autoFinishRecognitionMs")),
|
|
66
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "disableRepeatingFilter")),
|
|
67
|
+
JSIConverter<std::optional<std::vector<std::string>>>::fromJSI(runtime, obj.getProperty(runtime, "contextualStrings")),
|
|
68
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "androidMaskOffensiveWords")),
|
|
69
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "androidFormattingPreferQuality")),
|
|
70
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "androidUseWebSearchModel")),
|
|
71
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "androidDisableBatchHandling")),
|
|
72
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "iosAddPunctuation"))
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrospeech::SpeechToTextParams& arg) {
|
|
76
|
+
jsi::Object obj(runtime);
|
|
77
|
+
obj.setProperty(runtime, "locale", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.locale));
|
|
78
|
+
obj.setProperty(runtime, "autoFinishRecognitionMs", JSIConverter<std::optional<double>>::toJSI(runtime, arg.autoFinishRecognitionMs));
|
|
79
|
+
obj.setProperty(runtime, "disableRepeatingFilter", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.disableRepeatingFilter));
|
|
80
|
+
obj.setProperty(runtime, "contextualStrings", JSIConverter<std::optional<std::vector<std::string>>>::toJSI(runtime, arg.contextualStrings));
|
|
81
|
+
obj.setProperty(runtime, "androidMaskOffensiveWords", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.androidMaskOffensiveWords));
|
|
82
|
+
obj.setProperty(runtime, "androidFormattingPreferQuality", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.androidFormattingPreferQuality));
|
|
83
|
+
obj.setProperty(runtime, "androidUseWebSearchModel", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.androidUseWebSearchModel));
|
|
84
|
+
obj.setProperty(runtime, "androidDisableBatchHandling", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.androidDisableBatchHandling));
|
|
85
|
+
obj.setProperty(runtime, "iosAddPunctuation", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.iosAddPunctuation));
|
|
86
|
+
return obj;
|
|
87
|
+
}
|
|
88
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
89
|
+
if (!value.isObject()) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
jsi::Object obj = value.getObject(runtime);
|
|
93
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "locale"))) return false;
|
|
97
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "autoFinishRecognitionMs"))) return false;
|
|
98
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "disableRepeatingFilter"))) return false;
|
|
99
|
+
if (!JSIConverter<std::optional<std::vector<std::string>>>::canConvert(runtime, obj.getProperty(runtime, "contextualStrings"))) return false;
|
|
100
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "androidMaskOffensiveWords"))) return false;
|
|
101
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "androidFormattingPreferQuality"))) return false;
|
|
102
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "androidUseWebSearchModel"))) return false;
|
|
103
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "androidDisableBatchHandling"))) return false;
|
|
104
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "iosAddPunctuation"))) return false;
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
} // namespace margelo::nitro
|
package/package.json
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gmessier/nitro-speech",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "nitro-speech",
|
|
5
|
+
"main": "./lib/commonjs/index.js",
|
|
6
|
+
"module": "./lib/module/index.js",
|
|
7
|
+
"types": "./lib/typescript/index.d.ts",
|
|
8
|
+
"react-native": "./lib/module/index.js",
|
|
9
|
+
"source": "src/index.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"react-native.config.js",
|
|
13
|
+
"lib",
|
|
14
|
+
"nitrogen",
|
|
15
|
+
"android/build.gradle",
|
|
16
|
+
"android/gradle.properties",
|
|
17
|
+
"android/fix-prefab.gradle",
|
|
18
|
+
"android/CMakeLists.txt",
|
|
19
|
+
"android/src",
|
|
20
|
+
"ios/**/*.h",
|
|
21
|
+
"ios/**/*.m",
|
|
22
|
+
"ios/**/*.mm",
|
|
23
|
+
"ios/**/*.cpp",
|
|
24
|
+
"ios/**/*.swift",
|
|
25
|
+
"app.plugin.js",
|
|
26
|
+
"nitro.json",
|
|
27
|
+
"*.podspec",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"clean": "rm -rf android/build node_modules/**/android/build lib",
|
|
33
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
34
|
+
"lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
|
|
35
|
+
"typescript": "tsc",
|
|
36
|
+
"build": "rm -rf lib && npm run typecheck && bob build",
|
|
37
|
+
"specs": "tsc --noEmit false && nitrogen --logLevel=\"debug\""
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"react-native",
|
|
41
|
+
"nitro"
|
|
42
|
+
],
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/mrousavy/nitro.git"
|
|
46
|
+
},
|
|
47
|
+
"author": "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/mrousavy/nitro/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/mrousavy/nitro#readme",
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"registry": "https://registry.npmjs.org/"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@react-native/eslint-config": "0.82.0",
|
|
58
|
+
"@types/react": "^19.1.03",
|
|
59
|
+
"eslint": "^8.57.0",
|
|
60
|
+
"eslint-config-prettier": "^9.1.0",
|
|
61
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
62
|
+
"nitrogen": "*",
|
|
63
|
+
"prettier": "^3.3.3",
|
|
64
|
+
"react": "19.1.1",
|
|
65
|
+
"react-native": "0.82.0",
|
|
66
|
+
"react-native-nitro-modules": "*",
|
|
67
|
+
"react-native-builder-bob": "^0.37.0",
|
|
68
|
+
"typescript": "^5.8.3"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"react": "*",
|
|
72
|
+
"react-native": "*",
|
|
73
|
+
"react-native-nitro-modules": "*"
|
|
74
|
+
},
|
|
75
|
+
"eslintConfig": {
|
|
76
|
+
"root": true,
|
|
77
|
+
"extends": [
|
|
78
|
+
"@react-native",
|
|
79
|
+
"prettier"
|
|
80
|
+
],
|
|
81
|
+
"plugins": [
|
|
82
|
+
"prettier"
|
|
83
|
+
],
|
|
84
|
+
"rules": {
|
|
85
|
+
"prettier/prettier": [
|
|
86
|
+
"warn",
|
|
87
|
+
{
|
|
88
|
+
"quoteProps": "consistent",
|
|
89
|
+
"singleQuote": true,
|
|
90
|
+
"tabWidth": 2,
|
|
91
|
+
"trailingComma": "es5",
|
|
92
|
+
"useTabs": false
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"eslintIgnore": [
|
|
98
|
+
"node_modules/",
|
|
99
|
+
"lib/"
|
|
100
|
+
],
|
|
101
|
+
"prettier": {
|
|
102
|
+
"quoteProps": "consistent",
|
|
103
|
+
"singleQuote": true,
|
|
104
|
+
"tabWidth": 2,
|
|
105
|
+
"trailingComma": "es5",
|
|
106
|
+
"useTabs": false,
|
|
107
|
+
"semi": false
|
|
108
|
+
},
|
|
109
|
+
"react-native-builder-bob": {
|
|
110
|
+
"source": "src",
|
|
111
|
+
"output": "lib",
|
|
112
|
+
"targets": [
|
|
113
|
+
"commonjs",
|
|
114
|
+
"module",
|
|
115
|
+
[
|
|
116
|
+
"typescript",
|
|
117
|
+
{
|
|
118
|
+
"project": "tsconfig.json"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
dependency: {
|
|
5
|
+
platforms: {
|
|
6
|
+
/**
|
|
7
|
+
* @type {import('@react-native-community/cli-types').IOSDependencyParams}
|
|
8
|
+
*/
|
|
9
|
+
ios: {},
|
|
10
|
+
/**
|
|
11
|
+
* @type {import('@react-native-community/cli-types').AndroidDependencyParams}
|
|
12
|
+
*/
|
|
13
|
+
android: {},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
+
import type { NitroSpeech as NitroSpeechSpec } from './specs/NitroSpeech.nitro'
|
|
3
|
+
|
|
4
|
+
const NitroSpeech =
|
|
5
|
+
NitroModules.createHybridObject<NitroSpeechSpec>('NitroSpeech')
|
|
6
|
+
|
|
7
|
+
export const Recognizer = NitroSpeech.recognizer
|
|
8
|
+
export type { SpeechToTextParams } from './specs/NitroSpeech.nitro'
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type HybridObject } from 'react-native-nitro-modules'
|
|
2
|
+
|
|
3
|
+
interface ParamsAndroid {
|
|
4
|
+
/**
|
|
5
|
+
* Default - false
|
|
6
|
+
*
|
|
7
|
+
* Min Android 13
|
|
8
|
+
*/
|
|
9
|
+
androidMaskOffensiveWords?: boolean
|
|
10
|
+
/**
|
|
11
|
+
* Default - false
|
|
12
|
+
*
|
|
13
|
+
* Prefer quality over latency (may break autofinish timing, depends on engine)
|
|
14
|
+
*
|
|
15
|
+
* Min Android 13
|
|
16
|
+
*/
|
|
17
|
+
androidFormattingPreferQuality?: boolean
|
|
18
|
+
/**
|
|
19
|
+
* Default - false
|
|
20
|
+
*
|
|
21
|
+
* Language model based on web search terms. (may not work on some devices)
|
|
22
|
+
*
|
|
23
|
+
* Default - free form model
|
|
24
|
+
*/
|
|
25
|
+
androidUseWebSearchModel?: boolean
|
|
26
|
+
/**
|
|
27
|
+
* Default - false.
|
|
28
|
+
*
|
|
29
|
+
* If required to handle batches non-default way.
|
|
30
|
+
*
|
|
31
|
+
* Will add lots of batches with empty or similar content to the result.
|
|
32
|
+
*/
|
|
33
|
+
androidDisableBatchHandling?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ParamsIOS {
|
|
37
|
+
/**
|
|
38
|
+
* Default - true
|
|
39
|
+
*
|
|
40
|
+
* Adds punctuation to speech recognition results
|
|
41
|
+
*
|
|
42
|
+
* Min iOS 16
|
|
43
|
+
*/
|
|
44
|
+
iosAddPunctuation?: boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SpeechToTextParams extends ParamsAndroid, ParamsIOS {
|
|
48
|
+
/**
|
|
49
|
+
* Default - "en-US"
|
|
50
|
+
*/
|
|
51
|
+
locale?: string
|
|
52
|
+
/**
|
|
53
|
+
* Default - 8s
|
|
54
|
+
*/
|
|
55
|
+
autoFinishRecognitionMs?: number
|
|
56
|
+
/**
|
|
57
|
+
* Default - false
|
|
58
|
+
*
|
|
59
|
+
* Lots of repeating words in a row can be annoying
|
|
60
|
+
*/
|
|
61
|
+
disableRepeatingFilter?: boolean
|
|
62
|
+
/**
|
|
63
|
+
* Default - empty array
|
|
64
|
+
*
|
|
65
|
+
* An array of strings that should be recognized, even if they are not in the system vocabulary.
|
|
66
|
+
*/
|
|
67
|
+
contextualStrings?: string[]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface Recognizer extends HybridObject<{
|
|
71
|
+
ios: 'swift'
|
|
72
|
+
android: 'kotlin'
|
|
73
|
+
}> {
|
|
74
|
+
// Speech-to-text methods
|
|
75
|
+
startListening(params: SpeechToTextParams): void
|
|
76
|
+
stopListening(): void
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* User's speech is ready to be recognized.
|
|
80
|
+
*/
|
|
81
|
+
onReadyForSpeech?: () => void
|
|
82
|
+
/**
|
|
83
|
+
* Audio recording has stopped. (may be called multiple times for one recording)
|
|
84
|
+
*/
|
|
85
|
+
onRecordingStopped?: () => void
|
|
86
|
+
/**
|
|
87
|
+
* Called each time either a new batch has been added or the last batch has been updated.
|
|
88
|
+
*/
|
|
89
|
+
onResult?: (resultBatches: string[]) => void
|
|
90
|
+
/**
|
|
91
|
+
* Called each second while auto finish is in progress.
|
|
92
|
+
*
|
|
93
|
+
* Time left in milliseconds. Always more than 1000ms.
|
|
94
|
+
*
|
|
95
|
+
* TODO: Add for android
|
|
96
|
+
*/
|
|
97
|
+
onAutoFinishProgress?: (timeLeftMs: number) => void
|
|
98
|
+
/**
|
|
99
|
+
* Error of the speech recognition.
|
|
100
|
+
*/
|
|
101
|
+
onError?: (message: string) => void
|
|
102
|
+
/**
|
|
103
|
+
* Permission to record audio has been denied.
|
|
104
|
+
*/
|
|
105
|
+
onPermissionDenied?: () => void
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface NitroSpeech extends HybridObject<{
|
|
109
|
+
ios: 'swift'
|
|
110
|
+
android: 'kotlin'
|
|
111
|
+
}> {
|
|
112
|
+
recognizer: Recognizer
|
|
113
|
+
}
|