Commit 0709e671 authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

create a send audio to server function

parent 0ad79d03
...@@ -22,6 +22,8 @@ import Permissions from 'react-native-permissions'; ...@@ -22,6 +22,8 @@ import Permissions from 'react-native-permissions';
import AudioRecord from 'react-native-audio-record'; import AudioRecord from 'react-native-audio-record';
import axios from "axios"; import axios from "axios";
import client from "../client/Client";
export default function Blue(color) { export default function Blue(color) {
const navigation = useNavigation(); const navigation = useNavigation();
...@@ -88,7 +90,7 @@ export default function Blue(color) { ...@@ -88,7 +90,7 @@ export default function Blue(color) {
AudioRecord.start(); AudioRecord.start();
setTimeout(() => { setTimeout(() => {
audioStop(); audioStop();
}, 4000); }, 2000);
} }
// audioStop // audioStop
...@@ -100,6 +102,66 @@ export default function Blue(color) { ...@@ -100,6 +102,66 @@ export default function Blue(color) {
console.log('userFile', audioFile); console.log('userFile', audioFile);
} }
// send audio to server function
async function sendAudio(audioFile) {
// append form data and upload to api
const formData = new FormData();
formData.append(
'file',
{
uri: `file://${audioFile}`,
type: 'audio/wav',
name: 'color.wav',
}
);
formData.append(
'name', backColor
);
console.log(formData);
try {
const res = await client.post('http://192.168.8.101:5000/predict', formData, {
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data',
},
});
console.log(res);
if (res.data.error == false) {
//successfully
console.log("checking " + res.data.error);
} else {
//error occures
}
if (res.data.success) {
console.log("response " + JSON.stringify(res));
}
} catch (error) {
console.log(error);
}
}
return ( return (
<SafeAreaView> <SafeAreaView>
<View style={{ flexDirection: "column" }}> <View style={{ flexDirection: "column" }}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment