/
audio_notes_recorder.py
48 lines (36 loc) · 1003 Bytes
/
audio_notes_recorder.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
# coding=utf-8
import threading
import pyaudio
from datetime import datetime, time
import os
# coding=utf-8
##TODO обернуть в класс
from Recorder import Recorder
is_recording = False;
current_audio_file = []
def start_recording():
global is_recording, current_audio_file
is_recording = True;
time_stamp = datetime.now()
filename = time_stamp.strftime('%Y_%m_%d_%H_%M_%S') + ".wav"
print ("Start recording")
rec = Recorder(channels=2)
current_audio_file = rec.open(filename, 'wb')
current_audio_file.start_recording()
threading.Timer(1, sound).start()
def sound():
os.system('\a')
print ("Sound")
def end_recording():
global is_recording, current_audio_file
is_recording = False;
print ("Sound")
os.system('\a')
print ("Stop recording")
current_audio_file.stop_recording()
current_audio_file.close();
def user_handler():
if (is_recording):
end_recording();
else:
start_recording();