Expo module for detecting audio input routes on iOS and Android
npm install audio-input-routeAn Expo module for detecting audio input routes on iOS and Android devices. This module allows you to identify which audio input device is currently being used (built-in microphone, Bluetooth headset, wired headphones, etc.) and listen for audio route changes.
``bash`
npm install audio-input-route
or
`bash`
yarn add audio-input-route
After installation, rebuild your app:
`bash`
npx expo prebuild
npx expo run:iosor
npx expo run:android
- 🎤 Detect current audio input route (microphone type)
- 🔄 Listen for audio route change events
- 📱 iOS support with AVAudioSession integration
- 🤖 Android support with AudioManager integration
- 🎧 Support for Bluetooth, wired, and built-in microphones
`javascript
import { getAudioInputRoute } from 'audio-input-route';
const route = await getAudioInputRoute();
console.log(route);
// { portType: "MicrophoneBuiltIn", portName: "iPhone Microphone" }
`
`javascript
import { addAudioRouteChangeListener } from 'audio-input-route';
const subscription = addAudioRouteChangeListener(() => {
console.log('Audio route changed!');
// Get the new route
getAudioInputRoute().then(route => {
console.log('New route:', route);
});
});
// Don't forget to remove the listener when done
subscription.remove();
`
Returns a Promise that resolves to an object containing:
- portType: The type of audio input port (e.g., "MicrophoneBuiltIn", "BluetoothHFP", "MicrophoneWired")portName
- : The human-readable name of the input device
Adds a listener that will be called whenever the audio route changes (e.g., when plugging in headphones or connecting Bluetooth).
Returns a subscription object with a remove() method to unsubscribe.
- Built-in device microphone
- BluetoothHFP - Bluetooth hands-free profile
- BluetoothA2DP - Bluetooth A2DP
- MicrophoneWired - Wired headset microphone
- HeadsetMic - Headset microphone$3
- MicrophoneBuiltIn - Built-in device microphone
- BluetoothSCO - Bluetooth SCO (voice calls)
- BluetoothA2DP - Bluetooth A2DP (high quality audio)
- MicrophoneWired - Wired headset microphone
- USBDevice - USB audio device
- USBHeadset - USB headsetRequirements
- iOS 13.0 or higher
- Android 6.0 (API 23) or higher
- Expo SDK 47 or higher
- React Native project with Expo modules
$3
#### iOS
Add to your
app.json or Info.plist:
`json
{
"expo": {
"ios": {
"infoPlist": {
"NSMicrophoneUsageDescription": "This app needs access to the microphone to detect audio input routes."
}
}
}
}
`#### Android
The required permission is automatically added via the module's AndroidManifest.xml:
-
MODIFY_AUDIO_SETTINGS`MIT © moritouch
Contributions are welcome! Please feel free to submit a Pull Request.