audio-input-route
v1.1.4
Published
Expo module for detecting audio input routes on iOS and Android
Maintainers
Readme
audio-input-route
An 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.
Installation
npm install audio-input-routeor
yarn add audio-input-routeAfter installation, rebuild your app:
npx expo prebuild
npx expo run:ios
# or
npx expo run:androidFeatures
- 🎤 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
Usage
Get Current Audio Input Route
import { getAudioInputRoute } from 'audio-input-route';
const route = await getAudioInputRoute();
console.log(route);
// { portType: "MicrophoneBuiltIn", portName: "iPhone Microphone" }Listen for Audio Route Changes
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();API
getAudioInputRoute()
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
addAudioRouteChangeListener(listener)
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.
Common Port Types
iOS
MicrophoneBuiltIn- Built-in device microphoneBluetoothHFP- Bluetooth hands-free profileBluetoothA2DP- Bluetooth A2DPMicrophoneWired- Wired headset microphoneHeadsetMic- Headset microphone
Android
MicrophoneBuiltIn- Built-in device microphoneBluetoothSCO- Bluetooth SCO (voice calls)BluetoothA2DP- Bluetooth A2DP (high quality audio)MicrophoneWired- Wired headset microphoneUSBDevice- USB audio deviceUSBHeadset- USB headset
Requirements
- iOS 13.0 or higher
- Android 6.0 (API 23) or higher
- Expo SDK 47 or higher
- React Native project with Expo modules
Permissions
iOS
Add to your app.json or Info.plist:
{
"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
License
MIT © moritouch
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
