jsierles/react-native-audio

Name: react-native-audio

Description: Audio recorder library for React Native

Created: 2015-04-15 16:16:51.0

Updated: 2018-01-19 00:29:13.0

Pushed: 2018-01-17 01:58:18.0

Homepage: null

Size: 530

Language: Objective-C

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Record audio in iOS or Android React Native apps.

BREAKING CHANGES

For React Native >= 0.47.2, use v3.4.0 and up. For React Native >= 0.40, use v3.1.0 up til 3.2.2. For React Native <= 0.39, use v3.0.0 or lower.

v3.x removed playback support in favor of using more mature libraries like react-native-sound. If you need to play from the network, please submit a PR to that project or try react-native-video.

Installation

Install the npm package and link it to your project:

install react-native-audio --save
t-native link react-native-audio

On iOS you need to add a usage description to Info.plist:

>NSMicrophoneUsageDescription</key>
ing>This sample uses the microphone to record your speech and convert it to text.</string>

On Android you need to add a permission to AndroidManifest.xml:

s-permission android:name="android.permission.RECORD_AUDIO" />
Manual Installation on Android

This is not necessary if you have used react-native link

Edit android/settings.gradle to declare the project directory:

ude ':react-native-audio'
ect(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android')

Edit android/app/build.gradle to declare the project dependency:

ndencies {
.
mpile project(':react-native-audio')

Edit android/app/src/main/java/.../MainApplication.java to register the native module:


rt com.rnim.rn.audio.ReactNativeAudioPackage; // <-- New


ic class MainApplication extends Application implements ReactApplication {
.
verride
otected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    new ReactNativeAudioPackage() // <-- New
);

Running the Sample App

In the AudioExample directory:

install
t-native run-ios
t-native run-android
Usage

To record in AAC format, at 22050 KHz in low quality mono:

rt {AudioRecorder, AudioUtils} from 'react-native-audio';
audioPath = AudioUtils.DocumentDirectoryPath + '/test.aac';

oRecorder.prepareRecordingAtPath(audioPath, {
mpleRate: 22050,
annels: 1,
dioQuality: "Low",
dioEncoding: "aac"

Cross-platform options
leRate: int
nels: int
oQuality: string
oEncoding: string

Encodings supported on iOS: lpcm, ima4, aac, MAC3, MAC6, ulaw, alaw, mp1, mp2, alac, amr Encodings supported on Android: aac, aac_eld, amr_nb, amr_wb, he_aac, vorbis

iOS-only fields

The MeteringEnabled boolean to enable audio metering.

Android-only fields

AudioEncodingBitRate: int OutputFormat: string, mpeg_4, aac_adts, amr_nb, amr_wb, three_gpp, webm

See the example for more details. For playing audio check out React Native Sound

MP3 recording is not supported since the underlying platforms do not support it.

Thanks to Brent Vatne, Johannes Lumpe, Kureev Alexey, Matthew Hartman and Rakan Nimer for their assistance.

Progress tracking code borrowed from https://github.com/brentvatne/react-native-video.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.