Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
21_22-J 38
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 38
21_22-J 38
Commits
0709e671
Commit
0709e671
authored
Feb 09, 2022
by
W.D.R.P. Sandeepa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create a send audio to server function
parent
0ad79d03
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
1 deletion
+63
-1
frontend/src/screen/activity/Blue.js
frontend/src/screen/activity/Blue.js
+63
-1
No files found.
frontend/src/screen/activity/Blue.js
View file @
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
();
},
4
000
);
},
2
000
);
}
// 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
"
}}
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment