@quranlingoapp/react-native-live-audio-stream 0.0.0-stage → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Qi Xi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,95 @@
1
- # Temporary Holding Version
1
+ # QuranLingo live audio stream fork
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Published as `@quranlingoapp/react-native-live-audio-stream`. This fork maintains
4
+ microphone lifecycle fixes for QuranLingo. The original MIT licence and author
5
+ attribution are preserved. Native module and CocoaPods names remain `RNLiveAudioStream`.
6
+
7
+ Install with an alias to preserve the existing JavaScript imports:
8
+
9
+ ```bash
10
+ npm install --save-exact react-native-live-audio-stream@npm:@quranlingoapp/react-native-live-audio-stream@1.1.2
11
+ ```
12
+
13
+ Rebuild the native app after installation. Do not apply the old mobile
14
+ `react-native-live-audio-stream+1.1.1.patch` to this fork.
15
+
16
+ ## Original documentation
17
+
18
+
19
+ # react-native-live-audio-stream
20
+ [![npm](https://img.shields.io/npm/v/react-native-live-audio-stream)](https://www.npmjs.com/package/react-native-live-audio-stream)
21
+
22
+ Get live audio stream data for React Native. Ideal for live voice recognition (transcribing).
23
+
24
+ This module is modified from [react-native-audio-record](https://github.com/goodatlas/react-native-audio-record). Instead of saving to an audio file, it only emit events with live data. By doing this, it can reduce memory usage and eliminate file operation overheads in the case that an audio file is not necessary (e.g. live transcribing).
25
+
26
+ Most of the code was written by the respective original authors.
27
+
28
+ ## Install
29
+ ```
30
+ yarn add react-native-live-audio-stream
31
+ cd ios
32
+ pod install
33
+ ```
34
+
35
+ ## Add Microphone Permissions
36
+
37
+ ### iOS
38
+ Add these lines to ```ios/[YOU_APP_NAME]/info.plist```
39
+ ```xml
40
+ <key>NSMicrophoneUsageDescription</key>
41
+ <string>We need your permission to use the microphone.</string>
42
+ ```
43
+
44
+ ### Android
45
+ Add the following line to ```android/app/src/main/AndroidManifest.xml```
46
+ ```xml
47
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
48
+ ```
49
+
50
+ ## Usage
51
+ ```javascript
52
+ import LiveAudioStream from 'react-native-live-audio-stream';
53
+
54
+ const options = {
55
+ sampleRate: 32000, // default is 44100 but 32000 is adequate for accurate voice recognition
56
+ channels: 1, // 1 or 2, default 1
57
+ bitsPerSample: 16, // 8 or 16, default 16
58
+ audioSource: 6, // android only (see below)
59
+ bufferSize: 4096 // default is 2048
60
+ };
61
+
62
+ LiveAudioStream.init(options);
63
+ LiveAudioStream.on('data', data => {
64
+ // base64-encoded audio data chunks
65
+ });
66
+ ...
67
+ LiveAudioStream.start();
68
+ ...
69
+ LiveAudioStream.stop();
70
+ ...
71
+ ```
72
+
73
+ `audioSource` should be one of the constant values from [here](https://developer.android.com/reference/android/media/MediaRecorder.AudioSource). Default value is `6` (`VOICE_RECOGNITION`).
74
+
75
+ Use 3rd-party modules like [buffer](https://www.npmjs.com/package/buffer) to decode base64 data. Example:
76
+ ```javascript
77
+ // yarn add buffer
78
+ import { Buffer } from 'buffer';
79
+ ...
80
+ LiveAudioStream.on('data', data => {
81
+ var chunk = Buffer.from(data, 'base64');
82
+ });
83
+ ```
84
+
85
+ ## Credits/References
86
+ - [react-native-audio-record](https://github.com/goodatlas/react-native-audio-record)
87
+ - iOS [Audio Queues](https://developer.apple.com/library/content/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide)
88
+ - Android [AudioRecord](https://developer.android.com/reference/android/media/AudioRecord.html)
89
+ - [cordova-plugin-audioinput](https://github.com/edimuj/cordova-plugin-audioinput)
90
+ - [react-native-recording](https://github.com/qiuxiang/react-native-recording)
91
+ - [SpeakHere](https://github.com/shaojiankui/SpeakHere)
92
+ - [ringdroid](https://github.com/google/ringdroid)
93
+
94
+ ## License
95
+ MIT
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "RNLiveAudioStream"
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.description = package['description']
10
+ s.license = package['license']
11
+ s.author = package['author']
12
+ s.homepage = "https://github.com/hmones/react-native-live-audio-stream"
13
+ s.source = { :git => 'https://github.com/hmones/react-native-live-audio-stream.git' }
14
+
15
+ s.requires_arc = true
16
+ s.ios.deployment_target = '8.0'
17
+
18
+ s.preserve_paths = 'README.md', 'package.json', 'index.js'
19
+ s.source_files = 'ios/*.{h,m}'
20
+
21
+ s.dependency 'React'
22
+ end
@@ -0,0 +1,26 @@
1
+ apply plugin: 'com.android.library'
2
+
3
+ def DEFAULT_COMPILE_SDK_VERSION = 27
4
+ def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
5
+ def DEFAULT_MIN_SDK_VERSION = 16
6
+ def DEFAULT_TARGET_SDK_VERSION = 26
7
+
8
+ def safeExtGet(prop, fallback) {
9
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
10
+ }
11
+
12
+ android {
13
+ compileSdkVersion safeExtGet("compileSdkVersion", DEFAULT_COMPILE_SDK_VERSION)
14
+ buildToolsVersion safeExtGet("buildToolsVersion", DEFAULT_BUILD_TOOLS_VERSION)
15
+
16
+ defaultConfig {
17
+ minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
18
+ targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
19
+ versionCode 1
20
+ versionName "1.0"
21
+ }
22
+ }
23
+
24
+ dependencies {
25
+ compileOnly 'com.facebook.react:react-native:+'
26
+ }
@@ -0,0 +1,5 @@
1
+
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+ package="com.imxiqi.rnliveaudiostream">
4
+ <uses-permission android:name="android.permission.RECORD_AUDIO"/>
5
+ </manifest>
@@ -0,0 +1,179 @@
1
+ package com.imxiqi.rnliveaudiostream;
2
+
3
+ import android.media.AudioFormat;
4
+ import android.media.AudioRecord;
5
+ import android.media.MediaRecorder.AudioSource;
6
+ import android.util.Base64;
7
+ import android.util.Log;
8
+
9
+ import com.facebook.react.bridge.Promise;
10
+ import com.facebook.react.bridge.ReactApplicationContext;
11
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
12
+ import com.facebook.react.bridge.ReactMethod;
13
+ import com.facebook.react.bridge.ReadableMap;
14
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
15
+
16
+ import java.lang.Math;
17
+
18
+ public class RNLiveAudioStreamModule extends ReactContextBaseJavaModule {
19
+
20
+ private final ReactApplicationContext reactContext;
21
+ private DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter;
22
+
23
+ private int sampleRateInHz;
24
+ private int channelConfig;
25
+ private int audioFormat;
26
+ private int audioSource;
27
+
28
+ private AudioRecord recorder;
29
+ private int bufferSize;
30
+ private volatile boolean isRecording;
31
+ private Thread recordingThread;
32
+
33
+ public RNLiveAudioStreamModule(ReactApplicationContext reactContext) {
34
+ super(reactContext);
35
+ this.reactContext = reactContext;
36
+ }
37
+
38
+ @Override
39
+ public String getName() {
40
+ return "RNLiveAudioStream";
41
+ }
42
+
43
+ @ReactMethod
44
+ public void init(ReadableMap options) {
45
+ try {
46
+ releaseRecorder();
47
+ } catch (Exception e) {
48
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("error", e.getMessage());
49
+ return;
50
+ }
51
+ sampleRateInHz = 44100;
52
+ if (options.hasKey("sampleRate")) {
53
+ sampleRateInHz = options.getInt("sampleRate");
54
+ }
55
+
56
+ channelConfig = AudioFormat.CHANNEL_IN_MONO;
57
+ if (options.hasKey("channels")) {
58
+ if (options.getInt("channels") == 2) {
59
+ channelConfig = AudioFormat.CHANNEL_IN_STEREO;
60
+ }
61
+ }
62
+
63
+ audioFormat = AudioFormat.ENCODING_PCM_16BIT;
64
+ if (options.hasKey("bitsPerSample")) {
65
+ if (options.getInt("bitsPerSample") == 8) {
66
+ audioFormat = AudioFormat.ENCODING_PCM_8BIT;
67
+ }
68
+ }
69
+
70
+ audioSource = AudioSource.VOICE_RECOGNITION;
71
+ if (options.hasKey("audioSource")) {
72
+ audioSource = options.getInt("audioSource");
73
+ }
74
+
75
+ isRecording = false;
76
+ eventEmitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
77
+
78
+ int minBufferSize = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
79
+ if (minBufferSize == AudioRecord.ERROR || minBufferSize == AudioRecord.ERROR_BAD_VALUE) {
80
+ Log.e("RNLiveAudioStream", "init: unsupported audio config on this device");
81
+ eventEmitter.emit("error", "Unsupported audio config on this device");
82
+ return;
83
+ }
84
+
85
+ bufferSize = minBufferSize;
86
+ if (options.hasKey("bufferSize")) {
87
+ bufferSize = Math.max(bufferSize, options.getInt("bufferSize"));
88
+ }
89
+
90
+ // Release any previous recorder before creating a new one
91
+ if (recorder != null) {
92
+ try {
93
+ recorder.release();
94
+ } catch (Exception e) {
95
+ Log.w("RNLiveAudioStream", "init: release of previous recorder failed", e);
96
+ }
97
+ recorder = null;
98
+ }
99
+
100
+ int recordingBufferSize = bufferSize * 3;
101
+ recorder = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, recordingBufferSize);
102
+
103
+ if (recorder.getState() != AudioRecord.STATE_INITIALIZED) {
104
+ Log.e("RNLiveAudioStream", "init: AudioRecord failed to initialize");
105
+ recorder.release();
106
+ recorder = null;
107
+ eventEmitter.emit("error", "AudioRecord failed to initialize");
108
+ }
109
+ }
110
+
111
+ @ReactMethod
112
+ public void start() {
113
+ if (recorder == null || recorder.getState() != AudioRecord.STATE_INITIALIZED) {
114
+ Log.e("RNLiveAudioStream", "start: recorder not initialized, aborting");
115
+ if (eventEmitter != null) {
116
+ eventEmitter.emit("error", "AudioRecord not initialized");
117
+ }
118
+ return;
119
+ }
120
+
121
+ if (isRecording) return;
122
+
123
+ isRecording = true;
124
+ recorder.startRecording();
125
+
126
+ final AudioRecord activeRecorder = recorder;
127
+ recordingThread = new Thread(new Runnable() {
128
+ public void run() {
129
+ try {
130
+ int bytesRead;
131
+ String base64Data;
132
+ byte[] buffer = new byte[bufferSize];
133
+
134
+ while (isRecording && recorder == activeRecorder) {
135
+ bytesRead = activeRecorder.read(buffer, 0, buffer.length);
136
+ if (bytesRead < 0 && isRecording) throw new IllegalStateException("Microphone read failed: " + bytesRead);
137
+
138
+ if (bytesRead > 0 && isRecording) {
139
+ base64Data = Base64.encodeToString(buffer, 0, bytesRead, Base64.NO_WRAP);
140
+ eventEmitter.emit("data", base64Data);
141
+ }
142
+ }
143
+
144
+ } catch (Exception e) {
145
+ if (isRecording) eventEmitter.emit("error", e.getMessage());
146
+ }
147
+ }
148
+ });
149
+
150
+ recordingThread.start();
151
+ }
152
+
153
+ @ReactMethod
154
+ public void stop(Promise promise) {
155
+ try {
156
+ releaseRecorder();
157
+ promise.resolve(null);
158
+ } catch (Exception e) {
159
+ promise.reject("capture_stop_failed", e);
160
+ }
161
+ }
162
+
163
+ private void releaseRecorder() throws InterruptedException {
164
+ isRecording = false;
165
+ final AudioRecord previous = recorder;
166
+ if (previous != null && previous.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
167
+ previous.stop(); // Unblock the worker's blocking read before joining it.
168
+ }
169
+ if (recordingThread != null) {
170
+ recordingThread.join(2000);
171
+ if (recordingThread.isAlive()) throw new IllegalStateException("Microphone capture did not stop");
172
+ recordingThread = null;
173
+ }
174
+ if (previous != null) {
175
+ previous.release();
176
+ recorder = null;
177
+ }
178
+ }
179
+ }
@@ -0,0 +1,25 @@
1
+ package com.imxiqi.rnliveaudiostream;
2
+
3
+ import com.facebook.react.ReactPackage;
4
+ import com.facebook.react.bridge.NativeModule;
5
+ import com.facebook.react.bridge.ReactApplicationContext;
6
+ import com.facebook.react.uimanager.ViewManager;
7
+
8
+ import java.util.ArrayList;
9
+ import java.util.Collections;
10
+ import java.util.List;
11
+
12
+ public class RNLiveAudioStreamPackage implements ReactPackage {
13
+
14
+ @Override
15
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
16
+ List<NativeModule> modules = new ArrayList<>();
17
+ modules.add(new RNLiveAudioStreamModule(reactContext));
18
+ return modules;
19
+ }
20
+
21
+ @Override
22
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
23
+ return Collections.emptyList();
24
+ }
25
+ }
package/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ declare module "react-native-live-audio-stream" {
2
+ export interface IAudioRecord {
3
+ init: (options: Options) => void
4
+ start: () => void
5
+ stop: () => Promise<string>
6
+ on(event: "data", callback: (data: string) => void): void
7
+ on(event: "error", callback: (message: string) => void): void
8
+ }
9
+
10
+ export interface Options {
11
+ sampleRate: number
12
+ /**
13
+ * - `1 | 2`
14
+ */
15
+ channels: number
16
+ /**
17
+ * - `8 | 16`
18
+ */
19
+ bitsPerSample: number
20
+ /**
21
+ * - `6`
22
+ */
23
+ audioSource?: number
24
+ wavFile: string
25
+ bufferSize?: number
26
+ }
27
+
28
+ const AudioRecord: IAudioRecord
29
+
30
+ export default AudioRecord;
31
+ }
package/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import { NativeModules, NativeEventEmitter } from 'react-native';
2
+ const { RNLiveAudioStream } = NativeModules;
3
+ const EventEmitter = new NativeEventEmitter(RNLiveAudioStream);
4
+
5
+ const AudioRecord = {};
6
+
7
+ AudioRecord.init = options => RNLiveAudioStream.init(options);
8
+ AudioRecord.start = () => RNLiveAudioStream.start();
9
+ AudioRecord.stop = () => RNLiveAudioStream.stop();
10
+
11
+ const eventsMap = {
12
+ data: 'data',
13
+ error: 'error'
14
+ };
15
+
16
+ AudioRecord.on = (event, callback) => {
17
+ const nativeEvent = eventsMap[event];
18
+ if (!nativeEvent) {
19
+ throw new Error('Invalid event');
20
+ }
21
+ EventEmitter.removeAllListeners(nativeEvent);
22
+ return EventEmitter.addListener(nativeEvent, callback);
23
+ };
24
+
25
+ export default AudioRecord;
@@ -0,0 +1,19 @@
1
+ #import <AVFoundation/AVFoundation.h>
2
+ #import <React/RCTEventEmitter.h>
3
+ #import <React/RCTLog.h>
4
+
5
+ #define kNumberBuffers 3
6
+
7
+ typedef struct {
8
+ __unsafe_unretained id mSelf;
9
+ AudioStreamBasicDescription mDataFormat;
10
+ AudioQueueRef mQueue;
11
+ AudioQueueBufferRef mBuffers[kNumberBuffers];
12
+ UInt32 bufferByteSize;
13
+ SInt64 mCurrentPacket;
14
+ bool mIsRunning;
15
+ } AQRecordState;
16
+
17
+ @interface RNLiveAudioStream: RCTEventEmitter <RCTBridgeModule>
18
+ @property (nonatomic, assign) AQRecordState recordState;
19
+ @end
@@ -0,0 +1,105 @@
1
+ #import "RNLiveAudioStream.h"
2
+
3
+ @implementation RNLiveAudioStream
4
+
5
+ RCT_EXPORT_MODULE();
6
+
7
+ RCT_EXPORT_METHOD(init:(NSDictionary *) options) {
8
+ RCTLogInfo(@"[RNLiveAudioStream] init");
9
+ _recordState.mDataFormat.mSampleRate = options[@"sampleRate"] == nil ? 44100 : [options[@"sampleRate"] doubleValue];
10
+ _recordState.mDataFormat.mBitsPerChannel = options[@"bitsPerSample"] == nil ? 16 : [options[@"bitsPerSample"] unsignedIntValue];
11
+ _recordState.mDataFormat.mChannelsPerFrame = options[@"channels"] == nil ? 1 : [options[@"channels"] unsignedIntValue];
12
+ _recordState.mDataFormat.mBytesPerPacket = (_recordState.mDataFormat.mBitsPerChannel / 8) * _recordState.mDataFormat.mChannelsPerFrame;
13
+ _recordState.mDataFormat.mBytesPerFrame = _recordState.mDataFormat.mBytesPerPacket;
14
+ _recordState.mDataFormat.mFramesPerPacket = 1;
15
+ _recordState.mDataFormat.mReserved = 0;
16
+ _recordState.mDataFormat.mFormatID = kAudioFormatLinearPCM;
17
+ _recordState.mDataFormat.mFormatFlags = _recordState.mDataFormat.mBitsPerChannel == 8 ? kLinearPCMFormatFlagIsPacked : (kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked);
18
+ _recordState.bufferByteSize = options[@"bufferSize"] == nil ? 2048 : [options[@"bufferSize"] unsignedIntValue];
19
+ _recordState.mSelf = self;
20
+ }
21
+
22
+ RCT_EXPORT_METHOD(start) {
23
+ RCTLogInfo(@"[RNLiveAudioStream] start");
24
+ AVAudioSession *audioSession = [AVAudioSession sharedInstance];
25
+ NSError *error = nil;
26
+ BOOL success;
27
+
28
+ // Apple recommended:
29
+ // Instead of setting your category and mode properties independently, set them at the same time
30
+ if (@available(iOS 10.0, *)) {
31
+ success = [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
32
+ mode: AVAudioSessionModeVoiceChat
33
+ options: AVAudioSessionCategoryOptionDuckOthers |
34
+ AVAudioSessionCategoryOptionAllowBluetooth |
35
+ AVAudioSessionCategoryOptionAllowAirPlay
36
+ error: &error];
37
+ } else {
38
+ success = [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions: AVAudioSessionCategoryOptionDuckOthers error: &error];
39
+ success = [audioSession setMode: AVAudioSessionModeVoiceChat error: &error] && success;
40
+ }
41
+ if (!success || error != nil) {
42
+ RCTLog(@"[RNLiveAudioStream] Problem setting up AVAudioSession category and mode. Error: %@", error);
43
+ [self sendEventWithName:@"error" body:[error localizedDescription] ?: @"Failed to configure audio session"];
44
+ return;
45
+ }
46
+
47
+ _recordState.mIsRunning = true;
48
+
49
+ OSStatus status = AudioQueueNewInput(&_recordState.mDataFormat, HandleInputBuffer, &_recordState, NULL, NULL, 0, &_recordState.mQueue);
50
+ if (status != 0) {
51
+ RCTLog(@"[RNLiveAudioStream] Record Failed. Cannot initialize AudioQueueNewInput. status: %i", (int) status);
52
+ [self sendEventWithName:@"error" body:[NSString stringWithFormat:@"AudioQueueNewInput failed with status: %i", (int) status]];
53
+ return;
54
+ }
55
+
56
+ for (int i = 0; i < kNumberBuffers; i++) {
57
+ AudioQueueAllocateBuffer(_recordState.mQueue, _recordState.bufferByteSize, &_recordState.mBuffers[i]);
58
+ AudioQueueEnqueueBuffer(_recordState.mQueue, _recordState.mBuffers[i], 0, NULL);
59
+ }
60
+ AudioQueueStart(_recordState.mQueue, NULL);
61
+ }
62
+
63
+ RCT_EXPORT_METHOD(stop) {
64
+ RCTLogInfo(@"[RNLiveAudioStream] stop");
65
+ if (_recordState.mIsRunning) {
66
+ _recordState.mIsRunning = false;
67
+ AudioQueueStop(_recordState.mQueue, true);
68
+ for (int i = 0; i < kNumberBuffers; i++) {
69
+ AudioQueueFreeBuffer(_recordState.mQueue, _recordState.mBuffers[i]);
70
+ }
71
+ AudioQueueDispose(_recordState.mQueue, true);
72
+ }
73
+ }
74
+
75
+ void HandleInputBuffer(void *inUserData,
76
+ AudioQueueRef inAQ,
77
+ AudioQueueBufferRef inBuffer,
78
+ const AudioTimeStamp *inStartTime,
79
+ UInt32 inNumPackets,
80
+ const AudioStreamPacketDescription *inPacketDesc) {
81
+ AQRecordState* pRecordState = (AQRecordState *)inUserData;
82
+
83
+ if (!pRecordState->mIsRunning) {
84
+ return;
85
+ }
86
+
87
+ short *samples = (short *) inBuffer->mAudioData;
88
+ long nsamples = inBuffer->mAudioDataByteSize;
89
+ NSData *data = [NSData dataWithBytes:samples length:nsamples];
90
+ NSString *str = [data base64EncodedStringWithOptions:0];
91
+ [pRecordState->mSelf sendEventWithName:@"data" body:str];
92
+
93
+ AudioQueueEnqueueBuffer(pRecordState->mQueue, inBuffer, 0, NULL);
94
+ }
95
+
96
+ - (NSArray<NSString *> *)supportedEvents {
97
+ return @[@"data", @"error"];
98
+ }
99
+
100
+ - (void)dealloc {
101
+ RCTLogInfo(@"[RNLiveAudioStream] dealloc");
102
+ AudioQueueDispose(_recordState.mQueue, true);
103
+ }
104
+
105
+ @end
@@ -0,0 +1,263 @@
1
+ // !$*UTF8*$!
2
+ {
3
+ archiveVersion = 1;
4
+ classes = {
5
+ };
6
+ objectVersion = 46;
7
+ objects = {
8
+
9
+ /* Begin PBXBuildFile section */
10
+ 49C5D751243FA7A5003D418B /* RNLiveAudioStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 49C5D74F243FA7A5003D418B /* RNLiveAudioStream.m */; };
11
+ /* End PBXBuildFile section */
12
+
13
+ /* Begin PBXCopyFilesBuildPhase section */
14
+ 58B511D91A9E6C8500147676 /* CopyFiles */ = {
15
+ isa = PBXCopyFilesBuildPhase;
16
+ buildActionMask = 2147483647;
17
+ dstPath = "include/$(PRODUCT_NAME)";
18
+ dstSubfolderSpec = 16;
19
+ files = (
20
+ );
21
+ runOnlyForDeploymentPostprocessing = 0;
22
+ };
23
+ /* End PBXCopyFilesBuildPhase section */
24
+
25
+ /* Begin PBXFileReference section */
26
+ 49C5D74F243FA7A5003D418B /* RNLiveAudioStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNLiveAudioStream.m; sourceTree = "<group>"; };
27
+ 49C5D750243FA7A5003D418B /* RNLiveAudioStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNLiveAudioStream.h; sourceTree = "<group>"; };
28
+ 49C5D76024407376003D418B /* libRNLiveAudioStream.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNLiveAudioStream.a; sourceTree = BUILT_PRODUCTS_DIR; };
29
+ /* End PBXFileReference section */
30
+
31
+ /* Begin PBXFrameworksBuildPhase section */
32
+ 58B511D81A9E6C8500147676 /* Frameworks */ = {
33
+ isa = PBXFrameworksBuildPhase;
34
+ buildActionMask = 2147483647;
35
+ files = (
36
+ );
37
+ runOnlyForDeploymentPostprocessing = 0;
38
+ };
39
+ /* End PBXFrameworksBuildPhase section */
40
+
41
+ /* Begin PBXGroup section */
42
+ 58B511D21A9E6C8500147676 = {
43
+ isa = PBXGroup;
44
+ children = (
45
+ 49C5D750243FA7A5003D418B /* RNLiveAudioStream.h */,
46
+ 49C5D74F243FA7A5003D418B /* RNLiveAudioStream.m */,
47
+ 49C5D76024407376003D418B /* libRNLiveAudioStream.a */,
48
+ );
49
+ sourceTree = "<group>";
50
+ };
51
+ /* End PBXGroup section */
52
+
53
+ /* Begin PBXHeadersBuildPhase section */
54
+ 49C5D757243FC397003D418B /* Headers */ = {
55
+ isa = PBXHeadersBuildPhase;
56
+ buildActionMask = 2147483647;
57
+ files = (
58
+ );
59
+ runOnlyForDeploymentPostprocessing = 0;
60
+ };
61
+ /* End PBXHeadersBuildPhase section */
62
+
63
+ /* Begin PBXNativeTarget section */
64
+ 58B511DA1A9E6C8500147676 /* RNLiveAudioStream */ = {
65
+ isa = PBXNativeTarget;
66
+ buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNLiveAudioStream" */;
67
+ buildPhases = (
68
+ 49C5D757243FC397003D418B /* Headers */,
69
+ 58B511D71A9E6C8500147676 /* Sources */,
70
+ 58B511D81A9E6C8500147676 /* Frameworks */,
71
+ 58B511D91A9E6C8500147676 /* CopyFiles */,
72
+ );
73
+ buildRules = (
74
+ );
75
+ dependencies = (
76
+ );
77
+ name = RNLiveAudioStream;
78
+ productName = RCTDataManager;
79
+ productReference = 49C5D76024407376003D418B /* libRNLiveAudioStream.a */;
80
+ productType = "com.apple.product-type.library.static";
81
+ };
82
+ /* End PBXNativeTarget section */
83
+
84
+ /* Begin PBXProject section */
85
+ 58B511D31A9E6C8500147676 /* Project object */ = {
86
+ isa = PBXProject;
87
+ attributes = {
88
+ LastUpgradeCheck = 0830;
89
+ ORGANIZATIONNAME = "Qi Xi";
90
+ TargetAttributes = {
91
+ 58B511DA1A9E6C8500147676 = {
92
+ CreatedOnToolsVersion = 6.1.1;
93
+ };
94
+ };
95
+ };
96
+ buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNLiveAudioStream" */;
97
+ compatibilityVersion = "Xcode 3.2";
98
+ developmentRegion = English;
99
+ hasScannedForEncodings = 0;
100
+ knownRegions = (
101
+ English,
102
+ en,
103
+ );
104
+ mainGroup = 58B511D21A9E6C8500147676;
105
+ productRefGroup = 58B511D21A9E6C8500147676;
106
+ projectDirPath = "";
107
+ projectRoot = "";
108
+ targets = (
109
+ 58B511DA1A9E6C8500147676 /* RNLiveAudioStream */,
110
+ );
111
+ };
112
+ /* End PBXProject section */
113
+
114
+ /* Begin PBXSourcesBuildPhase section */
115
+ 58B511D71A9E6C8500147676 /* Sources */ = {
116
+ isa = PBXSourcesBuildPhase;
117
+ buildActionMask = 2147483647;
118
+ files = (
119
+ 49C5D751243FA7A5003D418B /* RNLiveAudioStream.m in Sources */,
120
+ );
121
+ runOnlyForDeploymentPostprocessing = 0;
122
+ };
123
+ /* End PBXSourcesBuildPhase section */
124
+
125
+ /* Begin XCBuildConfiguration section */
126
+ 58B511ED1A9E6C8500147676 /* Debug */ = {
127
+ isa = XCBuildConfiguration;
128
+ buildSettings = {
129
+ ALWAYS_SEARCH_USER_PATHS = NO;
130
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
131
+ CLANG_CXX_LIBRARY = "libc++";
132
+ CLANG_ENABLE_MODULES = YES;
133
+ CLANG_ENABLE_OBJC_ARC = YES;
134
+ CLANG_WARN_BOOL_CONVERSION = YES;
135
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
136
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
137
+ CLANG_WARN_EMPTY_BODY = YES;
138
+ CLANG_WARN_ENUM_CONVERSION = YES;
139
+ CLANG_WARN_INFINITE_RECURSION = YES;
140
+ CLANG_WARN_INT_CONVERSION = YES;
141
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
142
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
143
+ CLANG_WARN_UNREACHABLE_CODE = YES;
144
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
145
+ COPY_PHASE_STRIP = NO;
146
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
147
+ ENABLE_TESTABILITY = YES;
148
+ GCC_C_LANGUAGE_STANDARD = gnu99;
149
+ GCC_DYNAMIC_NO_PIC = NO;
150
+ GCC_NO_COMMON_BLOCKS = YES;
151
+ GCC_OPTIMIZATION_LEVEL = 0;
152
+ GCC_PREPROCESSOR_DEFINITIONS = (
153
+ "DEBUG=1",
154
+ "$(inherited)",
155
+ );
156
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
157
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
158
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
159
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
160
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
161
+ GCC_WARN_UNUSED_FUNCTION = YES;
162
+ GCC_WARN_UNUSED_VARIABLE = YES;
163
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
164
+ MTL_ENABLE_DEBUG_INFO = YES;
165
+ ONLY_ACTIVE_ARCH = YES;
166
+ SDKROOT = iphoneos;
167
+ };
168
+ name = Debug;
169
+ };
170
+ 58B511EE1A9E6C8500147676 /* Release */ = {
171
+ isa = XCBuildConfiguration;
172
+ buildSettings = {
173
+ ALWAYS_SEARCH_USER_PATHS = NO;
174
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
175
+ CLANG_CXX_LIBRARY = "libc++";
176
+ CLANG_ENABLE_MODULES = YES;
177
+ CLANG_ENABLE_OBJC_ARC = YES;
178
+ CLANG_WARN_BOOL_CONVERSION = YES;
179
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
180
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
181
+ CLANG_WARN_EMPTY_BODY = YES;
182
+ CLANG_WARN_ENUM_CONVERSION = YES;
183
+ CLANG_WARN_INFINITE_RECURSION = YES;
184
+ CLANG_WARN_INT_CONVERSION = YES;
185
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
186
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
187
+ CLANG_WARN_UNREACHABLE_CODE = YES;
188
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
189
+ COPY_PHASE_STRIP = YES;
190
+ ENABLE_NS_ASSERTIONS = NO;
191
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
192
+ GCC_C_LANGUAGE_STANDARD = gnu99;
193
+ GCC_NO_COMMON_BLOCKS = YES;
194
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
195
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
196
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
197
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
198
+ GCC_WARN_UNUSED_FUNCTION = YES;
199
+ GCC_WARN_UNUSED_VARIABLE = YES;
200
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
201
+ MTL_ENABLE_DEBUG_INFO = NO;
202
+ SDKROOT = iphoneos;
203
+ VALIDATE_PRODUCT = YES;
204
+ };
205
+ name = Release;
206
+ };
207
+ 58B511F01A9E6C8500147676 /* Debug */ = {
208
+ isa = XCBuildConfiguration;
209
+ buildSettings = {
210
+ HEADER_SEARCH_PATHS = (
211
+ "$(inherited)",
212
+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
213
+ "$(SRCROOT)/../../../React/**",
214
+ "$(SRCROOT)/../../react-native/React/**",
215
+ );
216
+ LIBRARY_SEARCH_PATHS = "$(inherited)";
217
+ OTHER_LDFLAGS = "-ObjC";
218
+ PRODUCT_NAME = RNLiveAudioStream;
219
+ SKIP_INSTALL = YES;
220
+ };
221
+ name = Debug;
222
+ };
223
+ 58B511F11A9E6C8500147676 /* Release */ = {
224
+ isa = XCBuildConfiguration;
225
+ buildSettings = {
226
+ HEADER_SEARCH_PATHS = (
227
+ "$(inherited)",
228
+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
229
+ "$(SRCROOT)/../../../React/**",
230
+ "$(SRCROOT)/../../react-native/React/**",
231
+ );
232
+ LIBRARY_SEARCH_PATHS = "$(inherited)";
233
+ OTHER_LDFLAGS = "-ObjC";
234
+ PRODUCT_NAME = RNLiveAudioStream;
235
+ SKIP_INSTALL = YES;
236
+ };
237
+ name = Release;
238
+ };
239
+ /* End XCBuildConfiguration section */
240
+
241
+ /* Begin XCConfigurationList section */
242
+ 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNLiveAudioStream" */ = {
243
+ isa = XCConfigurationList;
244
+ buildConfigurations = (
245
+ 58B511ED1A9E6C8500147676 /* Debug */,
246
+ 58B511EE1A9E6C8500147676 /* Release */,
247
+ );
248
+ defaultConfigurationIsVisible = 0;
249
+ defaultConfigurationName = Release;
250
+ };
251
+ 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNLiveAudioStream" */ = {
252
+ isa = XCConfigurationList;
253
+ buildConfigurations = (
254
+ 58B511F01A9E6C8500147676 /* Debug */,
255
+ 58B511F11A9E6C8500147676 /* Release */,
256
+ );
257
+ defaultConfigurationIsVisible = 0;
258
+ defaultConfigurationName = Release;
259
+ };
260
+ /* End XCConfigurationList section */
261
+ };
262
+ rootObject = 58B511D31A9E6C8500147676 /* Project object */;
263
+ }
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,67 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Scheme
3
+ LastUpgradeVersion = "1140"
4
+ version = "1.3">
5
+ <BuildAction
6
+ parallelizeBuildables = "YES"
7
+ buildImplicitDependencies = "YES">
8
+ <BuildActionEntries>
9
+ <BuildActionEntry
10
+ buildForTesting = "YES"
11
+ buildForRunning = "YES"
12
+ buildForProfiling = "YES"
13
+ buildForArchiving = "YES"
14
+ buildForAnalyzing = "YES">
15
+ <BuildableReference
16
+ BuildableIdentifier = "primary"
17
+ BlueprintIdentifier = "58B511DA1A9E6C8500147676"
18
+ BuildableName = "libRNLiveAudioStream.a"
19
+ BlueprintName = "RNLiveAudioStream"
20
+ ReferencedContainer = "container:RNLiveAudioStream.xcodeproj">
21
+ </BuildableReference>
22
+ </BuildActionEntry>
23
+ </BuildActionEntries>
24
+ </BuildAction>
25
+ <TestAction
26
+ buildConfiguration = "Debug"
27
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29
+ shouldUseLaunchSchemeArgsEnv = "YES">
30
+ <Testables>
31
+ </Testables>
32
+ </TestAction>
33
+ <LaunchAction
34
+ buildConfiguration = "Debug"
35
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37
+ launchStyle = "0"
38
+ useCustomWorkingDirectory = "NO"
39
+ ignoresPersistentStateOnLaunch = "NO"
40
+ debugDocumentVersioning = "YES"
41
+ debugServiceExtension = "internal"
42
+ allowLocationSimulation = "YES">
43
+ </LaunchAction>
44
+ <ProfileAction
45
+ buildConfiguration = "Release"
46
+ shouldUseLaunchSchemeArgsEnv = "YES"
47
+ savedToolIdentifier = ""
48
+ useCustomWorkingDirectory = "NO"
49
+ debugDocumentVersioning = "YES">
50
+ <MacroExpansion>
51
+ <BuildableReference
52
+ BuildableIdentifier = "primary"
53
+ BlueprintIdentifier = "58B511DA1A9E6C8500147676"
54
+ BuildableName = "libRNLiveAudioStream.a"
55
+ BlueprintName = "RNLiveAudioStream"
56
+ ReferencedContainer = "container:RNLiveAudioStream.xcodeproj">
57
+ </BuildableReference>
58
+ </MacroExpansion>
59
+ </ProfileAction>
60
+ <AnalyzeAction
61
+ buildConfiguration = "Debug">
62
+ </AnalyzeAction>
63
+ <ArchiveAction
64
+ buildConfiguration = "Release"
65
+ revealArchiveInOrganizer = "YES">
66
+ </ArchiveAction>
67
+ </Scheme>
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@quranlingoapp/react-native-live-audio-stream",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.2",
4
+ "description": "Get live audio stream data for React Native",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "live stream",
8
+ "react-native",
9
+ "audio",
10
+ "live",
11
+ "recording",
12
+ "voice"
13
+ ],
14
+ "main": "index.js",
15
+ "homepage": "https://github.com/hmones/react-native-live-audio-stream",
16
+ "bugs": {
17
+ "url": "https://github.com/hmones/react-native-live-audio-stream/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/hmones/react-native-live-audio-stream.git"
22
+ },
23
+ "author": "Qi Xi <me@imxiqi.com> (https://www.imxiqi.com/)",
24
+ "devDependencies": {
25
+ "babel-eslint": "^8.2.3",
26
+ "eslint": "^4.19.1",
27
+ "eslint-plugin-prettier": "^2.6.0",
28
+ "prettier": "^1.12.0"
29
+ },
30
+ "dependencies": {},
31
+ "peerDependencies": {},
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "files": [
36
+ "index.js",
37
+ "index.d.ts",
38
+ "RNLiveAudioStream.podspec",
39
+ "android/build.gradle",
40
+ "android/src",
41
+ "ios",
42
+ "README.md",
43
+ "LICENSE"
44
+ ]
45
+ }