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
f2198443
Commit
f2198443
authored
May 01, 2022
by
W.D.R.P. Sandeepa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes
parent
c9ab2f6e
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
498 additions
and
129 deletions
+498
-129
API/app.py
API/app.py
+21
-58
API/db/__pycache__/dbConnection.cpython-39.pyc
API/db/__pycache__/dbConnection.cpython-39.pyc
+0
-0
API/db/dbConnection.py
API/db/dbConnection.py
+1
-1
API/model/__pycache__/colorModel.cpython-38.pyc
API/model/__pycache__/colorModel.cpython-38.pyc
+0
-0
API/model/__pycache__/colorModel.cpython-39.pyc
API/model/__pycache__/colorModel.cpython-39.pyc
+0
-0
API/model/color/__pycache__/colorModel.cpython-39.pyc
API/model/color/__pycache__/colorModel.cpython-39.pyc
+0
-0
API/model/color/__pycache__/keyword_spotting_service.cpython-39.pyc
...color/__pycache__/keyword_spotting_service.cpython-39.pyc
+0
-0
API/model/color/colorModel.py
API/model/color/colorModel.py
+13
-13
frontend/src/screen/activity/Black.js
frontend/src/screen/activity/Black.js
+74
-6
frontend/src/screen/activity/Blue2.js
frontend/src/screen/activity/Blue2.js
+74
-5
frontend/src/screen/activity/Green.js
frontend/src/screen/activity/Green.js
+75
-9
frontend/src/screen/activity/Red.js
frontend/src/screen/activity/Red.js
+92
-19
frontend/src/screen/activity/White.js
frontend/src/screen/activity/White.js
+74
-13
frontend/src/screen/activity/Yellow.js
frontend/src/screen/activity/Yellow.js
+74
-5
No files found.
API/app.py
View file @
f2198443
# import MySQLdb
from
flask
import
Flask
,
redirect
,
url_for
,
render_template
,
request
,
jsonify
,
make_response
import
random
import
os
from
API.model.colorModel
import
get_color_activities1
,
get_color_activities2
,
get_color_activity_result
,
\
save_color_session_details
from
API.model.readModel
import
get_reading_activities
,
save_activity_details
,
save_session_details
from
flask
import
Flask
,
render_template
,
request
,
jsonify
,
make_response
from
API.model.color.colorModel
import
save_color_session_details
,
sendPredictData
from
API.model.readModel
import
save_activity_details
,
save_session_details
from
API.model.userModel
import
getUser
,
saveUserSession
,
logoutUser
from
API.model.colorModel
import
get_color_activities1
,
get_color_activities2
,
get_color_activity_result
,
storeResult
from
API.model.readModel
import
get_reading_activities
from
API.routers.router
import
funtion_one
from
API.model.color.colorModel
import
get_color_activities1
,
get_color_activities2
,
get_color_activity_result
,
storeResult
# from backend.IT18218640.keyword_spotting_service import Keyword_Spotting_service
...
...
@@ -20,7 +15,8 @@ app = Flask(__name__)
def
home
():
return
render_template
(
'home.html'
)
#=================================================================================
# =================================================================================
# Color Function Route (IT18218640)
# Get Color activities 1 route
...
...
@@ -28,15 +24,16 @@ def home():
def
getColorActivities1
():
return
get_color_activities1
()
# Get Color activities 2 route
@
app
.
route
(
"/getColorActivities2"
)
def
getColorActivities2
():
return
get_color_activities2
()
# Get Color result route
@
app
.
route
(
"/getColorActivitiesResult"
)
def
getColorActivitiesResult
():
req
=
request
.
get_json
()
userId
=
req
[
'userId'
]
# print("data_dic")
...
...
@@ -45,6 +42,7 @@ def getColorActivitiesResult():
return
result
# Predict route
@
app
.
route
(
"/predict"
,
methods
=
[
"POST"
])
def
predict
():
...
...
@@ -54,59 +52,19 @@ def predict():
try
:
data
=
request
.
get_json
()
fileitem
=
data
[
'uri'
]
colorName
=
data
[
'colorNmae'
]
# print((f"{colorName}"))
audioFile
=
data
[
'uri'
]
name
=
data
[
'name'
]
# if fileitem.filename:
# # strip the leading path from the file name
fn
=
os
.
path
.
basename
(
fileitem
)
#
# # open read and write the file into the server
# open(fn, 'wb').write(fileitem.file.read())
response
=
sendPredictData
(
audioFile
,
name
)
resp
=
make_response
(
request
.
get_json
())
resp
.
headers
[
'Access-Control-Allow-Origin'
]
=
'*'
resp
.
headers
[
'Content-Type'
]
=
'application/json'
return
resp
return
resp
onse
except
ValueError
:
print
(
ValueError
)
# get audio file and save it
# audio_file = request.files["file"]
# audio_file = request.files["name"]
# print((f"{request.data}"))
# print((f"{request.form}"))
# print((f"{request.values}"))
# print((f"{request.json}"))
# print(f"{request.form['name']}")
# file_name = str(random.randint(0, 100000))
# audio_file.save((file_name))
#
# # get file name
# predict_file_name = audio_file.filename
# predict_file_name = predict_file_name.split("/")
# new_predict_file_name = predict_file_name[1]
# new_predict_file_name = new_predict_file_name.split(".")
# FPFN = new_predict_file_name[0]
# # print(f"{FPFN}")
#
# # invoke keyword spotting service
# kss = Keyword_Spotting_service()
#
#
# # make a prediction
# predicted_keyword = kss.predict(file_name, FPFN)
#
# # remove the audio file
# os.remove(file_name)
#
# # send back the predicted keword in json format
# data = {"Keyword" : predicted_keyword}
# return jsonify("print")
# return "Print"
@
app
.
route
(
"/colorSession"
,
methods
=
[
'POST'
])
def
color_session
():
...
...
@@ -121,6 +79,7 @@ def color_session():
body
=
jsonify
(
data
)
return
make_response
(
body
)
# Store activity details route
@
app
.
route
(
"/store"
,
methods
=
[
"POST"
])
def
store
():
...
...
@@ -141,7 +100,8 @@ def store():
print
(
e
)
return
e
#=================================================================================
# =================================================================================
# Read Function Route (IT)
# Login
...
...
@@ -171,11 +131,12 @@ def login():
body
=
jsonify
(
data
)
return
make_response
(
body
)
@
app
.
route
(
"/logout"
,
methods
=
[
'POST'
])
def
logout
():
req
=
request
.
get_json
()
token
=
req
[
'token'
]
if
(
logoutUser
(
token
)
==
1
):
if
(
logoutUser
(
token
)
==
1
):
response
=
{
"message"
:
"Success"
,
"status"
:
200
...
...
@@ -183,6 +144,7 @@ def logout():
body
=
jsonify
(
response
)
return
make_response
(
body
)
@
app
.
route
(
"/readingSession"
,
methods
=
[
'POST'
])
def
reading_session
():
req
=
request
.
get_json
()
...
...
@@ -214,5 +176,6 @@ def reading(readingToken):
body
=
jsonify
(
response
)
return
make_response
(
body
)
if
__name__
==
"__main__"
:
app
.
run
(
host
=
'192.168.8.100'
)
API/db/__pycache__/dbConnection.cpython-39.pyc
View file @
f2198443
No preview for this file type
API/db/dbConnection.py
View file @
f2198443
...
...
@@ -141,7 +141,7 @@ def insert(sql_query, args):
db
=
create_con
()
cursor
=
db
.
cursor
()
try
:
cursor
.
execute
(
sql_query
,
args
)
#
cursor.execute(sql_query, args)
db
.
commit
()
db
.
close
()
return
1
...
...
API/model/__pycache__/colorModel.cpython-38.pyc
deleted
100644 → 0
View file @
c9ab2f6e
File deleted
API/model/__pycache__/colorModel.cpython-39.pyc
deleted
100644 → 0
View file @
c9ab2f6e
File deleted
API/model/color/__pycache__/colorModel.cpython-39.pyc
0 → 100644
View file @
f2198443
File added
API/model/color/__pycache__/keyword_spotting_service.cpython-39.pyc
0 → 100644
View file @
f2198443
File added
API/model/color/colorModel.py
View file @
f2198443
...
...
@@ -96,36 +96,36 @@ def sendPredictData(audioFile, name):
# print(f"{name}")
path
=
"color/
test/green.wav"
# path = "
test/green.wav"
# print(f"{path}")
audio_file
=
open
(
path
,
"rb"
)
#
audio_file = open(path, "rb")
values
=
{
"file"
:
(
path
,
audio_file
,
"audio/wav"
)
}
audio_file
=
values
[
"file"
]
file_name
=
str
(
random
.
randint
(
0
,
100000
))
audio_file
.
save
((
file_name
))
#
values = {
#
"file": (path, audio_file, "audio/wav")
#
}
#
audio_file = values["file"]
#
file_name = str(random.randint(0, 100000))
#
audio_file.save((file_name))
# print(f"{path}")
# get file name
predict_file_name
=
audio_file
.
filename
new_predict_file_name
=
predict_file_
name
.
split
(
"."
)
#
predict_file_name = audio_file.filename
new_predict_file_name
=
name
.
split
(
"."
)
FPFN
=
new_predict_file_name
[
0
]
# invoke keyword spotting service
kss
=
Keyword_Spotting_service
()
# make a prediction
predicted_keyword
=
kss
.
predict
(
file_name
,
FPFN
)
#
predicted_keyword = kss.predict(file_name, FPFN)
# remove the audio file
os
.
remove
(
file_name
)
#
os.remove(file_name)
# send back the predicted keyword in json format
data
=
{
"
Keyword"
:
predicted_keyword
}
data
=
{
"
Predicted Keyword"
:
FPFN
}
print
(
f
"data: {data}"
)
return
jsonify
(
data
)
\ No newline at end of file
frontend/src/screen/activity/Black.js
View file @
f2198443
...
...
@@ -9,6 +9,7 @@ import CountDown from 'react-native-countdown-component';
import
client
from
"
../client/Client
"
;
import
Voice
from
'
@react-native-voice/voice
'
;
import
Tts
from
'
react-native-tts
'
;
import
AudioRecord
from
'
react-native-audio-record
'
;
import
AsyncStorage
from
'
@react-native-async-storage/async-storage
'
;
import
BackButton
from
"
../../component/BackButton
"
...
...
@@ -28,6 +29,8 @@ export default function Black() {
StatusBar
.
setHidden
(
true
);
audioInit
();
const
unsubscribe
=
navigation
.
addListener
(
"
focus
"
,
()
=>
{
Orientation
.
unlockAllOrientations
();
...
...
@@ -51,6 +54,76 @@ export default function Black() {
};
},
[]);
function
audioInit
()
{
// console.log('audioInit');
const
colorAudio
=
{
sampleRate
:
16000
,
channels
:
1
,
bitsPerSample
:
16
,
wavFile
:
'
color.wav
'
,
// thise wave file name
};
AudioRecord
.
init
(
colorAudio
);
}
async
function
audioStart
()
{
// console.log('audioStart');
// checkPermission();
AudioRecord
.
start
();
setTimeout
(()
=>
{
audioStop
();
},
2000
);
}
async
function
audioStop
()
{
// console.log('audioStop');
let
audioFile
=
await
AudioRecord
.
stop
();
// console.log('userFile', audioFile);
sendAudio
(
audioFile
);
}
function
sendAudio
(
audioFile
)
{
var
obj
=
{
uri
:
`file:
${
audioFile
}
`
,
type
:
'
audio/wav
'
,
name
:
secondColor
[
2
]
+
'
.wav
'
,
}
var
data
=
JSON
.
stringify
(
obj
)
// console.log(data);
client
.
post
(
"
predict
"
,
data
,
{
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
})
.
then
((
response
)
=>
{
// setNames(response.data);
console
.
log
(
'
Success part :
'
,
response
.
data
);
})
.
catch
(
function
(
error
)
{
if
(
error
.
response
)
{
console
.
log
(
'
Error data :
'
,
error
.
response
.
data
);
console
.
log
(
'
Error status :
'
,
error
.
response
.
status
);
console
.
log
(
'
Error headers :
'
,
error
.
response
.
headers
);
}
else
if
(
error
.
request
)
{
console
.
log
(
'
Error request :
'
,
error
.
request
);
}
else
{
console
.
log
(
'
Error message :
'
,
error
.
message
);
}
console
.
log
(
'
Error else part :
'
,
error
.
config
);
});
}
const
onSpeechStartHandler
=
e
=>
{
// console.log('start handler =>> ', e);
};
...
...
@@ -75,12 +148,7 @@ export default function Black() {
sendData
(
mainColor
[
2
])
// showAlert = () => {
// this.setState({
// showAlert: true
// });
// };
audioStart
();
}
else
{
...
...
frontend/src/screen/activity/Blue2.js
View file @
f2198443
...
...
@@ -8,6 +8,7 @@ import { secondColor } from '../../assets/color/color';
import
CountDown
from
'
react-native-countdown-component
'
;
import
client
from
"
../client/Client
"
;
import
Voice
from
'
@react-native-voice/voice
'
;
import
AudioRecord
from
'
react-native-audio-record
'
;
import
Tts
from
'
react-native-tts
'
;
import
BackButton
from
"
../../component/BackButton
"
import
AsyncStorage
from
'
@react-native-async-storage/async-storage
'
;
...
...
@@ -26,6 +27,8 @@ export default function Blue2() {
Voice
.
destroy
().
then
(
Voice
.
removeAllListeners
);
StatusBar
.
setHidden
(
true
);
audioInit
();
const
unsubscribe
=
navigation
.
addListener
(
"
focus
"
,
()
=>
{
Orientation
.
unlockAllOrientations
();
...
...
@@ -49,6 +52,76 @@ export default function Blue2() {
};
},
[]);
function
audioInit
()
{
// console.log('audioInit');
const
colorAudio
=
{
sampleRate
:
16000
,
channels
:
1
,
bitsPerSample
:
16
,
wavFile
:
'
color.wav
'
,
// thise wave file name
};
AudioRecord
.
init
(
colorAudio
);
}
async
function
audioStart
()
{
// console.log('audioStart');
// checkPermission();
AudioRecord
.
start
();
setTimeout
(()
=>
{
audioStop
();
},
2000
);
}
async
function
audioStop
()
{
// console.log('audioStop');
let
audioFile
=
await
AudioRecord
.
stop
();
// console.log('userFile', audioFile);
sendAudio
(
audioFile
);
}
function
sendAudio
(
audioFile
)
{
var
obj
=
{
uri
:
`file:
${
audioFile
}
`
,
type
:
'
audio/wav
'
,
name
:
secondColor
[
4
]
+
'
.wav
'
,
}
var
data
=
JSON
.
stringify
(
obj
)
// console.log(data);
client
.
post
(
"
predict
"
,
data
,
{
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
})
.
then
((
response
)
=>
{
// setNames(response.data);
console
.
log
(
'
Success part :
'
,
response
.
data
);
})
.
catch
(
function
(
error
)
{
if
(
error
.
response
)
{
console
.
log
(
'
Error data :
'
,
error
.
response
.
data
);
console
.
log
(
'
Error status :
'
,
error
.
response
.
status
);
console
.
log
(
'
Error headers :
'
,
error
.
response
.
headers
);
}
else
if
(
error
.
request
)
{
console
.
log
(
'
Error request :
'
,
error
.
request
);
}
else
{
console
.
log
(
'
Error message :
'
,
error
.
message
);
}
console
.
log
(
'
Error else part :
'
,
error
.
config
);
});
}
const
onSpeechStartHandler
=
e
=>
{
// console.log('start handler =>> ', e);
};
...
...
@@ -73,11 +146,7 @@ export default function Blue2() {
sendData
(
mainColor
[
4
]);
showAlert
=
()
=>
{
this
.
setState
({
showAlert
:
true
});
};
audioStart
();
}
else
{
...
...
frontend/src/screen/activity/Green.js
View file @
f2198443
...
...
@@ -9,8 +9,7 @@ import { secondColor } from '../../assets/color/color';
import
client
from
"
../client/Client
"
;
import
Voice
from
'
@react-native-voice/voice
'
;
import
AsyncStorage
from
'
@react-native-async-storage/async-storage
'
;
import
AudioRecord
from
'
react-native-audio-record
'
;
import
BackButton
from
"
../../component/BackButton
"
...
...
@@ -29,6 +28,8 @@ export default function Green({ navigation }) {
StatusBar
.
setHidden
(
true
);
audioInit
();
const
unsubscribe
=
navigation
.
addListener
(
"
focus
"
,
()
=>
{
Orientation
.
unlockAllOrientations
();
...
...
@@ -50,6 +51,77 @@ export default function Green({ navigation }) {
};
},
[]);
function
audioInit
()
{
// console.log('audioInit');
const
colorAudio
=
{
sampleRate
:
16000
,
channels
:
1
,
bitsPerSample
:
16
,
wavFile
:
'
color.wav
'
,
// thise wave file name
};
AudioRecord
.
init
(
colorAudio
);
}
async
function
audioStart
()
{
// console.log('audioStart');
// checkPermission();
AudioRecord
.
start
();
setTimeout
(()
=>
{
audioStop
();
},
2000
);
}
async
function
audioStop
()
{
// console.log('audioStop');
let
audioFile
=
await
AudioRecord
.
stop
();
// console.log('userFile', audioFile);
sendAudio
(
audioFile
);
}
function
sendAudio
(
audioFile
)
{
var
obj
=
{
uri
:
`file:
${
audioFile
}
`
,
type
:
'
audio/wav
'
,
name
:
secondColor
[
1
]
+
'
.wav
'
,
}
var
data
=
JSON
.
stringify
(
obj
)
// console.log(data);
client
.
post
(
"
predict
"
,
data
,
{
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
})
.
then
((
response
)
=>
{
// setNames(response.data);
console
.
log
(
'
Success part :
'
,
response
.
data
);
})
.
catch
(
function
(
error
)
{
if
(
error
.
response
)
{
console
.
log
(
'
Error data :
'
,
error
.
response
.
data
);
console
.
log
(
'
Error status :
'
,
error
.
response
.
status
);
console
.
log
(
'
Error headers :
'
,
error
.
response
.
headers
);
}
else
if
(
error
.
request
)
{
console
.
log
(
'
Error request :
'
,
error
.
request
);
}
else
{
console
.
log
(
'
Error message :
'
,
error
.
message
);
}
console
.
log
(
'
Error else part :
'
,
error
.
config
);
});
}
const
onSpeechStartHandler
=
e
=>
{
// console.log('start handler =>> ', e);
};
...
...
@@ -70,17 +142,11 @@ export default function Green({ navigation }) {
if
(
value
.
includes
(
secondColor
[
1
])
==
true
)
{
const
value
=
e
.
value
;
console
.
log
(
'
Your Answer is Correct
'
);
sendData
(
mainColor
[
1
])
// showAlert = () => {
// this.setState({
// showAlert: true
// });
// };
audioStart
();
}
else
{
...
...
frontend/src/screen/activity/Red.js
View file @
f2198443
...
...
@@ -7,7 +7,9 @@ import axios from "axios";
import
{
secondColor
}
from
'
../../assets/color/color
'
;
import
CountDown
from
'
react-native-countdown-component
'
;
import
client
from
"
../client/Client
"
;
import
Tts
from
'
react-native-tts
'
;
import
Voice
from
'
@react-native-voice/voice
'
;
import
AudioRecord
from
'
react-native-audio-record
'
;
import
BackButton
from
"
../../component/BackButton
"
import
AsyncStorage
from
'
@react-native-async-storage/async-storage
'
;
...
...
@@ -26,6 +28,10 @@ export default function Red({ navigation }) {
StatusBar
.
setHidden
(
true
);
audioInit
();
const
unsubscribe
=
navigation
.
addListener
(
"
focus
"
,
()
=>
{
Orientation
.
unlockAllOrientations
();
...
...
@@ -48,6 +54,76 @@ export default function Red({ navigation }) {
};
},
[]);
function
audioInit
()
{
// console.log('audioInit');
const
colorAudio
=
{
sampleRate
:
16000
,
channels
:
1
,
bitsPerSample
:
16
,
wavFile
:
'
color.wav
'
,
// thise wave file name
};
AudioRecord
.
init
(
colorAudio
);
}
async
function
audioStart
()
{
// console.log('audioStart');
// checkPermission();
AudioRecord
.
start
();
setTimeout
(()
=>
{
audioStop
();
},
2000
);
}
async
function
audioStop
()
{
// console.log('audioStop');
let
audioFile
=
await
AudioRecord
.
stop
();
// console.log('userFile', audioFile);
sendAudio
(
audioFile
);
}
function
sendAudio
(
audioFile
)
{
var
obj
=
{
uri
:
`file:
${
audioFile
}
`
,
type
:
'
audio/wav
'
,
name
:
secondColor
[
0
]
+
'
.wav
'
,
}
var
data
=
JSON
.
stringify
(
obj
)
// console.log(data);
client
.
post
(
"
predict
"
,
data
,
{
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
})
.
then
((
response
)
=>
{
// setNames(response.data);
console
.
log
(
'
Success part :
'
,
response
.
data
);
})
.
catch
(
function
(
error
)
{
if
(
error
.
response
)
{
console
.
log
(
'
Error data :
'
,
error
.
response
.
data
);
console
.
log
(
'
Error status :
'
,
error
.
response
.
status
);
console
.
log
(
'
Error headers :
'
,
error
.
response
.
headers
);
}
else
if
(
error
.
request
)
{
console
.
log
(
'
Error request :
'
,
error
.
request
);
}
else
{
console
.
log
(
'
Error message :
'
,
error
.
message
);
}
console
.
log
(
'
Error else part :
'
,
error
.
config
);
});
}
const
onSpeechStartHandler
=
e
=>
{
// console.log('start handler =>> ', e);
};
...
...
@@ -69,18 +145,15 @@ export default function Red({ navigation }) {
if
(
value
.
includes
(
secondColor
[
0
])
==
true
)
{
console
.
log
(
'
Your Answer is Correct
'
);
sendData
(
mainColor
[
0
]);
sendData
(
mainColor
[
0
])
// showAlert = () => {
// this.setState({
// showAlert: true
// });
// };
audioStart
();
}
else
{
console
.
log
(
'
Your Answer is Incorrect
'
,
value
);
setModalVisible3
(
true
);
}
...
...
@@ -242,7 +315,7 @@ export default function Red({ navigation }) {
style
=
{[
styles
.
buttonClose2
]}
onPress
=
{()
=>
navigation
.
navigate
(
"
Green
"
)}
>
<
Image
source
=
{
require
(
'
../../assets/game/next.png
'
)}
resizeMode
=
'
contain
'
style
=
{{
width
:
100
,
height
:
70
,
marginBottom
:
-
10
}}
/
>
<
Image
source
=
{
require
(
'
../../assets/game/next.png
'
)}
resizeMode
=
'
contain
'
style
=
{{
width
:
100
,
height
:
70
,
marginBottom
:
-
10
}}
/
>
<
/TouchableOpacity
>
<
/View
>
<
/View
>
...
...
@@ -272,7 +345,7 @@ export default function Red({ navigation }) {
style
=
{[]}
onPress
=
{()
=>
setModalVisible3
(
!
modalVisible3
)}
>
<
Image
source
=
{
require
(
'
../../assets/alert/tryagain.png
'
)}
resizeMode
=
'
contain
'
style
=
{{
width
:
100
,
height
:
70
,
marginBottom
:
-
1
}}
/
>
<
Image
source
=
{
require
(
'
../../assets/alert/tryagain.png
'
)}
resizeMode
=
'
contain
'
style
=
{{
width
:
100
,
height
:
70
,
marginBottom
:
-
1
}}
/
>
<
/TouchableOpacity
>
<
/View
>
<
/View
>
...
...
@@ -394,10 +467,10 @@ const styles = StyleSheet.create({
elevation
:
2
},
centeredView2
:
{
flex
:
1
,
justifyContent
:
"
center
"
,
...
...
@@ -455,7 +528,7 @@ const styles = StyleSheet.create({
textAlign
:
"
center
"
,
fontSize
:
30
,
marginBottom
:
20
,
},
alert2
:
{
},
alert2
:
{
backgroundColor
:
"
white
"
,
borderRadius
:
50
,
width
:
100
,
...
...
@@ -464,11 +537,11 @@ const styles = StyleSheet.create({
marginTop
:
-
80
},
centeredView3
:
{
flex
:
1
,
justifyContent
:
"
center
"
,
...
...
frontend/src/screen/activity/White.js
View file @
f2198443
...
...
@@ -7,6 +7,7 @@ import axios from "axios";
import
{
secondColor
}
from
'
../../assets/color/color
'
;
import
CountDown
from
'
react-native-countdown-component
'
;
import
client
from
"
../client/Client
"
;
import
AudioRecord
from
'
react-native-audio-record
'
;
import
Voice
from
'
@react-native-voice/voice
'
;
import
AsyncStorage
from
'
@react-native-async-storage/async-storage
'
;
import
BackButton
from
"
../../component/BackButton
"
...
...
@@ -26,6 +27,8 @@ export default function White() {
StatusBar
.
setHidden
(
true
);
audioInit
();
const
unsubscribe
=
navigation
.
addListener
(
"
focus
"
,
()
=>
{
Orientation
.
unlockAllOrientations
();
...
...
@@ -49,6 +52,76 @@ export default function White() {
};
},
[]);
function
audioInit
()
{
// console.log('audioInit');
const
colorAudio
=
{
sampleRate
:
16000
,
channels
:
1
,
bitsPerSample
:
16
,
wavFile
:
'
color.wav
'
,
// thise wave file name
};
AudioRecord
.
init
(
colorAudio
);
}
async
function
audioStart
()
{
// console.log('audioStart');
// checkPermission();
AudioRecord
.
start
();
setTimeout
(()
=>
{
audioStop
();
},
2000
);
}
async
function
audioStop
()
{
// console.log('audioStop');
let
audioFile
=
await
AudioRecord
.
stop
();
// console.log('userFile', audioFile);
sendAudio
(
audioFile
);
}
function
sendAudio
(
audioFile
)
{
var
obj
=
{
uri
:
`file:
${
audioFile
}
`
,
type
:
'
audio/wav
'
,
name
:
secondColor
[
5
]
+
'
.wav
'
,
}
var
data
=
JSON
.
stringify
(
obj
)
// console.log(data);
client
.
post
(
"
predict
"
,
data
,
{
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
})
.
then
((
response
)
=>
{
// setNames(response.data);
console
.
log
(
'
Success part :
'
,
response
.
data
);
})
.
catch
(
function
(
error
)
{
if
(
error
.
response
)
{
console
.
log
(
'
Error data :
'
,
error
.
response
.
data
);
console
.
log
(
'
Error status :
'
,
error
.
response
.
status
);
console
.
log
(
'
Error headers :
'
,
error
.
response
.
headers
);
}
else
if
(
error
.
request
)
{
console
.
log
(
'
Error request :
'
,
error
.
request
);
}
else
{
console
.
log
(
'
Error message :
'
,
error
.
message
);
}
console
.
log
(
'
Error else part :
'
,
error
.
config
);
});
}
const
onSpeechStartHandler
=
e
=>
{
// console.log('start handler =>> ', e);
};
...
...
@@ -73,11 +146,7 @@ export default function White() {
sendData
(
mainColor
[
5
])
showAlert
=
()
=>
{
this
.
setState
({
showAlert
:
true
});
};
audioStart
();
}
else
{
...
...
@@ -141,14 +210,6 @@ export default function White() {
// setPartialResults(e.value);
};
const
onFinishCD
=
()
=>
{
Alert
.
alert
(
'
Countdown Finished...
'
);
}
const
onPressCD
=
()
=>
{
Alert
.
alert
(
'
Countdown Component Pressed...
'
);
}
const
startRecording
=
async
()
=>
{
setModalVisible
(
true
);
...
...
frontend/src/screen/activity/Yellow.js
View file @
f2198443
...
...
@@ -8,6 +8,7 @@ import CountDown from 'react-native-countdown-component';
import
{
mainColor
}
from
'
../../assets/color/color
'
;
import
client
from
"
../client/Client
"
;
import
Voice
from
'
@react-native-voice/voice
'
;
import
AudioRecord
from
'
react-native-audio-record
'
;
import
AsyncStorage
from
'
@react-native-async-storage/async-storage
'
;
import
BackButton
from
"
../../component/BackButton
"
...
...
@@ -25,6 +26,8 @@ export default function Yellow() {
Voice
.
destroy
().
then
(
Voice
.
removeAllListeners
);
StatusBar
.
setHidden
(
true
);
audioInit
();
const
unsubscribe
=
navigation
.
addListener
(
"
focus
"
,
()
=>
{
Orientation
.
unlockAllOrientations
();
...
...
@@ -48,6 +51,76 @@ export default function Yellow() {
};
},
[]);
function
audioInit
()
{
// console.log('audioInit');
const
colorAudio
=
{
sampleRate
:
16000
,
channels
:
1
,
bitsPerSample
:
16
,
wavFile
:
'
color.wav
'
,
// thise wave file name
};
AudioRecord
.
init
(
colorAudio
);
}
async
function
audioStart
()
{
// console.log('audioStart');
// checkPermission();
AudioRecord
.
start
();
setTimeout
(()
=>
{
audioStop
();
},
2000
);
}
async
function
audioStop
()
{
// console.log('audioStop');
let
audioFile
=
await
AudioRecord
.
stop
();
// console.log('userFile', audioFile);
sendAudio
(
audioFile
);
}
function
sendAudio
(
audioFile
)
{
var
obj
=
{
uri
:
`file:
${
audioFile
}
`
,
type
:
'
audio/wav
'
,
name
:
secondColor
[
3
]
+
'
.wav
'
,
}
var
data
=
JSON
.
stringify
(
obj
)
// console.log(data);
client
.
post
(
"
predict
"
,
data
,
{
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
})
.
then
((
response
)
=>
{
// setNames(response.data);
console
.
log
(
'
Success part :
'
,
response
.
data
);
})
.
catch
(
function
(
error
)
{
if
(
error
.
response
)
{
console
.
log
(
'
Error data :
'
,
error
.
response
.
data
);
console
.
log
(
'
Error status :
'
,
error
.
response
.
status
);
console
.
log
(
'
Error headers :
'
,
error
.
response
.
headers
);
}
else
if
(
error
.
request
)
{
console
.
log
(
'
Error request :
'
,
error
.
request
);
}
else
{
console
.
log
(
'
Error message :
'
,
error
.
message
);
}
console
.
log
(
'
Error else part :
'
,
error
.
config
);
});
}
const
onSpeechStartHandler
=
e
=>
{
// console.log('start handler =>> ', e);
};
...
...
@@ -72,11 +145,7 @@ export default function Yellow() {
sendData
(
mainColor
[
3
])
showAlert
=
()
=>
{
this
.
setState
({
showAlert
:
true
});
};
audioStart
();
}
else
{
...
...
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