react-native-audio-api is a high-performance audio engine for React Native that implements a significant portion of the Web Audio API specification, allowing developers to create and manipulate audio graphs in a cross-platform manner (iOS, Android, and Web). The library enables advanced audio functionalities such as sound synthesis, real-time effects processing using various audio nodes (e.g., OscillatorNode, GainNode, BiquadFilterNode), microphone input, audio recording to files, HLS streaming, and audio visualization. Currently at version 0.11.7, it receives frequent patch updates addressing bugs and adding minor features, demonstrating active development. Its core differentiator is the adherence to the Web Audio API, offering a familiar interface for web developers moving to React Native for complex audio tasks, unlike simpler audio playback libraries.
npm install react-native-audio-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart code initializes an `AudioContext` and creates a simple audio graph to generate and play a 440 Hz sine wave, demonstrating basic sound synthesis and control. It also includes an example of requesting necessary microphone permissions using `react-native-permissions` for more advanced use cases like recording.
Review the official migration guide or example applications on the GitHub repository. The removal of the metro-config wrapper suggests a simplified or standard Metro setup, but context refactoring may require changes to audio graph initialization and management logic.
Always create a new `OscillatorNode` or `AudioBufferSourceNode` instance each time you intend to play a sound. Disconnect and dereference old nodes if they are no longer needed to prevent memory leaks.
For Android, add `<uses-permission android:name="android.permission.RECORD_AUDIO" />` and `FOREGROUND_SERVICE_MEDIA_PLAYBACK` (if applicable) to `AndroidManifest.xml`. For iOS, add `NSMicrophoneUsageDescription` to `Info.plist` and ensure background audio modes are enabled for background playback. Use a library like `react-native-permissions` for runtime permission requests.
Consult the 'Web Audio API coverage' documentation to verify if a specific node or interface is implemented and supported across all target platforms before relying on it. If a crucial interface is missing, consider alternative approaches or contributing to the library.
Update your import statements to use ES module syntax: `import { SomeModule } from 'react-native-audio-api';`.For iOS, navigate to the `ios` directory and run `pod install`, then rebuild your project. For Android, ensure `react-native autolink` runs correctly during your build process. Clear Metro bundler cache if issues persist.
Ensure the app has completely loaded before attempting to create an `AudioContext`. If using Expo, ensure you are using a development build. Verify `react-native-audio-api` is properly linked. Delay `AudioContext` creation until essential app components are mounted.