I'm trying to create a recording app with React Native. At the moment I'm using an npm package react-native-audio-record to record audio which seems to be working fine.
However when I get the file it leads to an empty folder and file systems like react-native-fs are all returning there is no file there.
This being said I am now buffering the file and getting the audio binary data back like the below
{"data": [253, 75, 30, 174, 207, 230, 145, 233, 101, 203, 242, 226, 110, 182, 171, 203, 240, 222, 189, 233, 104, 165, 234, 255, 10, 138, 222, 74, 41, 174, 149, 171, 104, 175, 240, 222, 190, 39, 30, 179, 255, 66, 215, 176, 121, 212, 63, 133, 15, 142, 62, 227, 158, 253, 248, 13, 64, 243, 225, 66, 224, 94, 65, 3, 158, 248, 11, 191, 221, 106, 214, 191, 10, 137, 237, 106, 41, 222, 174, 207, 195, 106, 214, 191, 2, 154, 101, 137, 198, 173, 138, 137, 255, 8, 31, 57, 227, 125, 2, 251, 192, 187, 215, 238, 4, 215, 159, 128, 223, 126, 254, 208, 48, 60, 243, 142, 182, 247, 64, 192, 252, 58, 28, 186, 103, 167, 182, 207, 237, 122, 203, 112, 106], "type": "Buffer"}
I have two questions:
- What do I do with this data? I've tried to write a file using
react-native-fsI get the below error. Do I upload the buffer data to my server then write a file and send it back down?
- writeFile error
Possible Unhandled Promise Rejection (id: 0):
TypeError: string.charCodeAt is not a function. (In 'string.charCodeAt(counter++)', 'string.charCodeAt' is undefined)
ucs2decode@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:168299:34
utf8encode@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:168373:34
writeFile@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:167959:40
onRecordPause$@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:165688:47
tryCatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:31025:23
invoke@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:31201:32
tryCatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:31025:23
invoke@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:31101:30
http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:31111:21
tryCallOne@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:6202:16
http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:6303:27
_callTimer@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:32952:17
_callImmediatesPass@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:32988:19
callImmediates@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:33206:33
callImmediates@[native code]
__callImmediates@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:5638:35
http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:5424:34
__guard@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:5621:15
flushedQueue@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:5423:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]
- I can listen to the file when I manually go to the location of the file however when I try to get the file using
react-native-fsI getError: The file “fileName.wav” couldn’t be opened.. Why can't I open the WAV.
See below code.
// When user hits the pause icon.
const onRecordPause = async () => {
const audioFile = await AudioRecord.stop();
const bufferFile = Buffer.from(audioFile, 'base64');
const writeToPath = RNFS.DocumentDirectoryPath + '/test.wav';
// write the file
RNFS.writeFile(writeToPath, bufferFile, 'utf8')
.then((success) => {
console.log('FILE WRITTEN!');
})
.catch((err) => {
console.log(err.message);
});
return setRecordingStatus("PAUSED");
};