-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathRecorderTest.ts
More file actions
43 lines (40 loc) · 1.11 KB
/
RecorderTest.ts
File metadata and controls
43 lines (40 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import {
AudioContext,
AudioRecorder,
AudioBuffer,
} from 'react-native-audio-api';
export const recorderTest = (
audioContextRef: React.RefObject<AudioContext | null>,
buffers: AudioBuffer[]
) => {
const recorder = new AudioRecorder();
recorder.onAudioReady(
{
sampleRate: audioContextRef.current!.sampleRate,
bufferLength: audioContextRef.current!.sampleRate * 0.1,
channelCount: 1,
},
(event) => {
const { buffer, numFrames } = event;
console.log('Audio recorder buffer ready:', numFrames);
buffers.push(buffer);
}
);
recorder.start();
setTimeout(() => {
recorder.stop();
}, 5000);
};
export const recorderPlaybackTest = (
audioContextRef: React.RefObject<AudioContext | null>,
buffers: AudioBuffer[]
) => {
let nextStartAt = audioContextRef.current!.currentTime + 0.1;
for (let i = 0; i < buffers.length; i++) {
const source = audioContextRef.current!.createBufferSource();
source.buffer = buffers[i];
source.connect(audioContextRef.current!.destination);
source.start(nextStartAt);
nextStartAt += buffers[i].duration;
}
};