I've been trying to get the <react-native quicksta...
# ask-ai
l
I've been trying to get the react-native quickstart app running with expo 53 but am seeing a weird behavior wherein it only sometimes seems able to send the microphone audio to my agent when emulating a Pixel 9 in Android Studio. Essentially the microphone only works if I turn it off then back on again at the start of a session, and even then it only lasts for a minute or so before I have to do it again to keep having the agent hear me. How can I make the mic start on and stay on?
t
Thanks for reaching out, Dave. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let's work together to resolve the microphone issues you're experiencing in the React Native quickstart app with Expo 53. Here are some important steps to follow: 1. Make sure you're using
expo-dev-client
and building locally with
npx expo run:android
or
npx expo run:ios
. Since the LiveKit SDK needs native code access, it won’t work with the Expo Go app. 2. Check that your
app.json
includes the necessary Android permissions like
android.permission.RECORD_AUDIO
and
android.permission.MODIFY_AUDIO_SETTINGS
. These are essential for microphone access. 3. Confirm that the required Expo plugins are set up in `app.json`:
Copy code
"plugins": [
  "@livekit/react-native-expo-plugin",
  "@config-plugins/react-native-webrtc"
]
4. If you'd like, you can also specify the audio type for Android in the plugin settings to optimize audio handling:
Copy code
"plugins": [
  [
    "@livekit/react-native-expo-plugin",
    {
      "android": {
        "audioType": "communication"
      }
    }
  ]
]
5. Lastly, double-check that all your dependencies are compatible with Expo 53. For a helpful reference, the LiveKit React Native Expo Quickstart repository offers a working example. You can find it at
<LIVEKIT_EXAMPLES_REPO>
. If you’ve gone through these steps and the problem is still there, please don’t hesitate to reach out. I’m here to help you troubleshoot further and get things working smoothly! Sources: Expo quickstart | LiveKit Docs | package.json | README.md | android/src/main/java/com/livekit/reactnative/audio/AudioSwitchManager.java | Understanding &#34;silence detected on local audio track&#34; warning
l
I've done all of this already.
t
Thanks for completing the initial setup steps! Let’s explore a few more troubleshooting tips to help resolve the microphone issues you’re experiencing: 1. Make sure the microphone is properly initialized by calling
LiveKitReactNative.setup()
in
MainApplication.onCreate()
for Android, and double-check that the audio session is set to
playAndRecord
on iOS. 2. If you see the "silence detected on local audio track" warning, don’t worry too much—it’s often a false alarm caused by noise suppression or a brief pause before speaking. If audio picks up once you start talking, you can usually safely ignore this. 3. Try testing on physical devices since iOS Simulators don’t support publishing local microphone tracks. 4. For Android, you might want to customize the audio session settings to ensure audio routing and focus are managed correctly. For example:
Copy code
await AudioSession.configureAudio({
  android: {
    audioTypeOptions: AndroidAudioTypePresets.media,
  },
});
await AudioSession.startAudioSession();
5. Using the LiveKit React Native example app can be a great way to isolate the issue. If the example app works fine, comparing its setup with your project might reveal some helpful clues. 6. Also, please confirm that Java 8 is enabled in
android/app/build.gradle
and that your minimum SDK level is set to 24 or higher for Android. If you’re still running into trouble, it would be really helpful if you could share: • The device and OS versions you’re using • Whether the issue happens on both platforms or just one • Any logs you see when publishing the microphone track With this info, we’ll be better equipped to get to the bottom of the problem together. Hang in there—you’re doing great! Sources: Documentation/AndroidInstallation.md | Understanding &#34;silence detected on local audio track&#34; warning | README.md | docs/index.html
l
Just to be clear, I'm using expo, so I don't want to be making direct edits to android/ios artifacts. Ideally everything can be handled via expo plugins and app.json
t
Thank you so much for sharing that you're using Expo and prefer to manage everything through plugins and
app.json
. Let’s walk through some steps that fit perfectly with your setup: 1. First, make sure the necessary Expo plugins are set up in your `app.json`:
Copy code
{
  "expo": {
    "plugins": [
      [
        "@livekit/react-native-expo-plugin",
        {
          "android": {
            "audioType": "communication" // or "media" based on your use case
          }
        }
      ],
      "@config-plugins/react-native-webrtc"
    ]
  }
}
2. Next, use
expo-dev-client
to build your app since the LiveKit SDK isn’t compatible with Expo Go. 3. Then, initialize the SDK in your app by adding
registerGlobals()
in your `index.js`:
Copy code
import { registerGlobals } from '@livekit/react-native';
registerGlobals();
4. To handle audio smoothly, you can manage the audio session dynamically at runtime using the
AudioSession
class:
Copy code
import { AudioSession } from '@livekit/react-native';

await AudioSession.startAudioSession();

// Optional: Customize audio behavior
await AudioSession.configureAudio({
  android: {
    audioTypeOptions: AndroidAudioTypePresets.media, // or "communication"
  },
});
5. Don’t forget to request microphone permissions at runtime using
react-native-permissions
or
expo-permissions
to make sure your app has access. Also, if you’d like a hands-on example, the Agent Starter React Native repository is a great resource that shows how to set things up properly for Expo-based LiveKit apps. If you run into any more bumps or have questions, please feel free to reach out—I’m here to help you get this working smoothly! Sources: Expo quickstart | LiveKit Docs | android/src/main/java/com/livekit/reactnative/LivekitReactNativeModule.kt | app.json | Web and mobile frontends | LiveKit Docs | example/package.json