@iternio/react-native-auto-play 0.4.11 → 0.4.12
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 +26 -0
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt +0 -89
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoice.kt +97 -0
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputManager.kt +286 -20
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/utils/ThreadUtil.kt +6 -13
- package/ios/hybrid/HybridAutoPlay.swift +2 -47
- package/ios/hybrid/HybridVoice.swift +65 -0
- package/ios/utils/VoiceInputManager.swift +144 -40
- package/lib/HybridAutoPlay.d.ts +2 -0
- package/lib/HybridAutoPlay.js +2 -0
- package/lib/components/OnAppearedChildRenderer.d.ts +10 -0
- package/lib/components/OnAppearedChildRenderer.js +26 -0
- package/lib/hooks/useIsAutoPlayFocused.d.ts +7 -0
- package/lib/hooks/useIsAutoPlayFocused.js +20 -0
- package/lib/hybrid/HybridVoice.d.ts +52 -0
- package/lib/hybrid/HybridVoice.js +52 -0
- package/lib/hybrid.d.ts +2 -0
- package/lib/hybrid.js +2 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +2 -1
- package/lib/specs/AutoPlay.nitro.d.ts +0 -29
- package/lib/specs/AutomotivePermissionRequestTemplate.d.ts +11 -0
- package/lib/specs/AutomotivePermissionRequestTemplate.js +1 -0
- package/lib/specs/AutomotivePermissionRequestTemplate.nitro.d.ts +11 -0
- package/lib/specs/AutomotivePermissionRequestTemplate.nitro.js +1 -0
- package/lib/specs/Voice.nitro.d.ts +11 -0
- package/lib/specs/Voice.nitro.js +1 -0
- package/lib/templates/AutomotivePermissionRequestTemplate.d.ts +23 -0
- package/lib/templates/AutomotivePermissionRequestTemplate.js +18 -0
- package/lib/types/Glyphmap.d.ts +4105 -0
- package/lib/types/Glyphmap.js +4105 -0
- package/lib/types/Voice.d.ts +16 -0
- package/lib/types/Voice.js +1 -0
- package/nitro.json +10 -0
- package/nitrogen/generated/android/ReactNativeAutoPlay+autolinking.cmake +2 -0
- package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +18 -0
- package/nitrogen/generated/android/c++/JFunc_void_VoiceInputChunk.hpp +81 -0
- package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.cpp +0 -43
- package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.hpp +0 -4
- package/nitrogen/generated/android/c++/JHybridVoiceSpec.cpp +104 -0
- package/nitrogen/generated/android/c++/JHybridVoiceSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JVoiceInputChunk.hpp +64 -0
- package/nitrogen/generated/android/c++/JVoiceInputResult.hpp +64 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_VoiceInputChunk.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlaySpec.kt +0 -17
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoiceSpec.kt +72 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputChunk.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputResult.kt +56 -0
- package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.cpp +41 -16
- package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp +201 -126
- package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp +11 -0
- package/nitrogen/generated/ios/ReactNativeAutoPlayAutolinking.mm +8 -0
- package/nitrogen/generated/ios/ReactNativeAutoPlayAutolinking.swift +12 -0
- package/nitrogen/generated/ios/c++/HybridAutoPlaySpecSwift.hpp +0 -34
- package/nitrogen/generated/ios/c++/HybridVoiceSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridVoiceSpecSwift.hpp +116 -0
- package/nitrogen/generated/ios/swift/Func_void_VoiceInputChunk.swift +46 -0
- package/nitrogen/generated/ios/swift/{Func_void_std__shared_ptr_ArrayBuffer_.swift → Func_void_VoiceInputResult.swift} +10 -10
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +5 -5
- package/nitrogen/generated/ios/swift/HybridAutoPlaySpec.swift +0 -4
- package/nitrogen/generated/ios/swift/HybridAutoPlaySpec_cxx.swift +0 -82
- package/nitrogen/generated/ios/swift/HybridVoiceSpec.swift +58 -0
- package/nitrogen/generated/ios/swift/HybridVoiceSpec_cxx.swift +234 -0
- package/nitrogen/generated/ios/swift/VoiceInputChunk.swift +60 -0
- package/nitrogen/generated/ios/swift/VoiceInputResult.swift +60 -0
- package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.cpp +0 -4
- package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.hpp +0 -5
- package/nitrogen/generated/shared/c++/HybridVoiceSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridVoiceSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/VoiceInputChunk.hpp +89 -0
- package/nitrogen/generated/shared/c++/VoiceInputResult.hpp +89 -0
- package/package.json +1 -1
- package/src/hybrid/HybridVoice.ts +79 -0
- package/src/index.ts +3 -1
- package/src/specs/AutoPlay.nitro.ts +0 -37
- package/src/specs/Voice.nitro.ts +16 -0
- package/src/types/Voice.ts +18 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// VoiceInputChunk.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 `VoiceInputChunk`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias VoiceInputChunk = margelo.nitro.swe.iternio.reactnativeautoplay.VoiceInputChunk
|
|
14
|
+
|
|
15
|
+
public extension VoiceInputChunk {
|
|
16
|
+
private typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `VoiceInputChunk`.
|
|
20
|
+
*/
|
|
21
|
+
init(partial: String?, audio: ArrayBuffer?) {
|
|
22
|
+
self.init({ () -> bridge.std__optional_std__string_ in
|
|
23
|
+
if let __unwrappedValue = partial {
|
|
24
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
25
|
+
} else {
|
|
26
|
+
return .init()
|
|
27
|
+
}
|
|
28
|
+
}(), { () -> bridge.std__optional_std__shared_ptr_ArrayBuffer__ in
|
|
29
|
+
if let __unwrappedValue = audio {
|
|
30
|
+
return bridge.create_std__optional_std__shared_ptr_ArrayBuffer__(__unwrappedValue.getArrayBuffer())
|
|
31
|
+
} else {
|
|
32
|
+
return .init()
|
|
33
|
+
}
|
|
34
|
+
}())
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@inline(__always)
|
|
38
|
+
var partial: String? {
|
|
39
|
+
return { () -> String? in
|
|
40
|
+
if bridge.has_value_std__optional_std__string_(self.__partial) {
|
|
41
|
+
let __unwrapped = bridge.get_std__optional_std__string_(self.__partial)
|
|
42
|
+
return String(__unwrapped)
|
|
43
|
+
} else {
|
|
44
|
+
return nil
|
|
45
|
+
}
|
|
46
|
+
}()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@inline(__always)
|
|
50
|
+
var audio: ArrayBuffer? {
|
|
51
|
+
return { () -> ArrayBuffer? in
|
|
52
|
+
if bridge.has_value_std__optional_std__shared_ptr_ArrayBuffer__(self.__audio) {
|
|
53
|
+
let __unwrapped = bridge.get_std__optional_std__shared_ptr_ArrayBuffer__(self.__audio)
|
|
54
|
+
return ArrayBuffer(__unwrapped)
|
|
55
|
+
} else {
|
|
56
|
+
return nil
|
|
57
|
+
}
|
|
58
|
+
}()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// VoiceInputResult.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 `VoiceInputResult`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias VoiceInputResult = margelo.nitro.swe.iternio.reactnativeautoplay.VoiceInputResult
|
|
14
|
+
|
|
15
|
+
public extension VoiceInputResult {
|
|
16
|
+
private typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `VoiceInputResult`.
|
|
20
|
+
*/
|
|
21
|
+
init(transcription: String?, audio: ArrayBuffer?) {
|
|
22
|
+
self.init({ () -> bridge.std__optional_std__string_ in
|
|
23
|
+
if let __unwrappedValue = transcription {
|
|
24
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
25
|
+
} else {
|
|
26
|
+
return .init()
|
|
27
|
+
}
|
|
28
|
+
}(), { () -> bridge.std__optional_std__shared_ptr_ArrayBuffer__ in
|
|
29
|
+
if let __unwrappedValue = audio {
|
|
30
|
+
return bridge.create_std__optional_std__shared_ptr_ArrayBuffer__(__unwrappedValue.getArrayBuffer())
|
|
31
|
+
} else {
|
|
32
|
+
return .init()
|
|
33
|
+
}
|
|
34
|
+
}())
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@inline(__always)
|
|
38
|
+
var transcription: String? {
|
|
39
|
+
return { () -> String? in
|
|
40
|
+
if bridge.has_value_std__optional_std__string_(self.__transcription) {
|
|
41
|
+
let __unwrapped = bridge.get_std__optional_std__string_(self.__transcription)
|
|
42
|
+
return String(__unwrapped)
|
|
43
|
+
} else {
|
|
44
|
+
return nil
|
|
45
|
+
}
|
|
46
|
+
}()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@inline(__always)
|
|
50
|
+
var audio: ArrayBuffer? {
|
|
51
|
+
return { () -> ArrayBuffer? in
|
|
52
|
+
if bridge.has_value_std__optional_std__shared_ptr_ArrayBuffer__(self.__audio) {
|
|
53
|
+
let __unwrapped = bridge.get_std__optional_std__shared_ptr_ArrayBuffer__(self.__audio)
|
|
54
|
+
return ArrayBuffer(__unwrapped)
|
|
55
|
+
} else {
|
|
56
|
+
return nil
|
|
57
|
+
}
|
|
58
|
+
}()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -17,10 +17,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
|
|
|
17
17
|
prototype.registerHybridMethod("addListener", &HybridAutoPlaySpec::addListener);
|
|
18
18
|
prototype.registerHybridMethod("addListenerRenderState", &HybridAutoPlaySpec::addListenerRenderState);
|
|
19
19
|
prototype.registerHybridMethod("addListenerVoiceInput", &HybridAutoPlaySpec::addListenerVoiceInput);
|
|
20
|
-
prototype.registerHybridMethod("hasVoiceInputPermission", &HybridAutoPlaySpec::hasVoiceInputPermission);
|
|
21
|
-
prototype.registerHybridMethod("requestVoiceInputPermission", &HybridAutoPlaySpec::requestVoiceInputPermission);
|
|
22
|
-
prototype.registerHybridMethod("startVoiceInput", &HybridAutoPlaySpec::startVoiceInput);
|
|
23
|
-
prototype.registerHybridMethod("stopVoiceInput", &HybridAutoPlaySpec::stopVoiceInput);
|
|
24
20
|
prototype.registerHybridMethod("setRootTemplate", &HybridAutoPlaySpec::setRootTemplate);
|
|
25
21
|
prototype.registerHybridMethod("pushTemplate", &HybridAutoPlaySpec::pushTemplate);
|
|
26
22
|
prototype.registerHybridMethod("popTemplate", &HybridAutoPlaySpec::popTemplate);
|
|
@@ -31,7 +31,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct NitroAction
|
|
|
31
31
|
#include "Location.hpp"
|
|
32
32
|
#include <optional>
|
|
33
33
|
#include <NitroModules/Promise.hpp>
|
|
34
|
-
#include <NitroModules/ArrayBuffer.hpp>
|
|
35
34
|
#include "SafeAreaInsets.hpp"
|
|
36
35
|
#include "NitroAction.hpp"
|
|
37
36
|
#include <vector>
|
|
@@ -70,10 +69,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
|
|
|
70
69
|
virtual std::function<void()> addListener(EventName eventType, const std::function<void()>& callback) = 0;
|
|
71
70
|
virtual std::function<void()> addListenerRenderState(const std::string& moduleName, const std::function<void(VisibilityState /* payload */)>& callback) = 0;
|
|
72
71
|
virtual std::function<void()> addListenerVoiceInput(const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& callback) = 0;
|
|
73
|
-
virtual bool hasVoiceInputPermission() = 0;
|
|
74
|
-
virtual std::shared_ptr<Promise<bool>> requestVoiceInputPermission() = 0;
|
|
75
|
-
virtual std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> startVoiceInput(std::optional<double> silenceThresholdMs, std::optional<double> maxDurationMs, const std::optional<std::string>& listeningText) = 0;
|
|
76
|
-
virtual void stopVoiceInput() = 0;
|
|
77
72
|
virtual std::shared_ptr<Promise<void>> setRootTemplate(const std::string& templateId) = 0;
|
|
78
73
|
virtual std::shared_ptr<Promise<void>> pushTemplate(const std::string& templateId) = 0;
|
|
79
74
|
virtual std::shared_ptr<Promise<void>> popTemplate(std::optional<bool> animate) = 0;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridVoiceSpec.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 "HybridVoiceSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::swe::iternio::reactnativeautoplay {
|
|
11
|
+
|
|
12
|
+
void HybridVoiceSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("hasVoiceInputPermission", &HybridVoiceSpec::hasVoiceInputPermission);
|
|
18
|
+
prototype.registerHybridMethod("requestVoiceInputPermission", &HybridVoiceSpec::requestVoiceInputPermission);
|
|
19
|
+
prototype.registerHybridMethod("startVoiceInput", &HybridVoiceSpec::startVoiceInput);
|
|
20
|
+
prototype.registerHybridMethod("stopVoiceInput", &HybridVoiceSpec::stopVoiceInput);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
} // namespace margelo::nitro::swe::iternio::reactnativeautoplay
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridVoiceSpec.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/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 `VoiceInputResult` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct VoiceInputResult; }
|
|
18
|
+
// Forward declaration of `VoiceInputChunk` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct VoiceInputChunk; }
|
|
20
|
+
|
|
21
|
+
#include <NitroModules/Promise.hpp>
|
|
22
|
+
#include "VoiceInputResult.hpp"
|
|
23
|
+
#include <optional>
|
|
24
|
+
#include <string>
|
|
25
|
+
#include "VoiceInputChunk.hpp"
|
|
26
|
+
#include <functional>
|
|
27
|
+
|
|
28
|
+
namespace margelo::nitro::swe::iternio::reactnativeautoplay {
|
|
29
|
+
|
|
30
|
+
using namespace margelo::nitro;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* An abstract base class for `Voice`
|
|
34
|
+
* Inherit this class to create instances of `HybridVoiceSpec` in C++.
|
|
35
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
36
|
+
* @example
|
|
37
|
+
* ```cpp
|
|
38
|
+
* class HybridVoice: public HybridVoiceSpec {
|
|
39
|
+
* public:
|
|
40
|
+
* HybridVoice(...): HybridObject(TAG) { ... }
|
|
41
|
+
* // ...
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
class HybridVoiceSpec: public virtual HybridObject {
|
|
46
|
+
public:
|
|
47
|
+
// Constructor
|
|
48
|
+
explicit HybridVoiceSpec(): HybridObject(TAG) { }
|
|
49
|
+
|
|
50
|
+
// Destructor
|
|
51
|
+
~HybridVoiceSpec() override = default;
|
|
52
|
+
|
|
53
|
+
public:
|
|
54
|
+
// Properties
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
// Methods
|
|
59
|
+
virtual bool hasVoiceInputPermission() = 0;
|
|
60
|
+
virtual std::shared_ptr<Promise<bool>> requestVoiceInputPermission() = 0;
|
|
61
|
+
virtual std::shared_ptr<Promise<VoiceInputResult>> startVoiceInput(std::optional<double> silenceThresholdMs, std::optional<double> maxDurationMs, const std::optional<std::string>& listeningText, std::optional<bool> preferSpeechToText, const std::optional<std::function<void(const VoiceInputChunk& /* chunk */)>>& onChunk, const std::optional<std::string>& language) = 0;
|
|
62
|
+
virtual void stopVoiceInput() = 0;
|
|
63
|
+
|
|
64
|
+
protected:
|
|
65
|
+
// Hybrid Setup
|
|
66
|
+
void loadHybridMethods() override;
|
|
67
|
+
|
|
68
|
+
protected:
|
|
69
|
+
// Tag for logging
|
|
70
|
+
static constexpr auto TAG = "Voice";
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
} // namespace margelo::nitro::swe::iternio::reactnativeautoplay
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// VoiceInputChunk.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 <string>
|
|
34
|
+
#include <optional>
|
|
35
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
36
|
+
|
|
37
|
+
namespace margelo::nitro::swe::iternio::reactnativeautoplay {
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A struct which can be represented as a JavaScript object (VoiceInputChunk).
|
|
41
|
+
*/
|
|
42
|
+
struct VoiceInputChunk final {
|
|
43
|
+
public:
|
|
44
|
+
std::optional<std::string> partial SWIFT_PRIVATE;
|
|
45
|
+
std::optional<std::shared_ptr<ArrayBuffer>> audio SWIFT_PRIVATE;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
VoiceInputChunk() = default;
|
|
49
|
+
explicit VoiceInputChunk(std::optional<std::string> partial, std::optional<std::shared_ptr<ArrayBuffer>> audio): partial(partial), audio(audio) {}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
friend bool operator==(const VoiceInputChunk& lhs, const VoiceInputChunk& rhs) = default;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace margelo::nitro::swe::iternio::reactnativeautoplay
|
|
56
|
+
|
|
57
|
+
namespace margelo::nitro {
|
|
58
|
+
|
|
59
|
+
// C++ VoiceInputChunk <> JS VoiceInputChunk (object)
|
|
60
|
+
template <>
|
|
61
|
+
struct JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputChunk> final {
|
|
62
|
+
static inline margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputChunk fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
63
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
64
|
+
return margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputChunk(
|
|
65
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "partial"))),
|
|
66
|
+
JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audio")))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputChunk& arg) {
|
|
70
|
+
jsi::Object obj(runtime);
|
|
71
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "partial"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.partial));
|
|
72
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "audio"), JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::toJSI(runtime, arg.audio));
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
76
|
+
if (!value.isObject()) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
jsi::Object obj = value.getObject(runtime);
|
|
80
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "partial")))) return false;
|
|
84
|
+
if (!JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audio")))) return false;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// VoiceInputResult.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 <string>
|
|
34
|
+
#include <optional>
|
|
35
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
36
|
+
|
|
37
|
+
namespace margelo::nitro::swe::iternio::reactnativeautoplay {
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A struct which can be represented as a JavaScript object (VoiceInputResult).
|
|
41
|
+
*/
|
|
42
|
+
struct VoiceInputResult final {
|
|
43
|
+
public:
|
|
44
|
+
std::optional<std::string> transcription SWIFT_PRIVATE;
|
|
45
|
+
std::optional<std::shared_ptr<ArrayBuffer>> audio SWIFT_PRIVATE;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
VoiceInputResult() = default;
|
|
49
|
+
explicit VoiceInputResult(std::optional<std::string> transcription, std::optional<std::shared_ptr<ArrayBuffer>> audio): transcription(transcription), audio(audio) {}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
friend bool operator==(const VoiceInputResult& lhs, const VoiceInputResult& rhs) = default;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace margelo::nitro::swe::iternio::reactnativeautoplay
|
|
56
|
+
|
|
57
|
+
namespace margelo::nitro {
|
|
58
|
+
|
|
59
|
+
// C++ VoiceInputResult <> JS VoiceInputResult (object)
|
|
60
|
+
template <>
|
|
61
|
+
struct JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputResult> final {
|
|
62
|
+
static inline margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
63
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
64
|
+
return margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputResult(
|
|
65
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "transcription"))),
|
|
66
|
+
JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audio")))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::VoiceInputResult& arg) {
|
|
70
|
+
jsi::Object obj(runtime);
|
|
71
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "transcription"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.transcription));
|
|
72
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "audio"), JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::toJSI(runtime, arg.audio));
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
76
|
+
if (!value.isObject()) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
jsi::Object obj = value.getObject(runtime);
|
|
80
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "transcription")))) return false;
|
|
84
|
+
if (!JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "audio")))) return false;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { Voice } from '../specs/Voice.nitro';
|
|
3
|
+
import type { VoiceInputOptions, VoiceInputResult } from '../types/Voice';
|
|
4
|
+
|
|
5
|
+
const _native = NitroModules.createHybridObject<Voice>('Voice');
|
|
6
|
+
|
|
7
|
+
type StartVoiceInput = {
|
|
8
|
+
(
|
|
9
|
+
options: VoiceInputOptions & Required<Pick<VoiceInputOptions, 'onChunk'>>
|
|
10
|
+
): Promise<VoiceInputResult>;
|
|
11
|
+
(options?: Omit<VoiceInputOptions, 'onChunk'>): Promise<VoiceInputResult>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const startVoiceInput: StartVoiceInput = async (options?: VoiceInputOptions) => {
|
|
15
|
+
const {
|
|
16
|
+
onChunk,
|
|
17
|
+
silenceThresholdMs,
|
|
18
|
+
maxDurationMs,
|
|
19
|
+
listeningText,
|
|
20
|
+
preferSpeechToText,
|
|
21
|
+
language,
|
|
22
|
+
} = options ?? {};
|
|
23
|
+
|
|
24
|
+
return await _native.startVoiceInput(
|
|
25
|
+
silenceThresholdMs,
|
|
26
|
+
maxDurationMs,
|
|
27
|
+
listeningText,
|
|
28
|
+
preferSpeechToText,
|
|
29
|
+
onChunk,
|
|
30
|
+
language
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const HybridVoice = {
|
|
35
|
+
/**
|
|
36
|
+
* Returns true if all permissions required for voice input are granted.
|
|
37
|
+
* On iOS: checks both microphone and speech recognition authorization.
|
|
38
|
+
* On Android: checks RECORD_AUDIO permission.
|
|
39
|
+
*/
|
|
40
|
+
hasVoiceInputPermission: () => _native.hasVoiceInputPermission(),
|
|
41
|
+
/**
|
|
42
|
+
* Request all permissions required for voice input.
|
|
43
|
+
* On iOS: requests microphone permission then speech recognition authorization.
|
|
44
|
+
* On Android: requests RECORD_AUDIO via car context when connected, otherwise
|
|
45
|
+
* via the React Native application context.
|
|
46
|
+
* Returns true only if all required permissions were granted.
|
|
47
|
+
*/
|
|
48
|
+
requestVoiceInputPermission: () => _native.requestVoiceInputPermission(),
|
|
49
|
+
/**
|
|
50
|
+
* Start an in-app voice session.
|
|
51
|
+
*
|
|
52
|
+
* When preferSpeechToText is true:
|
|
53
|
+
* iOS — streams audio buffers into SFSpeechRecognizer during recording;
|
|
54
|
+
* onChunk fires with partial transcription results; resolves with
|
|
55
|
+
* { transcription } or falls back to { audio } if unavailable.
|
|
56
|
+
* Android — checks SpeechRecognizer availability upfront; if available it
|
|
57
|
+
* owns the mic and streams partial results via onChunk; if not
|
|
58
|
+
* available falls back to PCM recording.
|
|
59
|
+
*
|
|
60
|
+
* When preferSpeechToText is false (default):
|
|
61
|
+
* Both platforms record raw PCM; onChunk fires with audio chunks;
|
|
62
|
+
* resolves with { audio }.
|
|
63
|
+
*
|
|
64
|
+
* @param silenceThresholdMs ms of silence before auto-stop (default 1500)
|
|
65
|
+
* @param maxDurationMs hard cap on recording duration (default 10000)
|
|
66
|
+
* @param listeningText iOS only — text shown on CPVoiceControlTemplate
|
|
67
|
+
* @param preferSpeechToText request STT transcription instead of raw PCM
|
|
68
|
+
* @param onChunk optional streaming callback
|
|
69
|
+
* @param language specify the language for the SpeechRecognizer, falls back to system language if not set
|
|
70
|
+
*/
|
|
71
|
+
startVoiceInput,
|
|
72
|
+
/**
|
|
73
|
+
* Stop the active voice session early.
|
|
74
|
+
* For PCM mode: resolves startVoiceInput with audio captured so far.
|
|
75
|
+
* For STT mode: finalises the recognition request.
|
|
76
|
+
* No-op if no session is active.
|
|
77
|
+
*/
|
|
78
|
+
stopVoiceInput: () => _native.stopVoiceInput(),
|
|
79
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -3,11 +3,12 @@ import { NitroModules } from 'react-native-nitro-modules';
|
|
|
3
3
|
import AutoPlayHeadlessJsTask from './AutoPlayHeadlessJsTask';
|
|
4
4
|
import { HybridAndroidAutoTelemetry } from './hybrid/HybridAndroidAutoTelemetry';
|
|
5
5
|
import { HybridAutoPlay } from './hybrid/HybridAutoPlay';
|
|
6
|
+
import { HybridVoice } from './hybrid/HybridVoice';
|
|
6
7
|
import type { AndroidAutomotive } from './specs/AndroidAutomotive.nitro';
|
|
7
8
|
|
|
8
9
|
AutoPlayHeadlessJsTask.registerHeadlessTask(HybridAutoPlay);
|
|
9
10
|
|
|
10
|
-
export { HybridAndroidAutoTelemetry, HybridAutoPlay };
|
|
11
|
+
export { HybridAndroidAutoTelemetry, HybridAutoPlay, HybridVoice };
|
|
11
12
|
|
|
12
13
|
export const HybridAndroidAutomotive =
|
|
13
14
|
Platform.OS === 'android'
|
|
@@ -54,6 +55,7 @@ export * from './types/SignInMethod';
|
|
|
54
55
|
export * from './types/Telemetry';
|
|
55
56
|
export * from './types/Text';
|
|
56
57
|
export * from './types/Trip';
|
|
58
|
+
export type { VoiceInputChunk, VoiceInputOptions, VoiceInputResult } from './types/Voice';
|
|
57
59
|
export type {
|
|
58
60
|
AlertPriority,
|
|
59
61
|
NavigationAlert as Alert,
|
|
@@ -44,43 +44,6 @@ export interface AutoPlay extends HybridObject<{ android: 'kotlin'; ios: 'swift'
|
|
|
44
44
|
callback: (coordinates: Location | undefined, query: string | undefined) => void
|
|
45
45
|
): CleanupCallback;
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
* Returns true if microphone permission has already been granted.
|
|
49
|
-
*/
|
|
50
|
-
hasVoiceInputPermission(): boolean;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Request microphone permission from the user.
|
|
54
|
-
* On Android: uses the car context when Android Auto is connected, otherwise
|
|
55
|
-
* falls back to the React Native application context.
|
|
56
|
-
* On iOS: uses AVAudioApplication (iOS 17+) or AVAudioSession (iOS 15–16).
|
|
57
|
-
* Returns true if permission was granted, false if denied.
|
|
58
|
-
*/
|
|
59
|
-
requestVoiceInputPermission(): Promise<boolean>;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Start an in-app voice recording session.
|
|
63
|
-
* On Android: acquires audio focus and captures via CarAudioRecord when
|
|
64
|
-
* Android Auto is connected, otherwise uses standard AudioRecord.
|
|
65
|
-
* On iOS: presents CPVoiceControlTemplate (when a car is connected) and
|
|
66
|
-
* captures audio via AVAudioEngine.
|
|
67
|
-
* Resolves with the complete raw PCM buffer (16 kHz, 16-bit, mono) when
|
|
68
|
-
* silence is detected, the max duration is reached, or stopVoiceInput() is called.
|
|
69
|
-
* Rejects if microphone permission has not been granted or recording fails to start.
|
|
70
|
-
*/
|
|
71
|
-
startVoiceInput(
|
|
72
|
-
silenceThresholdMs?: number,
|
|
73
|
-
maxDurationMs?: number,
|
|
74
|
-
listeningText?: string
|
|
75
|
-
): Promise<ArrayBuffer>;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Stop the active voice recording session early. Causes the Promise returned
|
|
79
|
-
* by startVoiceInput() to resolve with the audio captured so far.
|
|
80
|
-
* No-op if no recording is in progress.
|
|
81
|
-
*/
|
|
82
|
-
stopVoiceInput(): void;
|
|
83
|
-
|
|
84
47
|
/**
|
|
85
48
|
* sets the specified template as root template, initializes a new stack
|
|
86
49
|
* Promise might contain an error message in case setting root template failed
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
import type { VoiceInputChunk, VoiceInputResult } from '../types/Voice';
|
|
3
|
+
|
|
4
|
+
export interface Voice extends HybridObject<{ android: 'kotlin'; ios: 'swift' }> {
|
|
5
|
+
hasVoiceInputPermission(): boolean;
|
|
6
|
+
requestVoiceInputPermission(): Promise<boolean>;
|
|
7
|
+
startVoiceInput(
|
|
8
|
+
silenceThresholdMs?: number,
|
|
9
|
+
maxDurationMs?: number,
|
|
10
|
+
listeningText?: string,
|
|
11
|
+
preferSpeechToText?: boolean,
|
|
12
|
+
onChunk?: (chunk: VoiceInputChunk) => void,
|
|
13
|
+
language?: string
|
|
14
|
+
): Promise<VoiceInputResult>;
|
|
15
|
+
stopVoiceInput(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface VoiceInputChunk {
|
|
2
|
+
partial?: string;
|
|
3
|
+
audio?: ArrayBuffer;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface VoiceInputResult {
|
|
7
|
+
transcription?: string;
|
|
8
|
+
audio?: ArrayBuffer;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface VoiceInputOptions {
|
|
12
|
+
silenceThresholdMs?: number;
|
|
13
|
+
maxDurationMs?: number;
|
|
14
|
+
listeningText?: string;
|
|
15
|
+
preferSpeechToText?: boolean;
|
|
16
|
+
onChunk?: (chunk: VoiceInputChunk) => void;
|
|
17
|
+
language?: string;
|
|
18
|
+
}
|