forked from gmaggiotti/EEG-wink2voice-AI
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.py
58 lines (46 loc) · 1.6 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from connector.NeuroskyConnector import NeuroskyConnector
from bluetooth.btcommon import BluetoothError
from neurosky.parser import ThinkGearParser, TimeSeriesRecorder
import wink, states
from Talk import Talk
import sys
from nnet.A4NN import A4NN
conn = NeuroskyConnector()
socket = conn.getConnectionInstance()
recorder = TimeSeriesRecorder()
parser = ThinkGearParser(recorders= [recorder])
w = wink.Wink()
s = states.States()
t = Talk()
net = A4NN()
net.train()
test_dataset=[87,87,97,97,97,97,97,97,97,97,97,97,107,107,107,107,107,107,167,247,55,29,59,59,29,29,29,129,129,129,129,307,309,92,37,60,72,75,97]
result = net.predict(test_dataset)
print("test-set validation. Expected: ~0 - Result:" + repr(result))
test_dataset=[85,85,85,85,85,85,85,85,85,72,72,72,97,149,337,436,436,436,436,436,436,436,436,436,436,401,295,55,55,55,55,65,121,141,141,141,141,141,141]
result = net.predict(test_dataset)
print("test-set validation. Expected: ~1 - Result:" + repr(result))
i=0
myList=[]
while socket is not None:
try:
data = socket.recv(1000)
parser.feed(data)
max = recorder.raw[-100:].max()
if(i==39):
prediction = net.predict(myList)
print("Output of example should be:" + repr(prediction))
if( prediction > 0.8 ):
s.addWink()
count = s.getWinkWithinDelta()
if( count == 1 ):
t.sayYes()
elif( count == 2 ):
t.sayNo()
i=0
myList = []
if(i<39):
myList.append(max)
i = i + 1
except BluetoothError:
pass