react-native-voice-bot-sdk 0.0.0-stage → 0.1.0

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 (45) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/LICENSE +21 -0
  3. package/README.md +464 -2
  4. package/android/build.gradle +15 -0
  5. package/android/src/main/AndroidManifest.xml +16 -0
  6. package/android/src/main/java/expo/modules/voicebot/VoiceBotAudioModule.kt +416 -0
  7. package/android/src/main/java/expo/modules/voicebot/VoiceBotMicService.kt +107 -0
  8. package/app.plugin.js +1 -0
  9. package/build/NativeAudio.d.ts +24 -0
  10. package/build/NativeAudio.js +1 -0
  11. package/build/VoiceBotClient.d.ts +231 -0
  12. package/build/VoiceBotClient.js +1 -0
  13. package/build/audio/noiseGate.d.ts +83 -0
  14. package/build/audio/noiseGate.js +1 -0
  15. package/build/base64.d.ts +6 -0
  16. package/build/base64.js +1 -0
  17. package/build/expo-router.d.ts +16 -0
  18. package/build/expo-router.js +1 -0
  19. package/build/index.d.ts +20 -0
  20. package/build/index.js +1 -0
  21. package/build/logger.d.ts +35 -0
  22. package/build/logger.js +1 -0
  23. package/build/navigation/callbackNavigation.d.ts +28 -0
  24. package/build/navigation/callbackNavigation.js +1 -0
  25. package/build/navigation/reactNavigation.d.ts +33 -0
  26. package/build/navigation/reactNavigation.js +1 -0
  27. package/build/navigation/state.d.ts +20 -0
  28. package/build/navigation/state.js +1 -0
  29. package/build/navigation/types.d.ts +27 -0
  30. package/build/navigation/types.js +1 -0
  31. package/build/protocol.d.ts +108 -0
  32. package/build/protocol.js +1 -0
  33. package/build/react/VoiceBotProvider.d.ts +52 -0
  34. package/build/react/VoiceBotProvider.js +1 -0
  35. package/build/react/VoiceBotWidget.d.ts +29 -0
  36. package/build/react/VoiceBotWidget.js +1 -0
  37. package/build/react/useVoiceBot.d.ts +17 -0
  38. package/build/react/useVoiceBot.js +1 -0
  39. package/docs/INTEGRATION.md +189 -0
  40. package/docs/PROTOCOL.md +271 -0
  41. package/expo-module.config.json +9 -0
  42. package/ios/VoiceBotAudio.podspec +25 -0
  43. package/ios/VoiceBotAudioModule.swift +219 -0
  44. package/package.json +76 -4
  45. package/plugin/withVoiceBot.js +137 -0
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Wire protocol shared with the voice server. These shapes match what the native Android
3
+ * voice bot app sends, so the same server works for both. See docs/PROTOCOL.md.
4
+ */
5
+ /** Audio format used in both directions: raw PCM s16le, 16 kHz, mono, no header. */
6
+ export declare const SAMPLE_RATE = 16000;
7
+ /** One uplink frame = 20 ms = 320 samples = 640 bytes. */
8
+ export declare const FRAME_BYTES: number;
9
+ /** Bytes of PCM per second (used to estimate how long reply audio plays). */
10
+ export declare const BYTES_PER_SECOND: number;
11
+ /**
12
+ * First (connect) TEXT frame, sent once right after the socket opens and before any audio.
13
+ * It carries the session info and the app's screen names in one message.
14
+ */
15
+ export interface ConnectMessage {
16
+ sessionId: string;
17
+ /** Host app's domain / tenant id (from `connect({ domainId })`). */
18
+ domain_id: string;
19
+ /** Visitor id (from `connect({ cookieId })`, or a random id kept for the app run). */
20
+ cookie_id: string;
21
+ type: 'Buffer';
22
+ deviceId: number;
23
+ sampleRate: number;
24
+ /** Route names; use one of these as `screen` in a `navigate` command. Names only, never code or data. */
25
+ screens: string[];
26
+ }
27
+ /** @deprecated Old name of {@link ConnectMessage}. */
28
+ export type MetadataMessage = ConnectMessage;
29
+ /** One navigable UI screen (a route). Names only: never code or data. */
30
+ export interface ScreenInfo {
31
+ /** Stable route name, e.g. `products`, `(tabs)/index`, `ProductDetails`. */
32
+ name: string;
33
+ /** URL path when the router has one, e.g. `/products` or `/product/[id]`. */
34
+ path?: string;
35
+ }
36
+ /**
37
+ * Only sent if the app registers different navigation while a session is already open,
38
+ * so the server's screen list stays correct. Not sent in a normal session.
39
+ */
40
+ export interface ScreensUpdateMessage {
41
+ type: 'screens';
42
+ sessionId: string;
43
+ screens: string[];
44
+ }
45
+ /** Optional uplink format when `uplinkEncoding: 'base64'` is chosen (TEXT frame). */
46
+ export interface AudioTextMessage {
47
+ type: 'audio';
48
+ sessionId: string;
49
+ seq: number;
50
+ sampleRate: number;
51
+ /** base64 of exactly 640 bytes of PCM s16le 16 kHz mono. */
52
+ data: string;
53
+ }
54
+ export interface BotOutput {
55
+ suggestions?: string[];
56
+ prompt?: string;
57
+ intent?: string;
58
+ message?: string;
59
+ error?: number | string;
60
+ /** `"navigation"` when the reply opens a screen, otherwise `"none"`. */
61
+ type?: string;
62
+ /** Screen to open (one of the `screens` names, or `"back"`). Checked first. */
63
+ screen?: string;
64
+ /** Same screen name (older field). Used when `screen` is empty. */
65
+ class_name?: string;
66
+ /** Same screen name (older field). Used when `screen` and `class_name` are empty. */
67
+ target?: string;
68
+ [key: string]: unknown;
69
+ }
70
+ /** Server → app reply. `buffer` is base64 raw PCM s16le 16 kHz mono (no WAV header). */
71
+ export interface BotReply {
72
+ session_id?: string;
73
+ question?: string;
74
+ output?: BotOutput;
75
+ buffer?: string;
76
+ /** Sample rate of `buffer` in Hz (8000-48000). Missing = 16000. */
77
+ sample_rate?: number;
78
+ [key: string]: unknown;
79
+ }
80
+ /** Server → app: open a screen, or go back. */
81
+ export interface NavigateCommand {
82
+ type: 'navigate';
83
+ screen?: string;
84
+ action?: 'open' | 'back';
85
+ params?: Record<string, string | number>;
86
+ requestId?: string | number;
87
+ }
88
+ export type NavigateStatus = 'opened' | 'went_back' | 'already_on_screen' | 'unknown_screen' | 'not_supported' | 'failed';
89
+ /** App → server answer to a `navigate` command. */
90
+ export interface NavigateResultMessage {
91
+ type: 'navigate_result';
92
+ sessionId: string;
93
+ screen: string | null;
94
+ action: 'open' | 'back';
95
+ /** Full route name that was acted on (`null` for unknown screens). Named like the Android field. */
96
+ className: string | null;
97
+ status: NavigateStatus;
98
+ message: string;
99
+ requestId: string | number | null;
100
+ }
101
+ /** App → server: sent every time a different screen comes to the front. */
102
+ export interface ScreenChangedMessage {
103
+ type: 'screen_changed';
104
+ sessionId: string;
105
+ screen: string;
106
+ /** Bottom → top; the last item is the visible screen. */
107
+ backStack: string[];
108
+ }
@@ -0,0 +1 @@
1
+ export const SAMPLE_RATE=16e3;export const FRAME_BYTES=640;export const BYTES_PER_SECOND=32e3;
@@ -0,0 +1,52 @@
1
+ import React, { type ReactNode } from 'react';
2
+ import type { NavigationAdapter } from '../navigation/types';
3
+ import type { BotReply } from '../protocol';
4
+ import { type ConnectOptions, type VoiceBotError } from '../VoiceBotClient';
5
+ import { type VoiceBotWidgetProps } from './VoiceBotWidget';
6
+ export interface VoiceBotProviderProps {
7
+ children?: ReactNode;
8
+ /**
9
+ * Voice server WebSocket URL, e.g. `wss://voice.example.com/demo`. When set, the provider
10
+ * connects by itself (see `autoConnect`), so wrapping the app is all the setup you need.
11
+ * Leave it out to connect yourself with `VoiceBot.connect()` / `useVoiceBot().connect()`.
12
+ */
13
+ url?: string;
14
+ /** Your domain / tenant id, sent as `domain_id`. */
15
+ domainId?: string;
16
+ /** Connect as soon as the provider mounts (when `url` is set). Default `true`. */
17
+ autoConnect?: boolean;
18
+ /**
19
+ * The floating mic button. Default `true` (drop-in voice widget, bottom-right). Pass an object to
20
+ * style it, or `false` to use your own button with `useVoiceBot().start()` / `stop()`.
21
+ */
22
+ widget?: boolean | VoiceBotWidgetProps;
23
+ /** Lets the server open your screens by voice. See `useExpoRouterNavigation()`. */
24
+ navigation?: NavigationAdapter | null;
25
+ /** Connected; the connect message (with your screen names) was sent. */
26
+ onConnect?(info: {
27
+ sessionId: string;
28
+ }): void;
29
+ /** Could not connect, or reconnecting gave up. */
30
+ onError?(error: VoiceBotError): void;
31
+ /** The connection closed. */
32
+ onClose?(info: {
33
+ code: number;
34
+ reason: string;
35
+ }): void;
36
+ /** Every reply from the server (what the user said, the bot's answer, its audio). */
37
+ onReply?(reply: BotReply): void;
38
+ /** Every JSON message from the server (replies, navigate commands, custom messages). */
39
+ onMessage?(message: Record<string, unknown>): void;
40
+ /** Advanced options, the same as `VoiceBot.connect()` (noise gate, barge-in, reconnect, logs ...). */
41
+ options?: Omit<ConnectOptions, 'url' | 'domainId' | 'onSuccess' | 'onFailure' | 'onClose' | 'onReply'>;
42
+ /** Disconnect when the provider unmounts. Default `true`. */
43
+ disconnectOnUnmount?: boolean;
44
+ }
45
+ /**
46
+ * Wrap your app once. With `url` it connects to your voice server and shows the floating mic:
47
+ *
48
+ * <VoiceBotProvider url="wss://voice.example.com/demo" domainId="your-domain-id" navigation={navigation}>
49
+ * <App />
50
+ * </VoiceBotProvider>
51
+ */
52
+ export declare function VoiceBotProvider({ children, url, domainId, autoConnect, widget, navigation, onConnect, onError, onClose, onReply, onMessage, options, disconnectOnUnmount, }: VoiceBotProviderProps): React.JSX.Element;
@@ -0,0 +1 @@
1
+ import{jsx as o,jsxs as n}from"react/jsx-runtime";import{useEffect as e,useRef as r}from"react";import{StyleSheet as t,View as i}from"react-native";import{VoiceBot as s}from"../VoiceBotClient";import{VoiceBotWidget as c}from"./VoiceBotWidget";export function VoiceBotProvider({children:t,url:a,domainId:u,autoConnect:p=!0,widget:d=!0,navigation:m=null,onConnect:f,onError:C,onClose:g,onReply:y,onMessage:v,options:x,disconnectOnUnmount:M=!0}){const R=r({onConnect:f,onError:C,onClose:g,onReply:y,onMessage:v,options:x});return R.current={onConnect:f,onError:C,onClose:g,onReply:y,onMessage:v,options:x},e((()=>{s.setNavigation(m)}),[m]),e((()=>s.addMessageListener((o=>R.current.onMessage?.(o)))),[]),e((()=>{if(a&&p)return s.connect({...R.current.options,url:a,domainId:u,onSuccess:o=>R.current.onConnect?.(o),onFailure:o=>R.current.onError?.(o),onClose:o=>R.current.onClose?.(o),onReply:o=>R.current.onReply?.(o)}),()=>s.disconnect()}),[a,u,p]),e((()=>()=>{s.setNavigation(null),M&&s.disconnect()}),[M]),n(i,{style:l.fill,children:[t,d?o(c,{..."object"==typeof d?d:{}}):null]})}const l=t.create({fill:{flex:1}});
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { type ViewStyle } from 'react-native';
3
+ export interface VoiceBotWidgetProps {
4
+ /** Button diameter. Default 60. */
5
+ size?: number;
6
+ /** Distance from the right edge. Default 20. */
7
+ right?: number;
8
+ /** Distance from the bottom edge. Default 32 (clear of the Android gesture bar). */
9
+ bottom?: number;
10
+ /** Colors per state. */
11
+ colors?: Partial<{
12
+ idle: string;
13
+ connecting: string;
14
+ listening: string;
15
+ speaking: string;
16
+ icon: string;
17
+ }>;
18
+ /** Called instead of the default toggle (start/stop) when the button is pressed. */
19
+ onPress?(): void;
20
+ style?: ViewStyle;
21
+ /** Accessibility label. Default "Voice assistant". */
22
+ accessibilityLabel?: string;
23
+ }
24
+ /**
25
+ * Floating mic button (bottom-right by default). Tap to start / stop the voice session.
26
+ * Shows a spinner while connecting, a pulsing red ring while listening and green while
27
+ * the bot is speaking.
28
+ */
29
+ export declare function VoiceBotWidget({ size, right, bottom, colors, onPress, style, accessibilityLabel, }: VoiceBotWidgetProps): React.JSX.Element;
@@ -0,0 +1 @@
1
+ import{jsx as t,jsxs as e}from"react/jsx-runtime";import{useEffect as i,useRef as o}from"react";import{ActivityIndicator as n,Animated as s,Easing as r,Pressable as a,StyleSheet as c,View as l}from"react-native";import{useVoiceBot as d}from"./useVoiceBot";const g={idle:"#3B5BDB",connecting:"#868E96",listening:"#E03131",speaking:"#2F9E44",icon:"#FFFFFF"};function u({size:i,color:o}){const n=.28*i,s=.42*i;return e(l,{style:{alignItems:"center"},children:[t(l,{style:{width:n,height:s,borderRadius:n/2,backgroundColor:o}}),t(l,{style:{width:1.7*n,height:.45*s,marginTop:.28*-s,borderBottomLeftRadius:n,borderBottomRightRadius:n,borderWidth:Math.max(2,.04*i),borderTopWidth:0,borderColor:o}}),t(l,{style:{width:Math.max(2,.04*i),height:.08*i,backgroundColor:o}})]})}export function VoiceBotWidget({size:c=60,right:b=20,bottom:p=32,colors:m,onPress:y,style:f,accessibilityLabel:w="Voice assistant"}){const R=d(),k={...g,...m},C=o(new s.Value(0)).current,v=R.isListening||R.speaking;i((()=>{if(!v)return C.stopAnimation(),void C.setValue(0);const t=s.loop(s.timing(C,{toValue:1,duration:1200,easing:r.out(r.ease),useNativeDriver:!0}));return t.start(),()=>t.stop()}),[v,C]);const x=R.speaking?k.speaking:"listening"===R.status?k.listening:"connecting"===R.status?k.connecting:k.idle;return e(l,{pointerEvents:"box-none",style:[h.container,{right:b,bottom:p},f],children:[v&&t(s.View,{pointerEvents:"none",style:[h.ring,{width:c,height:c,borderRadius:c/2,backgroundColor:x,opacity:C.interpolate({inputRange:[0,1],outputRange:[.45,0]}),transform:[{scale:C.interpolate({inputRange:[0,1],outputRange:[1,1.7]})}]}]}),t(a,{accessibilityRole:"button",accessibilityLabel:w,accessibilityState:{busy:"connecting"===R.status,selected:R.isListening},onPress:y??(()=>{R.toggle()}),style:({pressed:t})=>[h.button,{width:c,height:c,borderRadius:c/2,backgroundColor:x,opacity:t?.85:1}],children:"connecting"===R.status?t(n,{color:k.icon}):R.isListening?t(l,{style:{width:.3*c,height:.3*c,borderRadius:4,backgroundColor:k.icon}}):t(u,{size:c,color:k.icon})})]})}const h=c.create({container:{position:"absolute",zIndex:9999,elevation:12,alignItems:"center",justifyContent:"center"},ring:{position:"absolute"},button:{alignItems:"center",justifyContent:"center",shadowColor:"#000",shadowOpacity:.25,shadowRadius:6,shadowOffset:{width:0,height:3},elevation:8}});
@@ -0,0 +1,17 @@
1
+ import { VoiceBot, type VoiceBotState } from '../VoiceBotClient';
2
+ export interface UseVoiceBot extends VoiceBotState {
3
+ isConnected: boolean;
4
+ isListening: boolean;
5
+ /** Same as `isConnected`: the bot is ready to listen. */
6
+ isReady: boolean;
7
+ /** Same as `lastError`. */
8
+ error: VoiceBotState['lastError'];
9
+ connect: typeof VoiceBot.connect;
10
+ disconnect: typeof VoiceBot.disconnect;
11
+ start: typeof VoiceBot.start;
12
+ stop: typeof VoiceBot.stop;
13
+ toggle: typeof VoiceBot.toggle;
14
+ addMessageListener: typeof VoiceBot.addMessageListener;
15
+ }
16
+ /** React hook for the shared voice bot session. Re-renders on every state change. */
17
+ export declare function useVoiceBot(): UseVoiceBot;
@@ -0,0 +1 @@
1
+ import{useSyncExternalStore as t}from"react";import{VoiceBot as e}from"../VoiceBotClient";export function useVoiceBot(){const s=t(e.subscribe,e.getState,e.getState);return{...s,isConnected:"connected"===s.status||"listening"===s.status,isListening:"listening"===s.status,isReady:"connected"===s.status||"listening"===s.status,error:s.lastError,connect:e.connect,disconnect:e.disconnect,start:e.start,stop:e.stop,toggle:e.toggle,addMessageListener:e.addMessageListener}}
@@ -0,0 +1,189 @@
1
+ # Integration guide
2
+
3
+ Add a voice assistant to your React Native or Expo app in about 10 minutes. You need the URL of your
4
+ voice server (for example `wss://voice.example.com/demo`) and your domain id.
5
+
6
+ ## 1. Requirements
7
+
8
+ | | |
9
+ |---|---|
10
+ | Expo | SDK 52 or newer, with a **development build** (`npx expo run:android`, `npx expo run:ios` or EAS Build). Expo Go can't load the SDK's native audio module. |
11
+ | Bare React Native | 0.76 or newer (Expo modules SDK 52+) with Expo modules installed (`npx install-expo-modules@latest`). |
12
+ | Android | 7.0 (API 24) or newer. Tested on Android 16 (Pixel 7). |
13
+ | iOS | 16.4 or newer. **Not tested on a device yet** in this release. |
14
+ | Server | A voice server that speaks the protocol in [PROTOCOL.md](PROTOCOL.md), over `wss://` with a certificate from a public authority for release builds. |
15
+
16
+ ## 2. Install
17
+
18
+ ```bash
19
+ npx expo install react-native-voice-bot-sdk
20
+ ```
21
+
22
+ Bare React Native: `npm install react-native-voice-bot-sdk`, then `cd ios && pod install`.
23
+
24
+ ## 3. Add the config plugin (Expo)
25
+
26
+ In `app.json` / `app.config.js`:
27
+
28
+ ```json
29
+ {
30
+ "expo": {
31
+ "plugins": [
32
+ ["react-native-voice-bot-sdk", {
33
+ "microphonePermission": "Allow $(PRODUCT_NAME) to use the microphone for the voice assistant"
34
+ }]
35
+ ]
36
+ }
37
+ }
38
+ ```
39
+
40
+ It adds the microphone permission on Android and iOS. Other options:
41
+
42
+ | Option | When to use it |
43
+ |--------|----------------|
44
+ | `allowCleartextTraffic: true` | Your server URL is `ws://` (not `wss://`), e.g. a local test server. |
45
+ | `trustedCertificates: ["./certs/server.pem"]` | Your **test** server uses a self-signed certificate. Android dev builds only. |
46
+
47
+ Then rebuild the native app:
48
+
49
+ ```bash
50
+ npx expo prebuild --clean
51
+ ```
52
+
53
+ ```bash
54
+ npx expo run:android
55
+ ```
56
+
57
+ **Bare React Native:** the library's Android manifest adds the permissions by itself. On iOS add
58
+ `NSMicrophoneUsageDescription` to `Info.plist`.
59
+
60
+ ## 4. Wrap your app
61
+
62
+ This is all you need for the **widget-only** integration: a floating mic button, bottom-right.
63
+
64
+ **Expo Router** (`app/_layout.tsx`):
65
+
66
+ ```tsx
67
+ import { Stack } from 'expo-router';
68
+ import { VoiceBotProvider } from 'react-native-voice-bot-sdk';
69
+ import { useExpoRouterNavigation } from 'react-native-voice-bot-sdk/expo-router';
70
+
71
+ export default function RootLayout() {
72
+ const navigation = useExpoRouterNavigation();
73
+ return (
74
+ <VoiceBotProvider url="wss://voice.example.com/demo" domainId="YOUR_DOMAIN_ID" navigation={navigation}>
75
+ <Stack />
76
+ </VoiceBotProvider>
77
+ );
78
+ }
79
+ ```
80
+
81
+ **React Navigation:**
82
+
83
+ ```tsx
84
+ import { NavigationContainer, createNavigationContainerRef } from '@react-navigation/native';
85
+ import { VoiceBotProvider, createReactNavigationAdapter } from 'react-native-voice-bot-sdk';
86
+
87
+ const navigationRef = createNavigationContainerRef();
88
+ const navigation = createReactNavigationAdapter(navigationRef);
89
+
90
+ export default function App() {
91
+ return (
92
+ <VoiceBotProvider url="wss://voice.example.com/demo" domainId="YOUR_DOMAIN_ID" navigation={navigation}>
93
+ <NavigationContainer ref={navigationRef}>{/* your navigators */}</NavigationContainer>
94
+ </VoiceBotProvider>
95
+ );
96
+ }
97
+ ```
98
+
99
+ **No navigation by voice:** leave out `navigation`. The bot still listens and answers.
100
+
101
+ ### What is sent to the server
102
+
103
+ Only the **names of your screens** (route names such as `cart`, `products`, `product/[id]`), never
104
+ code, data or component names. Leave screens out with
105
+ `useExpoRouterNavigation({ exclude: ['settings/billing'] })`.
106
+
107
+ ## 5. Your own button (optional)
108
+
109
+ Hide the widget and use the hook:
110
+
111
+ ```tsx
112
+ <VoiceBotProvider url={URL} domainId={DOMAIN_ID} widget={false}>
113
+ ```
114
+
115
+ ```tsx
116
+ import { useVoiceBot } from 'react-native-voice-bot-sdk';
117
+
118
+ function TalkButton() {
119
+ const { isListening, isReady, start, stop } = useVoiceBot();
120
+ return (
121
+ <Button disabled={!isReady} title={isListening ? 'Stop' : 'Talk'} onPress={isListening ? stop : start} />
122
+ );
123
+ }
124
+ ```
125
+
126
+ ## 6. Events (optional)
127
+
128
+ ```tsx
129
+ <VoiceBotProvider
130
+ url={URL}
131
+ domainId={DOMAIN_ID}
132
+ onConnect={({ sessionId }) => analytics.track('voice_connected', { sessionId })}
133
+ onError={(e) => console.warn('voice bot', e.code, e.message)}
134
+ onReply={(reply) => console.log('user said', reply.question, 'bot said', reply.output?.prompt)}
135
+ onMessage={(msg) => { if (msg.type === 'my_custom_event') { /* … */ } }}
136
+ >
137
+ ```
138
+
139
+ ## 7. Tune it (optional)
140
+
141
+ Pass any `VoiceBot.connect()` option in `options`:
142
+
143
+ ```tsx
144
+ <VoiceBotProvider
145
+ url={URL}
146
+ options={{
147
+ noiseGate: { thresholdDb: 8 }, // more sensitive mic (default 10)
148
+ bargeIn: true, // talking over the bot stops it (default)
149
+ whileSpeaking: 'guard', // ignore the bot's own voice (default)
150
+ backgroundListening: { title: 'Shop assistant', text: 'Listening…' },
151
+ cookieId: currentUser?.visitorId, // your own visitor id (default: saved on the device)
152
+ logLevel: 'debug', // every request and response in the console
153
+ }}
154
+ >
155
+ ```
156
+
157
+ ## 8. Test
158
+
159
+ 1. Run the app on a real phone (the emulator's mic works too, but less like real use).
160
+ 2. Watch the console: with `logLevel: 'debug'` (the default in development) every request (`→ SEND`)
161
+ and response (`← RECV`) is printed. On Android: `adb logcat -s ReactNativeJS VoiceBotAudio`.
162
+ 3. Tap the mic and say something like "open my cart".
163
+
164
+ A small test server (Python 3, no packages) ships in the SDK repository's `test-server/` folder if
165
+ your real server isn't ready.
166
+
167
+ ## 9. Before you release
168
+
169
+ - [ ] The server URL is `wss://` with a certificate from a public authority (Let's Encrypt or
170
+ similar). `trustedCertificates` only works in dev builds.
171
+ - [ ] **Google Play:** the SDK keeps the mic on in the background with a *microphone* foreground
172
+ service. Declare it in Play Console → App content → Foreground service permissions, and
173
+ mention the voice assistant in your privacy policy.
174
+ - [ ] **App Store:** a clear `NSMicrophoneUsageDescription`.
175
+ - [ ] Test on the oldest Android and iOS versions you support.
176
+ - [ ] Set `logLevel: 'warn'` (the default in release builds) so requests aren't logged.
177
+
178
+ ## Troubleshooting
179
+
180
+ | Problem | Cause and fix |
181
+ |---------|---------------|
182
+ | `native_missing` error | Running in Expo Go. Use a development build (`npx expo run:android`). |
183
+ | `Trust anchor for certification path not found` | The server's certificate isn't trusted by the phone (self-signed). Use a public certificate, or `trustedCertificates` for test servers. |
184
+ | `CLEARTEXT communication … not permitted` | `ws://` URL in a release build. Use `wss://`, or `allowCleartextTraffic: true` for testing. |
185
+ | Connects, but the bot never answers | Check the server logs for the `sessionId`. In a noisy room, the server may not detect the end of a sentence; try closer to the phone. |
186
+ | The bot's voice sounds slow or deep | The server's audio sample rate doesn't match `sample_rate` in its replies. |
187
+ | The reply stops by itself | Barge-in: someone talked loudly over it. Use `options={{ bargeIn: false }}` to turn it off. |
188
+ | No mic in the background | Android: allow notifications (Android 13+), and don't turn off `backgroundListening`. iOS: not supported yet. |
189
+ | "App isn't responding" right after starting a dev build | Metro was still building the bundle. Wait or reopen the app; release builds don't do this. |