1- import { AudioComponent , RecordingObject } from './AudioVideo' ;
2-
3- export enum AndroidOutputFormat {
4- DEFAULT = 0 ,
5- THREE_GPP = 1 ,
6- MPEG_4 = 2 ,
7- AMR_NB = 3 ,
8- AMR_WB = 4 ,
9- AAC_ADIF = 5 ,
10- AAC_ADTS = 6 ,
11- RTP_AVP = 7 ,
12- MPEG2TS = 8 ,
13- WEBM = 9 ,
14- }
15-
16- // @docsMissing
17- export enum AndroidAudioEncoder {
18- DEFAULT = 0 ,
19- AMR_NB = 1 ,
20- AMR_WB = 2 ,
21- AAC = 3 ,
22- HE_AAC = 4 ,
23- AAC_ELD = 5 ,
24- }
25-
26- export enum IOSOutputFormat {
27- LINEARPCM = 'lpcm' ,
28- AC3 = 'ac-3' ,
29- '60958AC3' = 'cac3' ,
30- APPLEIMA4 = 'ima4' ,
31- MPEG4AAC = 'aac ' ,
32- MPEG4CELP = 'celp' ,
33- MPEG4HVXC = 'hvxc' ,
34- MPEG4TWINVQ = 'twvq' ,
35- MACE3 = 'MAC3' ,
36- MACE6 = 'MAC6' ,
37- ULAW = 'ulaw' ,
38- ALAW = 'alaw' ,
39- QDESIGN = 'QDMC' ,
40- QDESIGN2 = 'QDM2' ,
41- QUALCOMM = 'Qclp' ,
42- MPEGLAYER1 = '.mp1' ,
43- MPEGLAYER2 = '.mp2' ,
44- MPEGLAYER3 = '.mp3' ,
45- APPLELOSSLESS = 'alac' ,
46- MPEG4AAC_HE = 'aach' ,
47- MPEG4AAC_LD = 'aacl' ,
48- MPEG4AAC_ELD = 'aace' ,
49- MPEG4AAC_ELD_SBR = 'aacf' ,
50- MPEG4AAC_ELD_V2 = 'aacg' ,
51- MPEG4AAC_HE_V2 = 'aacp' ,
52- MPEG4AAC_SPATIAL = 'aacs' ,
53- AMR = 'samr' ,
54- AMR_WB = 'sawb' ,
55- AUDIBLE = 'AUDB' ,
56- ILBC = 'ilbc' ,
57- DVIINTELIMA = 0x6d730011 ,
58- MICROSOFTGSM = 0x6d730031 ,
59- AES3 = 'aes3' ,
60- ENHANCEDAC3 = 'ec-3' ,
61- }
62-
63- export enum IOSAudioQuality {
64- MIN = 0 ,
65- LOW = 0x20 ,
66- MEDIUM = 0x40 ,
67- HIGH = 0x60 ,
68- MAX = 0x7f ,
69- }
1+ import {
2+ AndroidAudioEncoder ,
3+ AndroidOutputFormat ,
4+ ExpoAudioRecordingConfiguration as AudioRecordingConfiguration ,
5+ IOSAudioQuality ,
6+ IOSOutputFormat ,
7+ ExpoRecordingOptions as RecordingOptions ,
8+ } from 'stream-chat-react-native-core' ;
709
71- export type RecordingOptionsAndroid = {
72- /**
73- * The desired audio encoder. See the [`AndroidAudioEncoder`](#androidaudioencoder) enum for all valid values.
74- */
75- audioEncoder : AndroidAudioEncoder | number ;
76- /**
77- * The desired file extension. Example valid values are `.3gp` and `.m4a`.
78- * For more information, see the [Android docs](https://developer.android.com/guide/topics/media/media-formats)
79- * for supported output formats.
80- */
81- extension : string ;
82- /**
83- * The desired file format. See the [`AndroidOutputFormat`](#androidoutputformat) enum for all valid values.
84- */
85- outputFormat : AndroidOutputFormat | number ;
86- /**
87- * The desired bit rate.
88- *
89- * Note that `prepareToRecordAsync()` may perform additional checks on the parameter to make sure whether the specified
90- * bit rate is applicable, and sometimes the passed bitRate will be clipped internally to ensure the audio recording
91- * can proceed smoothly based on the capabilities of the platform.
92- *
93- * @example `128000`
94- */
95- bitRate ?: number ;
96- /**
97- * The desired maximum file size in bytes, after which the recording will stop (but `stopAndUnloadAsync()` must still
98- * be called after this point).
99- *
100- * @example `65536`
101- */
102- maxFileSize ?: number ;
103- /**
104- * The desired number of channels.
105- *
106- * Note that `prepareToRecordAsync()` may perform additional checks on the parameter to make sure whether the specified
107- * number of audio channels are applicable.
108- *
109- * @example `1`, `2`
110- */
111- numberOfChannels ?: number ;
112- /**
113- * The desired sample rate.
114- *
115- * Note that the sampling rate depends on the format for the audio recording, as well as the capabilities of the platform.
116- * For instance, the sampling rate supported by AAC audio coding standard ranges from 8 to 96 kHz,
117- * the sampling rate supported by AMRNB is 8kHz, and the sampling rate supported by AMRWB is 16kHz.
118- * Please consult with the related audio coding standard for the supported audio sampling rate.
119- *
120- * @example 44100
121- */
122- sampleRate ?: number ;
123- } ;
124-
125- export type RecordingOptionsIOS = {
126- /**
127- * The desired audio quality. See the [`IOSAudioQuality`](#iosaudioquality) enum for all valid values.
128- */
129- audioQuality : IOSAudioQuality | number ;
130- /**
131- * The desired bit rate.
132- *
133- * @example `128000`
134- */
135- bitRate : number ;
136- /**
137- * The desired file extension.
138- *
139- * @example `'.caf'`
140- */
141- extension : string ;
142- /**
143- * The desired number of channels.
144- *
145- * @example `1`, `2`
146- */
147- numberOfChannels : number ;
148- /**
149- * The desired sample rate.
150- *
151- * @example `44100`
152- */
153- sampleRate : number ;
154- /**
155- * The desired bit depth hint.
156- *
157- * @example `16`
158- */
159- bitDepthHint ?: number ;
160- /**
161- * The desired bit rate strategy. See the next section for an enumeration of all valid values of `bitRateStrategy`.
162- */
163- bitRateStrategy ?: number ;
164- /**
165- * The desired PCM bit depth.
166- *
167- * @example `16`
168- */
169- linearPCMBitDepth ?: number ;
170- /**
171- * A boolean describing if the PCM data should be formatted in big endian.
172- */
173- linearPCMIsBigEndian ?: boolean ;
174- /**
175- * A boolean describing if the PCM data should be encoded in floating point or integral values.
176- */
177- linearPCMIsFloat ?: boolean ;
178- /**
179- * The desired file format. See the [`IOSOutputFormat`](#iosoutputformat) enum for all valid values.
180- */
181- outputFormat ?: string | IOSOutputFormat | number ;
182- } ;
183-
184- // @docsMissing
185- export type RecordingOptionsWeb = {
186- bitsPerSecond ?: number ;
187- mimeType ?: string ;
188- } ;
189-
190- export type RecordingOptions = {
191- /**
192- * Recording options for the Android platform.
193- */
194- android : RecordingOptionsAndroid ;
195- /**
196- * Recording options for the iOS platform.
197- */
198- ios : RecordingOptionsIOS ;
199- /**
200- * Recording options for the Web platform.
201- */
202- web : RecordingOptionsWeb ;
203- /**
204- * A boolean that determines whether audio level information will be part of the status object under the "metering" key.
205- */
206- isMeteringEnabled ?: boolean ;
207- /**
208- * A boolean that hints to keep the audio active after `prepareToRecordAsync` completes.
209- * Setting this value can improve the speed at which the recording starts. Only set this value to `true` when you call `startAsync`
210- * immediately after `prepareToRecordAsync`. This value is automatically set when using `Audio.recording.createAsync()`.
211- */
212- keepAudioActiveHint ?: boolean ;
213- } ;
10+ import { AudioComponent , RecordingObject } from './AudioVideo' ;
21411
21512const sleep = ( ms : number ) =>
21613 new Promise < void > ( ( resolve ) => {
@@ -221,6 +18,29 @@ const sleep = (ms: number) =>
22118
22219class _Audio {
22320 recording : typeof RecordingObject | null = null ;
21+ audioRecordingConfiguration : AudioRecordingConfiguration = {
22+ mode : {
23+ allowsRecordingIOS : true ,
24+ playsInSilentModeIOS : true ,
25+ } ,
26+ options : {
27+ android : {
28+ audioEncoder : AndroidAudioEncoder . AAC ,
29+ extension : '.aac' ,
30+ outputFormat : AndroidOutputFormat . AAC_ADTS ,
31+ } ,
32+ ios : {
33+ audioQuality : IOSAudioQuality . HIGH ,
34+ bitRate : 128000 ,
35+ extension : '.aac' ,
36+ numberOfChannels : 2 ,
37+ outputFormat : IOSOutputFormat . MPEG4AAC ,
38+ sampleRate : 44100 ,
39+ } ,
40+ isMeteringEnabled : true ,
41+ web : { } ,
42+ } ,
43+ } ;
22444
22545 startRecording = async ( recordingOptions : RecordingOptions , onRecordingStatusUpdate ) => {
22646 try {
@@ -242,28 +62,10 @@ class _Audio {
24262 if ( ! permissionsGranted ) {
24363 throw new Error ( 'Missing audio recording permission.' ) ;
24464 }
245- await AudioComponent . setAudioModeAsync ( {
246- allowsRecordingIOS : true ,
247- playsInSilentModeIOS : true ,
248- } ) ;
249- const androidOptions = {
250- audioEncoder : AndroidAudioEncoder . AAC ,
251- extension : '.aac' ,
252- outputFormat : AndroidOutputFormat . AAC_ADTS ,
253- } ;
254- const iosOptions = {
255- audioQuality : IOSAudioQuality . HIGH ,
256- bitRate : 128000 ,
257- extension : '.aac' ,
258- numberOfChannels : 2 ,
259- outputFormat : IOSOutputFormat . MPEG4AAC ,
260- sampleRate : 44100 ,
261- } ;
65+ await AudioComponent . setAudioModeAsync ( this . audioRecordingConfiguration . mode ) ;
26266 const options = {
26367 ...recordingOptions ,
264- android : androidOptions ,
265- ios : iosOptions ,
266- web : { } ,
68+ ...this . audioRecordingConfiguration . options ,
26769 } ;
26870
26971 // This is a band-aid fix for this (still unresolved) issue on Expo's side:
@@ -303,4 +105,8 @@ class _Audio {
303105 } ;
304106}
305107
108+ export const overrideAudioRecordingConfiguration = (
109+ audioRecordingConfiguration : AudioRecordingConfiguration ,
110+ ) => audioRecordingConfiguration ;
111+
306112export const Audio = AudioComponent ? new _Audio ( ) : null ;
0 commit comments