diff --git a/pupil_src/capture/recorder.py b/pupil_src/capture/recorder.py index 82c3e42795..fd97f4d239 100644 --- a/pupil_src/capture/recorder.py +++ b/pupil_src/capture/recorder.py @@ -17,7 +17,7 @@ from time import strftime,localtime,time,gmtime from shutil import copy2 from glob import glob -from audio import Audio_Capture +from audio import Audio_Capture,Audio_Input_Dict #logging import logging logger = logging.getLogger(__name__) @@ -77,7 +77,7 @@ def sanitize_timestamps(ts): class Recorder(Plugin): """Capture Recorder""" - def __init__(self,g_pool,session_name = get_auto_name(),user_info={'name':'','additional_field':'change_me'},info_menu_conf={},show_info_menu=False, record_eye = False, audio_src = -1, menu_conf = {}): + def __init__(self,g_pool,session_name = get_auto_name(),user_info={'name':'','additional_field':'change_me'},info_menu_conf={},show_info_menu=False, record_eye = False, audio_src = 'No Audio', menu_conf = {}): super(Recorder, self).__init__(g_pool) #update name if it was autogenerated. if session_name.startswith('20') and len(session_name)==10: @@ -86,7 +86,11 @@ def __init__(self,g_pool,session_name = get_auto_name(),user_info={'name':'','ad self.order = .9 self.record_eye = record_eye self.session_name = session_name - self.audio_src = audio_src + self.audio_devices_dict = Audio_Input_Dict() + if audio_src in self.audio_devices_dict.keys(): + self.audio_src = audio_src + else: + self.audio_src = 'No Audio' self.running = False self.menu = None self.button = None @@ -96,6 +100,7 @@ def __init__(self,g_pool,session_name = get_auto_name(),user_info={'name':'','ad self.show_info_menu = show_info_menu self.info_menu = None self.info_menu_conf = info_menu_conf + self.height, self.width = self.g_pool.capture.frame_size def get_init_dict(self): @@ -124,6 +129,7 @@ def init_gui(self): self.menu.append(ui.Switch('show_info_menu',self,on_val=True,off_val=False,label='Request additional user info')) self.menu.append(ui.Info_Text('Recording the raw eye video is optional. We use it for debugging.')) self.menu.append(ui.Switch('record_eye',self,on_val=True,off_val=False,label='Record eye')) + self.menu.append(ui.Selector('audio_src',self, selection=self.audio_devices_dict.keys())) self.button = ui.Thumb('running',self,setter=self.toggle,label='Record',hotkey='r') self.button.on_color[:] = (1,.0,.0,.8) @@ -189,14 +195,14 @@ def start(self): f.write("Start Time\t"+ strftime("%H:%M:%S", localtime(self.start_time))+ "\n") - if self.audio_src >=0: + if self.audio_src != 'No Audio': audio_path = os.path.join(self.rec_path, "world.wav") - self.audio_writer = Audio_Capture(self.audio_src,audio_path) + self.audio_writer = Audio_Capture(self.audio_devices_dict[self.audio_src],audio_path) else: self.audio_writer = None self.video_path = os.path.join(self.rec_path, "world.mkv") - self.writer = None + self.writer = cv2.VideoWriter(self.video_path, cv2.cv.CV_FOURCC(*'DIVX'), float(self.g_pool.capture.frame_rate), self.g_pool.capture.frame_size) # positions path to eye process if self.record_eye: for tx in self.g_pool.eye_tx: @@ -231,9 +237,6 @@ def close_info_menu(self): def update(self,frame,events): if self.running: - if not self.writer: - self.writer = cv2.VideoWriter(self.video_path, cv2.cv.CV_FOURCC(*'DIVX'), float(self.g_pool.capture.frame_rate), (frame.width,frame.height)) - self.height, self.width = frame.height,frame.width # cv2.putText(frame.img, "Frame %s"%self.frame_count,(200,200), cv2.FONT_HERSHEY_SIMPLEX,1,(255,100,100)) for p in events['pupil_positions']: diff --git a/pupil_src/capture/world.py b/pupil_src/capture/world.py index 740ac6fdd9..83d33e7b92 100644 --- a/pupil_src/capture/world.py +++ b/pupil_src/capture/world.py @@ -39,7 +39,6 @@ # helpers/utils from methods import normalize, denormalize,Temp from video_capture import autoCreateCapture, FileCaptureError, EndofVideoFileError, CameraCaptureError, FakeCapture -from audio import Audio_Input_List # Plug-ins diff --git a/pupil_src/shared_modules/audio/__init__.py b/pupil_src/shared_modules/audio/__init__.py index 25d99e18c7..c34c65ae06 100644 --- a/pupil_src/shared_modules/audio/__init__.py +++ b/pupil_src/shared_modules/audio/__init__.py @@ -63,11 +63,11 @@ def say(message): print message - class Audio_Input_List(list): - """docstring for Audio_Input_List""" + class Audio_Input_Dict(dict): + """docstring for Audio_Input_Dict""" def __init__(self): - super(Audio_Input_List, self).__init__() - self.append(('No Audio',-1)) + super(Audio_Input_Dict, self).__init__() + self['No Audio'] =-1 try: ret = sp.check_output([arecord_bin,"-l"]) except OSError: @@ -92,7 +92,7 @@ def __init__(self): device_names = [w.split(":")[-1] for w in devices] device_names = [w[1:] for w in device_names] for d,idx in zip(device_names,range(len(device_names))): - self.append((d,idx)) + self[d] = idx class Audio_Capture(object): @@ -110,7 +110,7 @@ def __init__(self,audio_src_idx=0, out_file='out.wav'): '-r', '16000', '-f', 'S16_LE', '-c', '2', - '-q', #we use quite because signint will write into stderr and we sue this to check for real errors. + '-q', #we use quite because signint will write into stderr and we use this to check for real errors. out_file] try: self.process = sp.Popen(command,stdout=sp.PIPE,stderr=sp.PIPE) @@ -134,16 +134,12 @@ def __del__(self): elif os_name == "Darwin": - - - class Audio_Input_List(list): - """docstring for Audio_Input_List""" + class Audio_Input_Dict(dict): + """docstring for Audio_Input_Dict""" def __init__(self): - super(Audio_Input_List, self).__init__() - self.append(('No Audio',-1)) - self.append(('Default Mic',0)) - - + super(Audio_Input_Dict, self).__init__() + self['No Audio'] = -1 + self['Default Mic'] = 0 # if getattr(sys, 'frozen', False): # # we are running in a |PyInstaller| bundle @@ -202,11 +198,11 @@ def say(message): print message - class Audio_Input_List(list): - """docstring for Audio_Input_List""" + class Audio_Input_Dict(dict): + """docstring for Audio_Input_Dict""" def __init__(self): - super(Audio_Input_List, self).__init__() - self.append(('No Audio Available',-1)) + super(Audio_Input_Dict, self).__init__() + self['No Audio'] = -1 class Audio_Capture(object): @@ -227,4 +223,4 @@ def __init__(self, audio_src_idx=0, out_file='out.wav'): say("Hello, I am Pupil's audio module.") sleep(3) cap = None - print Audio_Input_List() + print Audio_Input_Dict()