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

Input device selection is currently only supported on iOS. On Android, useAudioInput is implemented as a no-op: the hook will not list or switch input devices, and any selection calls will effectively be ignored.

Signature

function useAudioInput(): {
availableInputs: AudioDeviceInfo[];
currentInput: AudioDeviceInfo | null;
onSelectInput: (device: AudioDeviceInfo) => 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, onSelectInput } = useAudioInput();

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

{availableInputs.map((input) => (
<Button
key={input.id}
title={`${input.name} (${input.category})`}
onPress={() => onSelectInput(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.
onSelectInput(device: AudioDeviceInfo) => Promise<void>Selects the given device as the current input. Resolves once the device is selected; throws otherwise.
  • AudioManager - For managing audio sessions and permissions
  • AudioRecorder - For capturing audio from the selected input device