@iternio/react-native-auto-play 0.4.6 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt +0 -89
  2. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoice.kt +97 -0
  3. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputManager.kt +286 -20
  4. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/utils/ThreadUtil.kt +6 -13
  5. package/ios/hybrid/HybridAutoPlay.swift +2 -47
  6. package/ios/hybrid/HybridVoice.swift +65 -0
  7. package/ios/utils/VoiceInputManager.swift +144 -40
  8. package/lib/HybridAutoPlay.d.ts +2 -0
  9. package/lib/HybridAutoPlay.js +2 -0
  10. package/lib/hooks/useIsAutoPlayFocused.d.ts +7 -0
  11. package/lib/hooks/useIsAutoPlayFocused.js +20 -0
  12. package/lib/hybrid/HybridVoice.d.ts +52 -0
  13. package/lib/hybrid/HybridVoice.js +52 -0
  14. package/lib/hybrid.d.ts +2 -0
  15. package/lib/hybrid.js +2 -0
  16. package/lib/index.d.ts +3 -1
  17. package/lib/index.js +2 -1
  18. package/lib/specs/AutoPlay.nitro.d.ts +0 -29
  19. package/lib/specs/AutomotivePermissionRequestTemplate.d.ts +11 -0
  20. package/lib/specs/AutomotivePermissionRequestTemplate.js +1 -0
  21. package/lib/specs/AutomotivePermissionRequestTemplate.nitro.d.ts +11 -0
  22. package/lib/specs/AutomotivePermissionRequestTemplate.nitro.js +1 -0
  23. package/lib/specs/Voice.nitro.d.ts +11 -0
  24. package/lib/specs/Voice.nitro.js +1 -0
  25. package/lib/templates/AutomotivePermissionRequestTemplate.d.ts +23 -0
  26. package/lib/templates/AutomotivePermissionRequestTemplate.js +18 -0
  27. package/lib/templates/MapTemplate.js +1 -6
  28. package/lib/types/Glyphmap.d.ts +4105 -0
  29. package/lib/types/Glyphmap.js +4105 -0
  30. package/lib/types/Voice.d.ts +16 -0
  31. package/lib/types/Voice.js +1 -0
  32. package/nitro.json +10 -0
  33. package/nitrogen/generated/android/ReactNativeAutoPlay+autolinking.cmake +2 -0
  34. package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +18 -0
  35. package/nitrogen/generated/android/c++/JFunc_void_VoiceInputChunk.hpp +81 -0
  36. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.cpp +0 -43
  37. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.hpp +0 -4
  38. package/nitrogen/generated/android/c++/JHybridVoiceSpec.cpp +104 -0
  39. package/nitrogen/generated/android/c++/JHybridVoiceSpec.hpp +66 -0
  40. package/nitrogen/generated/android/c++/JVoiceInputChunk.hpp +64 -0
  41. package/nitrogen/generated/android/c++/JVoiceInputResult.hpp +64 -0
  42. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_VoiceInputChunk.kt +80 -0
  43. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlaySpec.kt +0 -17
  44. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridVoiceSpec.kt +72 -0
  45. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputChunk.kt +41 -0
  46. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/VoiceInputResult.kt +41 -0
  47. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.cpp +41 -16
  48. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp +201 -126
  49. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp +11 -0
  50. package/nitrogen/generated/ios/ReactNativeAutoPlayAutolinking.mm +8 -0
  51. package/nitrogen/generated/ios/ReactNativeAutoPlayAutolinking.swift +12 -0
  52. package/nitrogen/generated/ios/c++/HybridAutoPlaySpecSwift.hpp +0 -34
  53. package/nitrogen/generated/ios/c++/HybridVoiceSpecSwift.cpp +11 -0
  54. package/nitrogen/generated/ios/c++/HybridVoiceSpecSwift.hpp +116 -0
  55. package/nitrogen/generated/ios/swift/Func_void_VoiceInputChunk.swift +46 -0
  56. package/nitrogen/generated/ios/swift/{Func_void_std__shared_ptr_ArrayBuffer_.swift → Func_void_VoiceInputResult.swift} +10 -10
  57. package/nitrogen/generated/ios/swift/Func_void_bool.swift +5 -5
  58. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec.swift +0 -4
  59. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec_cxx.swift +0 -82
  60. package/nitrogen/generated/ios/swift/HybridVoiceSpec.swift +58 -0
  61. package/nitrogen/generated/ios/swift/HybridVoiceSpec_cxx.swift +234 -0
  62. package/nitrogen/generated/ios/swift/VoiceInputChunk.swift +60 -0
  63. package/nitrogen/generated/ios/swift/VoiceInputResult.swift +60 -0
  64. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.cpp +0 -4
  65. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.hpp +0 -5
  66. package/nitrogen/generated/shared/c++/HybridVoiceSpec.cpp +24 -0
  67. package/nitrogen/generated/shared/c++/HybridVoiceSpec.hpp +73 -0
  68. package/nitrogen/generated/shared/c++/VoiceInputChunk.hpp +89 -0
  69. package/nitrogen/generated/shared/c++/VoiceInputResult.hpp +89 -0
  70. package/package.json +1 -1
  71. package/src/hybrid/HybridVoice.ts +79 -0
  72. package/src/index.ts +3 -1
  73. package/src/specs/AutoPlay.nitro.ts +0 -37
  74. package/src/specs/Voice.nitro.ts +16 -0
  75. package/src/templates/MapTemplate.ts +1 -6
  76. package/src/types/Voice.ts +18 -0
  77. package/src/components/OnAppearedChildRenderer.tsx +0 -37
@@ -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
+ }
@@ -3,7 +3,6 @@ import { AppRegistry, Platform } from 'react-native';
3
3
  import { NitroModules } from 'react-native-nitro-modules';
4
4
  import type { AutoText } from '..';
5
5
  import { MapTemplateProvider } from '../components/MapTemplateContext';
6
- import OnAppearedChildRenderer from '../components/OnAppearedChildRenderer';
7
6
  import { SafeAreaInsetsProvider } from '../components/SafeAreaInsetsContext';
8
7
  import { HybridAutoPlay } from '../hybrid/HybridAutoPlay';
9
8
  import type { MapTemplate as NitroMapTemplate } from '../specs/MapTemplate.nitro';
@@ -197,11 +196,7 @@ export class MapTemplate extends Template<MapTemplateConfig, MapTemplateConfig['
197
196
  children: React.createElement(SafeAreaInsetsProvider, {
198
197
  moduleName: this.id,
199
198
  // biome-ignore lint/correctness/noChildrenProp: there is no other way in a ts file
200
- children: React.createElement(OnAppearedChildRenderer, {
201
- // biome-ignore lint/correctness/noChildrenProp: there is no other way in a ts file
202
- children: React.createElement(component, props),
203
- moduleName: this.id,
204
- }),
199
+ children: React.createElement(component, props),
205
200
  }),
206
201
  })
207
202
  );
@@ -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
+ }
@@ -1,37 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { HybridAutoPlay } from '../hybrid/HybridAutoPlay';
3
- import type { CleanupCallback } from '../types/Event';
4
-
5
- type Props = { children: React.ReactNode; moduleName: string };
6
-
7
- /**
8
- * renders the passed children when the specified scene/screen appeared
9
- * this makes sure child hooks are executed only when the map template is ready
10
- */
11
- export default function OnAppearedChildRenderer({ children, moduleName }: Props) {
12
- const [didAppear, setDidAppear] = useState(false);
13
-
14
- useEffect(() => {
15
- let remove: CleanupCallback | null = HybridAutoPlay.addListenerRenderState(
16
- moduleName,
17
- (renderState) => {
18
- if (renderState === 'didAppear') {
19
- remove?.();
20
- remove = null;
21
- setDidAppear(true);
22
- }
23
- }
24
- );
25
-
26
- return () => {
27
- remove?.();
28
- remove = null;
29
- };
30
- }, [moduleName]);
31
-
32
- if (didAppear) {
33
- return children;
34
- }
35
-
36
- return null;
37
- }