okgrow/react-native-audio

Name: react-native-audio

Owner: OK GROW!

Description: Audio recorder library for React Native

Forked from: jsierles/react-native-audio

Created: 2017-11-01 13:50:39.0

Updated: 2017-11-01 13:50:40.0

Pushed: 2017-11-17 14:07:30.0

Homepage: null

Size: 539

Language: Objective-C

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

OK GROW FORK:

This fork adds ability to also record from Bluetooth as well.

Here's how you can use it:

t path = `${AudioUtils.DocumentDirectoryPath}/file.aac`;

t inputs = await AudioRecorder.getAvailableInputs();

ole.log(inputs);

(let input of inputs) {
 (/LOTUS/.test(input.name)) {
await AudioRecorder.prepareRecordingAtPath(path, {
  preferredInput: input.id,
  // ... other options such as sample rate, etc.
});


The AudioRecorder.getAvailableInputs() returns a list of available recording devices like this:

id: 'Built-In Microphone',
type: 'builtInMic',
name: 'iPhone Microphone' },
id: 'D4:F5:11:50:8A:22',
type: 'bluetoothHFP',
name: 'LOTUS 1.7-12311' } ]

Original Readme:

Record audio in iOS or Android React Native apps.

BREAKING CHANGES

For React Native >= 0.40, use v3.1.0 and up. 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.