@iternio/react-native-auto-play 0.4.1 → 0.4.2
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/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 +95 -0
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputManager.kt +276 -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 +63 -0
- package/ios/utils/VoiceInputManager.swift +141 -40
- package/lib/hybrid/HybridVoice.d.ts +12 -0
- package/lib/hybrid/HybridVoice.js +13 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +2 -0
- package/lib/specs/AutoPlay.nitro.d.ts +0 -29
- package/lib/specs/Voice.nitro.d.ts +51 -0
- package/lib/specs/Voice.nitro.js +1 -0
- package/lib/types/Voice.d.ts +15 -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 +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputResult.kt +41 -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 +227 -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 +30 -0
- package/src/index.ts +3 -0
- package/src/specs/AutoPlay.nitro.ts +0 -37
- package/src/specs/Voice.nitro.ts +58 -0
- package/src/types/Voice.ts +17 -0
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
(options: VoiceInputOptions & Required<Pick<VoiceInputOptions, 'onChunk'>>): Promise<void>;
|
|
9
|
+
(options?: Omit<VoiceInputOptions, 'onChunk'>): Promise<VoiceInputResult>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const startVoiceInput: StartVoiceInput = (async (options?: VoiceInputOptions) => {
|
|
13
|
+
const { onChunk, silenceThresholdMs, maxDurationMs, listeningText, preferSpeechToText } =
|
|
14
|
+
options ?? {};
|
|
15
|
+
const result = await _native.startVoiceInput(
|
|
16
|
+
silenceThresholdMs,
|
|
17
|
+
maxDurationMs,
|
|
18
|
+
listeningText,
|
|
19
|
+
preferSpeechToText,
|
|
20
|
+
onChunk
|
|
21
|
+
);
|
|
22
|
+
return onChunk !== undefined ? undefined : result;
|
|
23
|
+
}) as unknown as StartVoiceInput;
|
|
24
|
+
|
|
25
|
+
export const HybridVoice = {
|
|
26
|
+
hasVoiceInputPermission: () => _native.hasVoiceInputPermission(),
|
|
27
|
+
requestVoiceInputPermission: () => _native.requestVoiceInputPermission(),
|
|
28
|
+
startVoiceInput,
|
|
29
|
+
stopVoiceInput: () => _native.stopVoiceInput(),
|
|
30
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -3,11 +3,13 @@ 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
11
|
export { HybridAutoPlay };
|
|
12
|
+
export { HybridVoice };
|
|
11
13
|
export { HybridAndroidAutoTelemetry };
|
|
12
14
|
|
|
13
15
|
export const HybridAndroidAutomotive =
|
|
@@ -55,6 +57,7 @@ export * from './types/SignInMethod';
|
|
|
55
57
|
export * from './types/Telemetry';
|
|
56
58
|
export * from './types/Text';
|
|
57
59
|
export * from './types/Trip';
|
|
60
|
+
export type { VoiceInputChunk, VoiceInputOptions, VoiceInputResult } from './types/Voice';
|
|
58
61
|
export type {
|
|
59
62
|
AlertPriority,
|
|
60
63
|
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,58 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Returns true if all permissions required for voice input are granted.
|
|
7
|
+
* On iOS: checks both microphone and speech recognition authorization.
|
|
8
|
+
* On Android: checks RECORD_AUDIO permission.
|
|
9
|
+
*/
|
|
10
|
+
hasVoiceInputPermission(): boolean;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Request all permissions required for voice input.
|
|
14
|
+
* On iOS: requests microphone permission then speech recognition authorization.
|
|
15
|
+
* On Android: requests RECORD_AUDIO via car context when connected, otherwise
|
|
16
|
+
* via the React Native application context.
|
|
17
|
+
* Returns true only if all required permissions were granted.
|
|
18
|
+
*/
|
|
19
|
+
requestVoiceInputPermission(): Promise<boolean>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Start an in-app voice session.
|
|
23
|
+
*
|
|
24
|
+
* When preferSpeechToText is true:
|
|
25
|
+
* iOS — streams audio buffers into SFSpeechRecognizer during recording;
|
|
26
|
+
* onChunk fires with partial transcription results; resolves with
|
|
27
|
+
* { transcription } or falls back to { audio } if unavailable.
|
|
28
|
+
* Android — checks SpeechRecognizer availability upfront; if available it
|
|
29
|
+
* owns the mic and streams partial results via onChunk; if not
|
|
30
|
+
* available falls back to PCM recording.
|
|
31
|
+
*
|
|
32
|
+
* When preferSpeechToText is false (default):
|
|
33
|
+
* Both platforms record raw PCM; onChunk fires with audio chunks;
|
|
34
|
+
* resolves with { audio }.
|
|
35
|
+
*
|
|
36
|
+
* @param silenceThresholdMs ms of silence before auto-stop (default 1500)
|
|
37
|
+
* @param maxDurationMs hard cap on recording duration (default 10000)
|
|
38
|
+
* @param listeningText iOS only — text shown on CPVoiceControlTemplate
|
|
39
|
+
* @param preferSpeechToText request STT transcription instead of raw PCM
|
|
40
|
+
* @param onChunk optional streaming callback; when set the
|
|
41
|
+
* promise resolves with an empty VoiceInputResult
|
|
42
|
+
*/
|
|
43
|
+
startVoiceInput(
|
|
44
|
+
silenceThresholdMs?: number,
|
|
45
|
+
maxDurationMs?: number,
|
|
46
|
+
listeningText?: string,
|
|
47
|
+
preferSpeechToText?: boolean,
|
|
48
|
+
onChunk?: (chunk: VoiceInputChunk) => void
|
|
49
|
+
): Promise<VoiceInputResult>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Stop the active voice session early.
|
|
53
|
+
* For PCM mode: resolves startVoiceInput with audio captured so far.
|
|
54
|
+
* For STT mode: finalises the recognition request.
|
|
55
|
+
* No-op if no session is active.
|
|
56
|
+
*/
|
|
57
|
+
stopVoiceInput(): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|