Commit 4ea8f61d authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

Merge branch 'it18218640' into 'master'

create a send audio to server function

See merge request !113
parents 0ad79d03 0709e671
......@@ -22,6 +22,8 @@ import Permissions from 'react-native-permissions';
import AudioRecord from 'react-native-audio-record';
import axios from "axios";
import client from "../client/Client";
export default function Blue(color) {
const navigation = useNavigation();
......@@ -88,7 +90,7 @@ export default function Blue(color) {
AudioRecord.start();
setTimeout(() => {
audioStop();
}, 4000);
}, 2000);
}
// audioStop
......@@ -100,6 +102,66 @@ export default function Blue(color) {
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 (
<SafeAreaView>
<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