2 Star 0 Fork 0

UnPourTous / react-native-audio

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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:

npm install react-native-audio --save
react-native link react-native-audio

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

<key>NSMicrophoneUsageDescription</key>
<string>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:

<uses-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:

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

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

dependencies {
  ...
  compile project(':react-native-audio')
}

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

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

public class MainApplication extends Application implements ReactApplication {
  ...
  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new ReactNativeAudioPackage() // <-- New
    );
  }

Running the Sample App

In the AudioExample directory:

npm install
react-native run-ios
react-native run-android

Usage

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

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

AudioRecorder.prepareRecordingAtPath(audioPath, {
  SampleRate: 22050,
  Channels: 1,
  AudioQuality: "Low",
  AudioEncoding: "aac"
});

Cross-platform options

SampleRate: int
Channels: int
AudioQuality: string
AudioEncoding: 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.

The MIT License (MIT) Copyright (c) [2016] [Joshua Sierles] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/UnPourTous/react-native-audio.git
git@gitee.com:UnPourTous/react-native-audio.git
UnPourTous
react-native-audio
react-native-audio
master

搜索帮助