Skip to main content
Version: Next

useAudioInput


A React hook for managing audio input device selection and monitoring available audio input devices. The current input will be available after the first activation of the audio session. Not all connected devices might be listed as available inputs; some might be filtered out as incompatible with the current session configuration.

The useAudioInput hook provides an interface for:

  • retrieving all available audio input devices
  • getting the currently active input device
  • switching between different input devices
Platform support

On Android, currentInput is null whenever the system picks the input: before a device is selected through this hook, after selectInput('default'), and after the selected device is disconnected. The platform does not report which device it would choose on its own.

Signature​

function useAudioInput(): {
availableInputs: AudioDeviceInfo[];
currentInput: AudioDeviceInfo | null;
selectInput: (device: AudioDeviceInfo | 'default') => Promise<void>;
}

Usage​

import React from 'react';
import { View, Text, Button } from 'react-native';
import { useAudioInput } from 'react-native-audio-api';

function AudioInputSelector() {
const { availableInputs, currentInput, selectInput } = useAudioInput();

return (
<View>
<Text>Current Input: {currentInput?.name || 'System default'}</Text>

<Button title="System default" onPress={() => selectInput('default')} />

{availableInputs.map((input) => (
<Button
key={input.id}
title={`${input.name} (${input.category})`}
onPress={() => selectInput(input)}
/>
))}
</View>
);
}

Return value​

Returns an object with the following properties:​

NameTypeDescription
availableInputsAudioDeviceInfo[]List of available audio input devices under the current device configuration.
currentInputAudioDeviceInfo | nullThe currently selected audio input device, or null if none is yet selected by the system.
selectInput(device: AudioDeviceInfo | 'default') => Promise<void>Selects the given device as the current input; 'default' hands the choice back to the system. Resolves once done; throws otherwise.
  • AudioManager - For managing audio sessions and permissions
  • AudioRecorder - For capturing audio from the selected input device