1 # -*- coding: utf-8 -*-
2 # Spec_Recoeder Ver.1.02
4 # Author = Yuta Minakawa
23 conf = ConfigParser.SafeConfigParser()
24 conf.read("./sr.conf")
25 if conf.get("sox","high_color") == "on":
27 print "high_color is available"
29 print "high_color is unavailable"
31 if conf.get("sox","mono_color") == "on":
33 print "mono_color is available"
35 print "mono_color is unavailable"
37 if conf.get("server", "server") == "on":
38 subprocess.Popen(["python", "server.py"])
39 print "HTTP server is working"
41 print "HTTP server is unavailable"
43 if conf.get("file", "del_ogg") == "on":
45 print "del_ogg is available"
47 print "del_ogg is unavailable"
49 if conf.get("file", "write_filename") == "on":
51 print "filename will be written"
53 print "filename will not be written"
55 if conf.get("file", "write_csv") == "on":
57 print "CSV file will be saved"
59 if conf.get("analyze", "analyze") == "on":
61 print "data will be analyzed"
63 if os.name == 'posix':
64 print "OS = Linux,etc This system is supported"
66 print "OS = Windows This system is NOT supported"
70 subprocess.Popen(['rec', '-c', '1', "test.wav", 'trim', '0', '00:10'])
73 while os.path.exists("test.wav") == 1:
75 wait_time = wait_time + 1
78 subprocess.Popen(["python", "./freq_exec.py", str(wait_time)])
80 subprocess.Popen(["python", "./freq_exec.py", "0"])
85 def write_cara(x,y,string,filename):
86 font = ImageFont.truetype("/usr/share/fonts/truetype/takao-gothic/TakaoGothic.ttf", 15, encoding="utf-8")
87 img = Image.open(filename)
88 draw = ImageDraw.Draw(img)
89 draw.text((x,y), string, font=font, fill=255)
94 output = subprocess.call()
97 def how_long(filename):
98 output = subprocess.check_output(["soxi", "-d", filename])
101 ten_second = output[6]
103 file_info = (minute , ten_second, second)
106 def write2freq_exec(content):
107 f = open('text.txt', 'w')
112 #output = subprocess.call(['sox', filename + ".ogg", "-n", 'rate', '3k',"spectrogram" , "-X", "8", "-Y", "300", "-o", filename + ".png" ])
113 oggfilename = "./ogg/" + filename + ".ogg"
114 pngfilename = "./PNG/" + filename + ".png"
117 output = subprocess.Popen(['sox', oggfilename[:], "-n", 'rate', '3k',"spectrogram" , "-X", "8", "-Y", "300", "-z", "100", "-q", "30", "-h", "-m", "-o", pngfilename[:] ])
119 output = subprocess.Popen(['sox', oggfilename[:], "-n", 'rate', '3k',"spectrogram" , "-X", "8", "-Y", "300", "-z", "100", "-q", "30", "-h", "-o", pngfilename[:] ])
122 output = subprocess.Popen(['sox', oggfilename[:], "-n", 'rate', '3k',"spectrogram" , "-X", "8", "-Y", "300", "-z", "100", "-q", "30", "-m", "-o", pngfilename[:] ])
124 output = subprocess.Popen(['sox', oggfilename[:], "-n", 'rate', '3k',"spectrogram" , "-X", "8", "-Y", "300", "-z", "100", "-q", "30", "-o", pngfilename[:] ])
125 print filename +".png" + " was made"
128 subprocess.Popen(['sox', "./ogg/" + filename + ".ogg", "-n", 'rate', '3k',"spectrogram" , "-X", "8", "-Y", "300", "-z", "100", "-q", "30", "-h", "-m"])
130 subprocess.Popen(['sox', "./ogg/" + filename + ".ogg", "-n", 'rate', '3k',"spectrogram" , "-X", "8", "-Y", "300", "-z", "100", "-q", "30", "-h"])
133 subprocess.Popen(['sox', "./ogg/" + filename + ".ogg", "-n", 'rate', '3k',"spectrogram" , "-X", "8", "-Y", "300", "-z", "100", "-q", "30", "-m"])
135 subprocess.Popen(['sox', "./ogg/" + filename + ".ogg", "-n", 'rate', '3k',"spectrogram" , "-X", "8", "-Y", "300", "-z", "100", "-q", "30"])
138 print "Spec_Recorder Ver.b"
140 now_minute = int(datetime.datetime.now().strftime("%M"))
141 now_hour = int(datetime.datetime.now().strftime("%H"))
142 now_month = int(datetime.datetime.now().strftime("%m"))
143 now_day = int(datetime.datetime.now().strftime("%d"))
144 now_year = int(datetime.datetime.now().strftime("%Y"))
146 if int(datetime.datetime.now().strftime("%M")) % 5 == 0:
148 subprocess.Popen(["python", "./freq_exec.py", "0"])
149 print "Executed freq_exec.py"
153 if int(datetime.datetime.now().strftime("%M")) % 5 == 0:
154 start_year = str(datetime.datetime.now().strftime("%Y"))[2:]
155 start_month = str(datetime.datetime.now().strftime("%m"))[:]
157 start_month = "0" + str(datetime.datetime.now().strftime("%m"))[:]
158 start_day = str(datetime.datetime.now().strftime("%d"))[:]
160 start_day = "0" + str(datetime.datetime.now().strftime("%d"))[:]
161 start_hour = str(datetime.datetime.now().strftime("%H"))[:]
163 start_hour = "0" + str(datetime.datetime.now().strftime("%H"))[:]
164 start_minute = str(datetime.datetime.now().strftime("%M"))[:]
165 if datetime.datetime.now().strftime("%M") < 10:
166 start_minute = "0" + str(datetime.datetime.now().strftime("%M"))[:]
167 filename = str(start_year)[:] + str(start_month)[:] + str(start_day)[:] + str(start_hour)[:] + str(start_minute)[:]
168 print "Audio fileneme is " + filename + ".ogg"
169 print "Waiting 5 minutes"
171 for cnt in range(1000):
172 if os.path.exists("./ogg/" + filename + ".ogg") == 1:
173 if how_long("./ogg/"+ filename + ".ogg")[0] == "5":
175 #print "Waiting for " + filename +".ogg."
179 subprocess.call(["rm", "./ogg/" + filename + ".ogg"])
180 for cnt in range(20):
181 if os.path.exists("./PNG/" + filename + ".png") == 1:
182 print filename + ".png is exist"
184 print "Waiting for " + filename +".png"
186 if write_filename == 1:
187 if os.path.exists("./PNG/" + filename + ".png") == 1:
188 write_string = filename[:]
189 write_cara(90,320,write_string,"./PNG/" + filename + ".png")
190 write_cara(90,320,write_string,"spectrogram" + ".png")
192 print "Error! " + filename + ".png is not found"
196 subprocess.Popen(["python", "./make_csv.py", "-c", filename])
199 subprocess.Popen(["python", "./make_csv.py", "-ac", filename])
200 #img = Image.open(filename + ".png")
201 #im = ImageDraw.ImageDraw(img)
202 #im.rectangle((100, 100, 300, 300))