@gmessier/nitro-speech 0.4.2 → 0.4.4
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/README.md +19 -7
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/AudioPermissionRequester.kt +12 -6
- package/android/src/main/java/com/margelo/nitro/nitrospeech/recognizer/HybridRecognizer.kt +57 -39
- package/ios/Audio/AudioLevelTracker.swift +1 -1
- package/ios/Coordinator.swift +1 -0
- package/ios/Engines/AnalyzerEngine.swift +11 -7
- package/ios/Engines/RecognizerEngine.swift +140 -82
- package/ios/Engines/SFSpeechEngine.swift +7 -3
- package/ios/HybridRecognizer.swift +49 -8
- package/ios/Shared/AutoStopper.swift +1 -1
- package/ios/Shared/Permissions.swift +12 -47
- package/ios/Shared/Utils.swift +2 -1
- package/lib/Recognizer/methods.d.ts +10 -10
- package/lib/Recognizer/methods.js +2 -2
- package/lib/Recognizer/types.d.ts +2 -1
- package/lib/index.d.ts +1 -1
- package/lib/specs/Recognizer.nitro.d.ts +2 -1
- package/lib/specs/SpeechRecognitionConfig.d.ts +7 -3
- package/lib/specs/SpeechRecognitionPrewarm.d.ts +10 -0
- package/lib/specs/SpeechRecognitionPrewarm.js +1 -0
- package/nitrogen/generated/android/c++/JHybridRecognizerSpec.cpp +7 -3
- package/nitrogen/generated/android/c++/JHybridRecognizerSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JIosPreset.hpp +3 -0
- package/nitrogen/generated/android/c++/JSpeechRecognitionPrewarm.hpp +57 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/HybridRecognizerSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/IosPreset.kt +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrospeech/SpeechRecognitionPrewarm.kt +51 -0
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Bridge.hpp +18 -0
- package/nitrogen/generated/ios/NitroSpeech-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridRecognizerSpecSwift.hpp +5 -2
- package/nitrogen/generated/ios/swift/HybridRecognizerSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridRecognizerSpec_cxx.swift +2 -2
- package/nitrogen/generated/ios/swift/IosPreset.swift +4 -0
- package/nitrogen/generated/ios/swift/SpeechRecognitionPrewarm.swift +42 -0
- package/nitrogen/generated/shared/c++/HybridRecognizerSpec.hpp +4 -1
- package/nitrogen/generated/shared/c++/IosPreset.hpp +4 -0
- package/nitrogen/generated/shared/c++/SpeechRecognitionPrewarm.hpp +83 -0
- package/package.json +1 -1
- package/src/Recognizer/methods.ts +38 -31
- package/src/Recognizer/types.ts +2 -0
- package/src/index.ts +1 -0
- package/src/specs/Recognizer.nitro.ts +5 -1
- package/src/specs/SpeechRecognitionConfig.ts +7 -3
- package/src/specs/SpeechRecognitionPrewarm.ts +10 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// SpeechRecognitionPrewarm.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
|
+
/**
|
|
11
|
+
* Represents an instance of `SpeechRecognitionPrewarm`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias SpeechRecognitionPrewarm = margelo.nitro.nitrospeech.SpeechRecognitionPrewarm
|
|
14
|
+
|
|
15
|
+
public extension SpeechRecognitionPrewarm {
|
|
16
|
+
private typealias bridge = margelo.nitro.nitrospeech.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `SpeechRecognitionPrewarm`.
|
|
20
|
+
*/
|
|
21
|
+
init(requestPermission: Bool?) {
|
|
22
|
+
self.init({ () -> bridge.std__optional_bool_ in
|
|
23
|
+
if let __unwrappedValue = requestPermission {
|
|
24
|
+
return bridge.create_std__optional_bool_(__unwrappedValue)
|
|
25
|
+
} else {
|
|
26
|
+
return .init()
|
|
27
|
+
}
|
|
28
|
+
}())
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@inline(__always)
|
|
32
|
+
var requestPermission: Bool? {
|
|
33
|
+
return { () -> Bool? in
|
|
34
|
+
if bridge.has_value_std__optional_bool_(self.__requestPermission) {
|
|
35
|
+
let __unwrapped = bridge.get_std__optional_bool_(self.__requestPermission)
|
|
36
|
+
return __unwrapped
|
|
37
|
+
} else {
|
|
38
|
+
return nil
|
|
39
|
+
}
|
|
40
|
+
}()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
namespace margelo::nitro::nitrospeech { struct VolumeChangeEvent; }
|
|
18
18
|
// Forward declaration of `SpeechRecognitionConfig` to properly resolve imports.
|
|
19
19
|
namespace margelo::nitro::nitrospeech { struct SpeechRecognitionConfig; }
|
|
20
|
+
// Forward declaration of `SpeechRecognitionPrewarm` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::nitrospeech { struct SpeechRecognitionPrewarm; }
|
|
20
22
|
// Forward declaration of `MutableSpeechRecognitionConfig` to properly resolve imports.
|
|
21
23
|
namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
|
|
22
24
|
|
|
@@ -27,6 +29,7 @@ namespace margelo::nitro::nitrospeech { struct MutableSpeechRecognitionConfig; }
|
|
|
27
29
|
#include "VolumeChangeEvent.hpp"
|
|
28
30
|
#include <NitroModules/Promise.hpp>
|
|
29
31
|
#include "SpeechRecognitionConfig.hpp"
|
|
32
|
+
#include "SpeechRecognitionPrewarm.hpp"
|
|
30
33
|
#include "MutableSpeechRecognitionConfig.hpp"
|
|
31
34
|
|
|
32
35
|
namespace margelo::nitro::nitrospeech {
|
|
@@ -73,7 +76,7 @@ namespace margelo::nitro::nitrospeech {
|
|
|
73
76
|
|
|
74
77
|
public:
|
|
75
78
|
// Methods
|
|
76
|
-
virtual std::shared_ptr<Promise<void>> prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams) = 0;
|
|
79
|
+
virtual std::shared_ptr<Promise<void>> prewarm(const std::optional<SpeechRecognitionConfig>& defaultParams, const std::optional<SpeechRecognitionPrewarm>& options) = 0;
|
|
77
80
|
virtual void startListening(const std::optional<SpeechRecognitionConfig>& params) = 0;
|
|
78
81
|
virtual void stopListening() = 0;
|
|
79
82
|
virtual void resetAutoFinishTime() = 0;
|
|
@@ -31,6 +31,7 @@ namespace margelo::nitro::nitrospeech {
|
|
|
31
31
|
enum class IosPreset {
|
|
32
32
|
SHORTFORM SWIFT_NAME(shortform) = 0,
|
|
33
33
|
GENERAL SWIFT_NAME(general) = 1,
|
|
34
|
+
SPEED SWIFT_NAME(speed) = 2,
|
|
34
35
|
} CLOSED_ENUM;
|
|
35
36
|
|
|
36
37
|
} // namespace margelo::nitro::nitrospeech
|
|
@@ -45,6 +46,7 @@ namespace margelo::nitro {
|
|
|
45
46
|
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
46
47
|
case hashString("shortform"): return margelo::nitro::nitrospeech::IosPreset::SHORTFORM;
|
|
47
48
|
case hashString("general"): return margelo::nitro::nitrospeech::IosPreset::GENERAL;
|
|
49
|
+
case hashString("speed"): return margelo::nitro::nitrospeech::IosPreset::SPEED;
|
|
48
50
|
default: [[unlikely]]
|
|
49
51
|
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum IosPreset - invalid value!");
|
|
50
52
|
}
|
|
@@ -53,6 +55,7 @@ namespace margelo::nitro {
|
|
|
53
55
|
switch (arg) {
|
|
54
56
|
case margelo::nitro::nitrospeech::IosPreset::SHORTFORM: return JSIConverter<std::string>::toJSI(runtime, "shortform");
|
|
55
57
|
case margelo::nitro::nitrospeech::IosPreset::GENERAL: return JSIConverter<std::string>::toJSI(runtime, "general");
|
|
58
|
+
case margelo::nitro::nitrospeech::IosPreset::SPEED: return JSIConverter<std::string>::toJSI(runtime, "speed");
|
|
56
59
|
default: [[unlikely]]
|
|
57
60
|
throw std::invalid_argument("Cannot convert IosPreset to JS - invalid value: "
|
|
58
61
|
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
@@ -66,6 +69,7 @@ namespace margelo::nitro {
|
|
|
66
69
|
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
67
70
|
case hashString("shortform"):
|
|
68
71
|
case hashString("general"):
|
|
72
|
+
case hashString("speed"):
|
|
69
73
|
return true;
|
|
70
74
|
default:
|
|
71
75
|
return false;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// SpeechRecognitionPrewarm.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
|
+
|
|
32
|
+
|
|
33
|
+
#include <optional>
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::nitrospeech {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (SpeechRecognitionPrewarm).
|
|
39
|
+
*/
|
|
40
|
+
struct SpeechRecognitionPrewarm final {
|
|
41
|
+
public:
|
|
42
|
+
std::optional<bool> requestPermission SWIFT_PRIVATE;
|
|
43
|
+
|
|
44
|
+
public:
|
|
45
|
+
SpeechRecognitionPrewarm() = default;
|
|
46
|
+
explicit SpeechRecognitionPrewarm(std::optional<bool> requestPermission): requestPermission(requestPermission) {}
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
friend bool operator==(const SpeechRecognitionPrewarm& lhs, const SpeechRecognitionPrewarm& rhs) = default;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
} // namespace margelo::nitro::nitrospeech
|
|
53
|
+
|
|
54
|
+
namespace margelo::nitro {
|
|
55
|
+
|
|
56
|
+
// C++ SpeechRecognitionPrewarm <> JS SpeechRecognitionPrewarm (object)
|
|
57
|
+
template <>
|
|
58
|
+
struct JSIConverter<margelo::nitro::nitrospeech::SpeechRecognitionPrewarm> final {
|
|
59
|
+
static inline margelo::nitro::nitrospeech::SpeechRecognitionPrewarm fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
60
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
61
|
+
return margelo::nitro::nitrospeech::SpeechRecognitionPrewarm(
|
|
62
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requestPermission")))
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrospeech::SpeechRecognitionPrewarm& arg) {
|
|
66
|
+
jsi::Object obj(runtime);
|
|
67
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "requestPermission"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.requestPermission));
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
71
|
+
if (!value.isObject()) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
jsi::Object obj = value.getObject(runtime);
|
|
75
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requestPermission")))) return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
|
@@ -1,53 +1,60 @@
|
|
|
1
1
|
import { SpeechRecognizer } from './SpeechRecognizer'
|
|
2
|
-
import type {
|
|
3
|
-
MutableSpeechRecognitionConfig,
|
|
4
|
-
SpeechRecognitionConfig,
|
|
5
|
-
} from './types'
|
|
2
|
+
import type { RecognizerMethods } from './types'
|
|
6
3
|
|
|
7
|
-
export const recognizerPrewarm = (
|
|
4
|
+
export const recognizerPrewarm: RecognizerMethods['prewarm'] = (
|
|
5
|
+
params,
|
|
6
|
+
options
|
|
7
|
+
) => {
|
|
8
8
|
'worklet'
|
|
9
|
-
return SpeechRecognizer.prewarm(params)
|
|
9
|
+
return SpeechRecognizer.prewarm(params, options)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const recognizerStartListening = (
|
|
12
|
+
export const recognizerStartListening: RecognizerMethods['startListening'] = (
|
|
13
|
+
params
|
|
14
|
+
) => {
|
|
13
15
|
'worklet'
|
|
14
16
|
SpeechRecognizer.startListening(params)
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
export const recognizerStopListening =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
export const recognizerStopListening: RecognizerMethods['stopListening'] =
|
|
20
|
+
() => {
|
|
21
|
+
'worklet'
|
|
22
|
+
SpeechRecognizer.stopListening()
|
|
23
|
+
}
|
|
21
24
|
|
|
22
|
-
export const recognizerResetAutoFinishTime =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
export const recognizerResetAutoFinishTime: RecognizerMethods['resetAutoFinishTime'] =
|
|
26
|
+
() => {
|
|
27
|
+
'worklet'
|
|
28
|
+
SpeechRecognizer.resetAutoFinishTime()
|
|
29
|
+
}
|
|
26
30
|
|
|
27
|
-
export const recognizerAddAutoFinishTime =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
export const recognizerAddAutoFinishTime: RecognizerMethods['addAutoFinishTime'] =
|
|
32
|
+
(additionalTimeMs) => {
|
|
33
|
+
'worklet'
|
|
34
|
+
SpeechRecognizer.addAutoFinishTime(additionalTimeMs)
|
|
35
|
+
}
|
|
31
36
|
|
|
32
|
-
export const recognizerUpdateConfig = (
|
|
33
|
-
newConfig
|
|
34
|
-
resetAutoFinishTime
|
|
37
|
+
export const recognizerUpdateConfig: RecognizerMethods['updateConfig'] = (
|
|
38
|
+
newConfig,
|
|
39
|
+
resetAutoFinishTime
|
|
35
40
|
) => {
|
|
36
41
|
'worklet'
|
|
37
42
|
SpeechRecognizer.updateConfig(newConfig, resetAutoFinishTime)
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
export const recognizerGetIsActive = () => {
|
|
45
|
+
export const recognizerGetIsActive: RecognizerMethods['getIsActive'] = () => {
|
|
41
46
|
'worklet'
|
|
42
47
|
return SpeechRecognizer.getIsActive()
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
export const recognizerGetVoiceInputVolume =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
export const recognizerGetVoiceInputVolume: RecognizerMethods['getVoiceInputVolume'] =
|
|
51
|
+
() => {
|
|
52
|
+
'worklet'
|
|
53
|
+
return SpeechRecognizer.getVoiceInputVolume()
|
|
54
|
+
}
|
|
49
55
|
|
|
50
|
-
export const recognizerGetSupportedLocalesIOS =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
export const recognizerGetSupportedLocalesIOS: RecognizerMethods['getSupportedLocalesIOS'] =
|
|
57
|
+
() => {
|
|
58
|
+
'worklet'
|
|
59
|
+
return SpeechRecognizer.getSupportedLocalesIOS().sort()
|
|
60
|
+
}
|
package/src/Recognizer/types.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
SpeechRecognitionConfig,
|
|
5
5
|
} from '../specs/SpeechRecognitionConfig'
|
|
6
6
|
import type { VolumeChangeEvent } from '../specs/VolumeChangeEvent'
|
|
7
|
+
import type { SpeechRecognitionPrewarm } from '../specs/SpeechRecognitionPrewarm'
|
|
7
8
|
|
|
8
9
|
type RecognizerCallbacks = Pick<
|
|
9
10
|
RecognizerSpec,
|
|
@@ -32,6 +33,7 @@ type RecognizerMethods = Pick<
|
|
|
32
33
|
export type {
|
|
33
34
|
RecognizerSpec,
|
|
34
35
|
SpeechRecognitionConfig,
|
|
36
|
+
SpeechRecognitionPrewarm,
|
|
35
37
|
MutableSpeechRecognitionConfig,
|
|
36
38
|
VolumeChangeEvent,
|
|
37
39
|
RecognizerCallbacks,
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
SpeechRecognitionConfig,
|
|
5
5
|
} from './SpeechRecognitionConfig'
|
|
6
6
|
import type { VolumeChangeEvent } from './VolumeChangeEvent'
|
|
7
|
+
import type { SpeechRecognitionPrewarm } from './SpeechRecognitionPrewarm'
|
|
7
8
|
|
|
8
9
|
export interface Recognizer extends HybridObject<{
|
|
9
10
|
ios: 'swift'
|
|
@@ -31,7 +32,10 @@ export interface Recognizer extends HybridObject<{
|
|
|
31
32
|
* });
|
|
32
33
|
* ```
|
|
33
34
|
*/
|
|
34
|
-
prewarm(
|
|
35
|
+
prewarm(
|
|
36
|
+
defaultParams?: SpeechRecognitionConfig,
|
|
37
|
+
options?: SpeechRecognitionPrewarm
|
|
38
|
+
): Promise<void>
|
|
35
39
|
|
|
36
40
|
/**
|
|
37
41
|
* Try to start the speech recognition.
|
|
@@ -23,7 +23,7 @@ interface ParamsAndroid {
|
|
|
23
23
|
androidDisableBatchHandling?: boolean
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
type IosPreset = 'shortform' | 'general'
|
|
26
|
+
type IosPreset = 'shortform' | 'general' | 'speed'
|
|
27
27
|
|
|
28
28
|
interface ParamsIOS {
|
|
29
29
|
/**
|
|
@@ -35,9 +35,13 @@ interface ParamsIOS {
|
|
|
35
35
|
*/
|
|
36
36
|
iosAddPunctuation?: boolean
|
|
37
37
|
/**
|
|
38
|
-
* `"shortForm"` -
|
|
38
|
+
* `"shortForm"` - For a short phrase or sentence, also disables punctuation
|
|
39
39
|
*
|
|
40
|
-
* `"
|
|
40
|
+
* `"speed"` - Gives priority to speed over accuracy
|
|
41
|
+
*
|
|
42
|
+
* `"general"` - For longer speeches, more accurate but delayed response
|
|
43
|
+
*
|
|
44
|
+
* @note preset may be overridden by other properties
|
|
41
45
|
*
|
|
42
46
|
* @since iOS 26.0+
|
|
43
47
|
*
|