From 3f06ff4f522d913e4c1812faf60d739ea2adeffa Mon Sep 17 00:00:00 2001 From: vinayr Date: Sat, 21 Apr 2018 20:51:34 +0900 Subject: [PATCH] first commit --- .eslintignore | 6 + .eslintrc | 16 + .gitattributes | 1 + .gitignore | 46 + .npmignore | 1 + Example/.babelrc | 3 + Example/.buckconfig | 6 + Example/.flowconfig | 54 + Example/.gitattributes | 1 + Example/.gitignore | 56 + Example/.watchmanconfig | 1 + Example/App.js | 102 + Example/android/app/BUCK | 65 + Example/android/app/build.gradle | 152 + Example/android/app/proguard-rules.pro | 70 + .../android/app/src/main/AndroidManifest.xml | 26 + .../main/java/com/audiotest/MainActivity.java | 15 + .../java/com/audiotest/MainApplication.java | 49 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 8 + Example/android/build.gradle | 24 + Example/android/gradle.properties | 20 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 52266 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 + Example/android/gradlew | 164 + Example/android/gradlew.bat | 90 + Example/android/keystores/BUCK | 8 + .../keystores/debug.keystore.properties | 4 + Example/android/settings.gradle | 7 + Example/app.json | 4 + Example/index.js | 4 + Example/ios/AudioTest-tvOS/Info.plist | 54 + Example/ios/AudioTest-tvOSTests/Info.plist | 24 + .../ios/AudioTest.xcodeproj/project.pbxproj | 1646 +++++ .../xcschemes/AudioTest-tvOS.xcscheme | 129 + .../xcshareddata/xcschemes/AudioTest.xcscheme | 129 + Example/ios/AudioTest/AppDelegate.h | 14 + Example/ios/AudioTest/AppDelegate.m | 35 + .../ios/AudioTest/Base.lproj/LaunchScreen.xib | 42 + .../AppIcon.appiconset/Contents.json | 38 + .../AudioTest/Images.xcassets/Contents.json | 6 + Example/ios/AudioTest/Info.plist | 57 + Example/ios/AudioTest/main.m | 16 + Example/ios/AudioTestTests/AudioTestTests.m | 68 + Example/ios/AudioTestTests/Info.plist | 24 + Example/package.json | 28 + Example/yarn.lock | 5583 +++++++++++++++++ LICENSE | 21 + README.md | 55 + android/build.gradle | 35 + android/src/main/AndroidManifest.xml | 5 + .../audiorecord/RNAudioRecordModule.java | 216 + .../audiorecord/RNAudioRecordPackage.java | 25 + index.js | 24 + ios/RNAudioRecord.h | 21 + ios/RNAudioRecord.m | 100 + ios/RNAudioRecord.xcodeproj/project.pbxproj | 259 + package.json | 22 + yarn.lock | 941 +++ 63 files changed, 10628 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 Example/.babelrc create mode 100644 Example/.buckconfig create mode 100644 Example/.flowconfig create mode 100644 Example/.gitattributes create mode 100644 Example/.gitignore create mode 100644 Example/.watchmanconfig create mode 100644 Example/App.js create mode 100644 Example/android/app/BUCK create mode 100644 Example/android/app/build.gradle create mode 100644 Example/android/app/proguard-rules.pro create mode 100644 Example/android/app/src/main/AndroidManifest.xml create mode 100644 Example/android/app/src/main/java/com/audiotest/MainActivity.java create mode 100644 Example/android/app/src/main/java/com/audiotest/MainApplication.java create mode 100644 Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/values/strings.xml create mode 100644 Example/android/app/src/main/res/values/styles.xml create mode 100644 Example/android/build.gradle create mode 100644 Example/android/gradle.properties create mode 100644 Example/android/gradle/wrapper/gradle-wrapper.jar create mode 100644 Example/android/gradle/wrapper/gradle-wrapper.properties create mode 100755 Example/android/gradlew create mode 100644 Example/android/gradlew.bat create mode 100644 Example/android/keystores/BUCK create mode 100644 Example/android/keystores/debug.keystore.properties create mode 100644 Example/android/settings.gradle create mode 100644 Example/app.json create mode 100644 Example/index.js create mode 100644 Example/ios/AudioTest-tvOS/Info.plist create mode 100644 Example/ios/AudioTest-tvOSTests/Info.plist create mode 100644 Example/ios/AudioTest.xcodeproj/project.pbxproj create mode 100644 Example/ios/AudioTest.xcodeproj/xcshareddata/xcschemes/AudioTest-tvOS.xcscheme create mode 100644 Example/ios/AudioTest.xcodeproj/xcshareddata/xcschemes/AudioTest.xcscheme create mode 100644 Example/ios/AudioTest/AppDelegate.h create mode 100644 Example/ios/AudioTest/AppDelegate.m create mode 100644 Example/ios/AudioTest/Base.lproj/LaunchScreen.xib create mode 100644 Example/ios/AudioTest/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Example/ios/AudioTest/Images.xcassets/Contents.json create mode 100644 Example/ios/AudioTest/Info.plist create mode 100644 Example/ios/AudioTest/main.m create mode 100644 Example/ios/AudioTestTests/AudioTestTests.m create mode 100644 Example/ios/AudioTestTests/Info.plist create mode 100644 Example/package.json create mode 100644 Example/yarn.lock create mode 100644 LICENSE create mode 100644 README.md create mode 100644 android/build.gradle create mode 100644 android/src/main/AndroidManifest.xml create mode 100644 android/src/main/java/com/goodatlas/audiorecord/RNAudioRecordModule.java create mode 100644 android/src/main/java/com/goodatlas/audiorecord/RNAudioRecordPackage.java create mode 100644 index.js create mode 100644 ios/RNAudioRecord.h create mode 100644 ios/RNAudioRecord.m create mode 100644 ios/RNAudioRecord.xcodeproj/project.pbxproj create mode 100644 package.json create mode 100644 yarn.lock diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..ef354ad --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +android +ios +node_modules +Example/android +Example/ios +Example/node_modules diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..6f459b8 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,16 @@ +{ + "parser": "babel-eslint", + "plugins": ["prettier"], + "env": { + "es6": true + }, + "rules": { + "prettier/prettier": [ + "error", + { + "printWidth": 120, + "singleQuote": true + } + ] + } +} diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..eb39591 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.pbxproj -text \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9cadbfe --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ + +# OSX +# +.DS_Store + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml + +# BUCK +buck-out/ +\.buckd/ +*.keystore + \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..12a719a --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +Example diff --git a/Example/.babelrc b/Example/.babelrc new file mode 100644 index 0000000..a9ce136 --- /dev/null +++ b/Example/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["react-native"] +} diff --git a/Example/.buckconfig b/Example/.buckconfig new file mode 100644 index 0000000..934256c --- /dev/null +++ b/Example/.buckconfig @@ -0,0 +1,6 @@ + +[android] + target = Google Inc.:Google APIs:23 + +[maven_repositories] + central = https://repo1.maven.org/maven2 diff --git a/Example/.flowconfig b/Example/.flowconfig new file mode 100644 index 0000000..7d5e2d3 --- /dev/null +++ b/Example/.flowconfig @@ -0,0 +1,54 @@ +[ignore] +; We fork some components by platform +.*/*[.]android.js + +; Ignore "BUCK" generated dirs +/\.buckd/ + +; Ignore unexpected extra "@providesModule" +.*/node_modules/.*/node_modules/fbjs/.* + +; Ignore duplicate module providers +; For RN Apps installed via npm, "Libraries" folder is inside +; "node_modules/react-native" but in the source repo it is in the root +.*/Libraries/react-native/React.js + +; Ignore polyfills +.*/Libraries/polyfills/.* + +; Ignore metro +.*/node_modules/metro/.* + +[include] + +[libs] +node_modules/react-native/Libraries/react-native/react-native-interface.js +node_modules/react-native/flow/ +node_modules/react-native/flow-github/ + +[options] +emoji=true + +module.system=haste + +munge_underscores=true + +module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' + +module.file_ext=.js +module.file_ext=.jsx +module.file_ext=.json +module.file_ext=.native.js + +suppress_type=$FlowIssue +suppress_type=$FlowFixMe +suppress_type=$FlowFixMeProps +suppress_type=$FlowFixMeState + +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy +suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError + +[version] +^0.67.0 diff --git a/Example/.gitattributes b/Example/.gitattributes new file mode 100644 index 0000000..d42ff18 --- /dev/null +++ b/Example/.gitattributes @@ -0,0 +1 @@ +*.pbxproj -text diff --git a/Example/.gitignore b/Example/.gitignore new file mode 100644 index 0000000..5d64756 --- /dev/null +++ b/Example/.gitignore @@ -0,0 +1,56 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# BUCK +buck-out/ +\.buckd/ +*.keystore + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/ + +*/fastlane/report.xml +*/fastlane/Preview.html +*/fastlane/screenshots + +# Bundle artifact +*.jsbundle diff --git a/Example/.watchmanconfig b/Example/.watchmanconfig new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/Example/.watchmanconfig @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/Example/App.js b/Example/App.js new file mode 100644 index 0000000..159130b --- /dev/null +++ b/Example/App.js @@ -0,0 +1,102 @@ +import React, { Component } from 'react'; +import { AppRegistry, StyleSheet, Text, View, Platform, Alert, TouchableOpacity } from 'react-native'; +import { Button } from 'react-native'; +import { Buffer } from 'buffer'; +import Permissions from 'react-native-permissions'; +import Sound from 'react-native-sound'; +import AudioRecord from 'react-native-audio-record'; + +export default class App extends Component { + state = { + recording: false, + audioFile: '' + }; + + async componentDidMount() { + await this.checkPermission(); + + const options = { + sampleRate: 16000, + channels: 1, + bitsPerSample: 16, + wavFile: 'test.wav' + }; + + AudioRecord.init(options); + + AudioRecord.on('data', data => { + const chunk = Buffer.from(data, 'base64'); + // do something with audio chunk + }); + } + + checkPermission = async () => { + const p = await Permissions.check('microphone'); + console.log('permission check', p); + if (p === 'authorized') return; + this.requestPermission(); + }; + + requestPermission = async () => { + const p = await Permissions.request('microphone'); + console.log('permission request', p); + }; + + start = () => { + console.log('start record'); + this.setState({ recording: true }); + AudioRecord.start(); + }; + + stop = async () => { + if (!this.state.recording) return; + console.log('stop record'); + let audioFile = await AudioRecord.stop(); + console.log('audioFile', audioFile); + this.setState({ audioFile, recording: false }); + }; + + play = () => { + if (!this.state.audioFile) return; + const whoosh = new Sound(this.state.audioFile, '', error => { + if (error) { + console.log('failed to load the sound', error); + return; + } + Sound.setCategory('Playback'); + whoosh.play(success => { + if (success) { + console.log('successfully finished playing'); + } else { + console.log('playback failed due to audio decoding errors'); + } + Sound.setCategory('Record'); + whoosh.release(); + }); + }); + }; + + render() { + const { recording, audioFile } = this.state; + return ( + + +