-
Notifications
You must be signed in to change notification settings - Fork 0
/
MusicSuggestions.py
76 lines (59 loc) · 2.51 KB
/
MusicSuggestions.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import UnicornPy
from neurol import streams
from neurol.connect_device import get_lsl_EEG_inlets
from neurol.BCI import generic_BCI, automl_BCI
from neurol import BCI_tools
from neurol.models import classification_tools
from sys import exit
from pylsl import StreamInlet, resolve_stream
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import time
print("Enter the calibration period (in seconds).")
calib_time = input()
print("Enter a wave type ('theta', 'alpha_low', 'alpha_high', 'beta', 'gamma')")
wave_type = input()
#can include later but where it currently says 'beta' , 'alpha_low' change to wave_type
clb = lambda stream: BCI_tools.band_power_calibrator(stream, ['EEG 1', 'EEG 2', 'EEG 3', 'EEG 4', 'EEG 5', 'EEG 6', 'EEG 7', 'EEG 8'], 'unicorn', bands=['beta', 'alpha_low'],
percentile=5, recording_length=int(calib_time), epoch_len=1, inter_window_interval=0.25)
gen_tfrm = lambda buffer, clb_info: BCI_tools.band_power_transformer(buffer, clb_info, ['EEG 1', 'EEG 2', 'EEG 3', 'EEG 4', 'EEG 5', 'EEG 6', 'EEG 7', 'EEG 8'], 'unicorn', bands=['beta', 'alpha_low'],
epoch_len=1)
global xs, EEG1, EEG2, EEG3, EEG4, EEG5, EEG6, EEG7, EEG8
xs = []
EEG1 = []
EEG2 = []
EEG3 = []
EEG4 = []
EEG5 = []
EEG6 = []
EEG7 = []
EEG8 = []
binary_label_arr = []
def clf(clf_input, clb_info):
#print ("clb info: ", clb_info)
clf_input = clf_input[:clb_info.shape[0]]
EEG1.append(clf_input[0][0])
EEG2.append(clf_input[0][1])
EEG3.append(clf_input[0][2])
EEG4.append(clf_input[0][3])
EEG5.append(clf_input[0][4])
EEG6.append(clf_input[0][5])
EEG7.append(clf_input[0][6])
EEG8.append(clf_input[0][7])
xs.append(len(EEG1))
binary_label = classification_tools.threshold_clf(clf_input, clb_info, clf_consolidator='all')
label = classification_tools.decode_prediction(
binary_label, {True: 'HIGH', False: 'LOW'})
print ("Label is:", label)
#binary_label_arr.append(label)
exit()
return label
print (len(binary_label_arr))
streams1 = resolve_stream("name='Unicorn'")
inlet = StreamInlet(streams1[0])
stream = streams.lsl_stream(inlet, buffer_length=1024)
GPT_Generic = generic_BCI(clf, transformer=gen_tfrm, action=print, calibrator=clb)
print ("Did we get here???\n")
GPT_Generic.calibrate(stream)
GPT_Generic.run(stream)