async function startRecording() {
try {
if (permissionResponse?.status !== 'granted') {
console.log('Requesting permission..');
await requestPermission();
}
await Audio.setAudioModeAsync({
allowsRecordingIOS: true,
playsInSilentModeIOS: true,
});
console.log('Starting recording..');
const { recording } = await Audio.Recording.createAsync(
Audio.RecordingOptionsPresets.HIGH_QUALITY
);
setRecording(recording);
setIsRecording(true);
console.log('Recording started');
} catch (err) {
console.error('Failed to start recording', err);
}
}
async function stopRecording() {
console.log('Stopping recording..');
setIsRecording(false);
setRecording(undefined);
await recording.stopAndUnloadAsync();
await Audio.setAudioModeAsync({
allowsRecordingIOS: false,
});
const uri = recording.getURI();
setUri(uri);
setTimer(0);
console.log('Recording stopped and stored at', uri);
}
const handleSubmit = () => {
let convertedUri = uri;
// if (Platform.OS === 'android') {
// convertedUri = uri.replace('file://', '');
// }
const formData = new FormData();
formData.append('session_name', textInputValue);
formData.append('session_audio', {
uri: convertedUri,
type: 'audio/m4a',
name: 'test.m4a',
} as any);
mutate({ assets: formData });
setUri('');
setModalVisible(false);
setTextInputValue('');
};
`Recording audio in my Expo app works fine, and the file is saved locally. However, when I try to send it to the server, I’m getting an error saying it’s not an audio file. Any ideas why this might be happening?
server accepts m4a file since both android and ios are creating m4a mime types files and in ios the code is working but for android the server responding as this is not an audio file`
Waleed Taher is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.