-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (52 loc) · 1.66 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import time
from PySerialMonitor import PySerialMonitor
from Processor import Processor
import logging as log
from threading import Thread
log.basicConfig(
# filename="coderock.log",
level=log.DEBUG,
format='%(asctime)s - %(message)s')
config = {
'debug': False,
'log': True,
'console': True
}
psm = PySerialMonitor(debug=False, baudrate=115200)
proc = Processor()
def setup():
if config['log']:
log.info('Application Launched!')
def loop():
if psm.available():
print('Monitor print command received: ', psm.data)
command = psm.data
if command['CMD'] == 'record' and proc.status == 'stopped':
print('Record Voice, voice id: ', command['CONTENT'])
# proc.record_with_timer(file_name=command['CONTENT'])
async_recorder(receive_msg)
if command['CMD'] == 'play' and proc.status == 'stopped':
print('Play Voice, voice id: ', command['CONTENT'])
proc.play_file(file_name=command['CONTENT'])
if command['CMD'] == 'stop' and proc.status == 'recording':
print('Try to stop recording!')
proc.status = 'stopped'
def async_recorder(cb):
def func(callback):
print("Start recording async thread! ")
proc.record_file(file_name=psm.data['CONTENT'])
res = 'Finished'
callback(res)
print('Finish recording and close thread')
t1 = Thread(target=func, args=(cb,))
t1.start()
def receive_msg(res):
print("Return result: ", res)
def main():
setup()
if config['log']:
log.info('Enter Loop! ')
while True:
loop()
if __name__ == "__main__":
main()