def __init__(self, idx, channels=None): self.channels = channels if channels is not None else pyo.pa_get_output_max_channels( idx) self.server = pyo.Server(nchnls=self.channels, ichnls=0).boot() self.server.start() self.mixers = {} self.files = {}
def get_devices(): dev_list, dev_index = pyo.pa_get_output_devices() res = [] for idx, dev_name in enumerate(dev_list): res.append( dict(idx=dev_index[idx], name=dev_name, channels=pyo.pa_get_output_max_channels(dev_index[idx]))) return res
def GetAudioOutputs(self): if not hasattr(self, '_audio_outputs'): output_device_names, output_device_indexes = pyo.pa_get_output_devices() default_output_index = pyo.pa_get_default_output() audio_outputs = {} for output_index, output_name in zip(output_device_indexes, output_device_names): output_max_channels = pyo.pa_get_output_max_channels(output_index) audio_outputs[output_index] = { 'name': output_name, 'default': bool(output_index == default_output_index), 'channels': output_max_channels, } setattr(self, '_audio_outputs', audio_outputs) return getattr(self, '_audio_outputs')
def setDefaultSoundDevice(self): """AudioTheme Class """ self.output_device_index = self.view.select_audio_output.currentIndex() n_out_channel = pa_get_output_max_channels(self.output_device_index+1) if self.audio_controller == None: self.audio_controller = actrl.AudioController(n_out_channel,self.output_device_index) self.view.button_start.setEnabled(True) self.view.button_start_default.setEnabled(False) self.view.button_listen_task.setEnabled(True) self.view.button_listen_task_2.setEnabled(True) self.view.select_audio_output.setEnabled(False) self.view.audio_submit.setEnabled(False) self.view.setListInfo('Audio Device paired')
def init(rate=44100, stereo=True, buffer=128): """setup the pyo (sound) server """ global pyoSndServer, Sound, audioDriver, duplex, maxChnls Sound = SoundPyo global pyo try: assert pyo except NameError: # pragma: no cover import pyo # can be needed for microphone.switchOn(), which calls init even # if audioLib is something else # subclass the pyo.Server so that we can insert a __del__ function that # shuts it down skip coverage since the class is never used if we have # a recent version of pyo class _Server(pyo.Server): # pragma: no cover # make libs class variables so they don't get deleted first core = core logging = logging def __del__(self): self.stop() # make sure enough time passes for the server to shutdown self.core.wait(0.5) self.shutdown() # make sure enough time passes for the server to shutdown self.core.wait(0.5) # this may never get printed self.logging.debug('pyo sound server shutdown') if '.'.join(map(str, pyo.getVersion())) < '0.6.4': Server = _Server else: Server = pyo.Server # if we already have a server, just re-initialize it if 'pyoSndServer' in globals() and hasattr(pyoSndServer, 'shutdown'): pyoSndServer.stop() # make sure enough time passes for the server to shutdown core.wait(0.5) pyoSndServer.shutdown() core.wait(0.5) pyoSndServer.reinit(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) pyoSndServer.boot() else: if platform == 'win32': # check for output device/driver devNames, devIDs = pyo.pa_get_output_devices() audioDriver, outputID = _bestDriver(devNames, devIDs) if outputID is None: # using the default output because we didn't find the one(s) # requested audioDriver = 'Windows Default Output' outputID = pyo.pa_get_default_output() if outputID is not None: logging.info('Using sound driver: %s (ID=%i)' % (audioDriver, outputID)) maxOutputChnls = pyo.pa_get_output_max_channels(outputID) else: logging.warning( 'No audio outputs found (no speakers connected?') return -1 # check for valid input (mic) # If no input device is available, devNames and devIDs are empty # lists. devNames, devIDs = pyo.pa_get_input_devices() audioInputName, inputID = _bestDriver(devNames, devIDs) # Input devices were found, but requested devices were not found if len(devIDs) > 0 and inputID is None: defaultID = pyo.pa_get_default_input() if defaultID is not None and defaultID != -1: # default input is found # use the default input because we didn't find the one(s) # requested audioInputName = 'Windows Default Input' inputID = defaultID else: # default input is not available inputID = None if inputID is not None: msg = 'Using sound-input driver: %s (ID=%i)' logging.info(msg % (audioInputName, inputID)) maxInputChnls = pyo.pa_get_input_max_channels(inputID) duplex = bool(maxInputChnls > 0) else: maxInputChnls = 0 duplex = False # for other platforms set duplex to True (if microphone is available) else: audioDriver = prefs.general['audioDriver'][0] maxInputChnls = pyo.pa_get_input_max_channels( pyo.pa_get_default_input()) maxOutputChnls = pyo.pa_get_output_max_channels( pyo.pa_get_default_output()) duplex = bool(maxInputChnls > 0) maxChnls = min(maxInputChnls, maxOutputChnls) if maxInputChnls < 1: # pragma: no cover msg = ('%s.init could not find microphone hardware; ' 'recording not available') logging.warning(msg % __name__) maxChnls = maxOutputChnls if maxOutputChnls < 1: # pragma: no cover msg = ('%s.init could not find speaker hardware; ' 'sound not available') logging.error(msg % __name__) return -1 # create the instance of the server: if platform in ['darwin', 'linux2']: # for mac/linux we set the backend using the server audio param pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) else: # with others we just use portaudio and then set the OutputDevice # below pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer) pyoSndServer.setVerbosity(1) if platform == 'win32': pyoSndServer.setOutputDevice(outputID) if inputID is not None: pyoSndServer.setInputDevice(inputID) # do other config here as needed (setDuplex? setOutputDevice?) pyoSndServer.setDuplex(duplex) pyoSndServer.boot() core.wait(0.5) # wait for server to boot before starting te sound stream pyoSndServer.start() try: Sound() # test creation, no play except pyo.PyoServerStateException: msg = "Failed to start pyo sound Server" if platform == 'darwin' and audioDriver != 'portaudio': msg += "; maybe try prefs.general.audioDriver 'portaudio'?" logging.error(msg) core.quit() logging.debug('pyo sound server started') logging.flush()
def initPyo(rate=44100, stereo=True, buffer=128): """setup the pyo (sound) server """ global pyoSndServer, Sound, audioDriver, duplex, maxChnls Sound = SoundPyo global pyo try: assert pyo except NameError: # pragma: no cover import pyo # microphone.switchOn() calls initPyo even if audioLib is something else #subclass the pyo.Server so that we can insert a __del__ function that shuts it down # skip coverage since the class is never used if we have a recent version of pyo class _Server(pyo.Server): # pragma: no cover core=core #make libs class variables so they don't get deleted first logging=logging def __del__(self): self.stop() self.core.wait(0.5)#make sure enough time passes for the server to shutdown self.shutdown() self.core.wait(0.5)#make sure enough time passes for the server to shutdown self.logging.debug('pyo sound server shutdown')#this may never get printed if '.'.join(map(str, pyo.getVersion())) < '0.6.4': Server = _Server else: Server = pyo.Server # if we already have a server, just re-initialize it if 'pyoSndServer' in globals() and hasattr(pyoSndServer,'shutdown'): pyoSndServer.stop() core.wait(0.5)#make sure enough time passes for the server to shutdown pyoSndServer.shutdown() core.wait(0.5) pyoSndServer.reinit(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) pyoSndServer.boot() else: if platform=='win32': #check for output device/driver devNames, devIDs=pyo.pa_get_output_devices() audioDriver,outputID=_bestDriver(devNames, devIDs) if outputID is None: audioDriver = 'Windows Default Output' #using the default output because we didn't find the one(s) requested outputID = pyo.pa_get_default_output() if outputID is not None: logging.info('Using sound driver: %s (ID=%i)' %(audioDriver, outputID)) maxOutputChnls = pyo.pa_get_output_max_channels(outputID) else: logging.warning('No audio outputs found (no speakers connected?') return -1 #check for valid input (mic) devNames, devIDs = pyo.pa_get_input_devices() audioInputName, inputID = _bestDriver(devNames, devIDs) if inputID is None: audioInputName = 'Windows Default Input' #using the default input because we didn't find the one(s) requested inputID = pyo.pa_get_default_input() if inputID is not None: logging.info('Using sound-input driver: %s (ID=%i)' %(audioInputName, inputID)) maxInputChnls = pyo.pa_get_input_max_channels(inputID) duplex = bool(maxInputChnls > 0) else: maxInputChnls = 0 duplex=False else:#for other platforms set duplex to True (if microphone is available) audioDriver = prefs.general['audioDriver'][0] maxInputChnls = pyo.pa_get_input_max_channels(pyo.pa_get_default_input()) maxOutputChnls = pyo.pa_get_output_max_channels(pyo.pa_get_default_output()) duplex = bool(maxInputChnls > 0) maxChnls = min(maxInputChnls, maxOutputChnls) if maxInputChnls < 1: # pragma: no cover logging.warning('%s.initPyo could not find microphone hardware; recording not available' % __name__) maxChnls = maxOutputChnls if maxOutputChnls < 1: # pragma: no cover logging.error('%s.initPyo could not find speaker hardware; sound not available' % __name__) return -1 # create the instance of the server: if platform in ['darwin', 'linux2']: #for mac/linux we set the backend using the server audio param pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) else: #with others we just use portaudio and then set the OutputDevice below pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer) pyoSndServer.setVerbosity(1) if platform=='win32': pyoSndServer.setOutputDevice(outputID) if inputID is not None: pyoSndServer.setInputDevice(inputID) #do other config here as needed (setDuplex? setOutputDevice?) pyoSndServer.setDuplex(duplex) pyoSndServer.boot() core.wait(0.5)#wait for server to boot before starting te sound stream pyoSndServer.start() try: Sound() # test creation, no play except pyo.PyoServerStateException: msg = "Failed to start pyo sound Server" if platform == 'darwin' and audioDriver != 'portaudio': msg += "; maybe try prefs.general.audioDriver 'portaudio'?" logging.error(msg) core.quit() logging.debug('pyo sound server started') logging.flush()
def initPyo(rate=44100, stereo=True, buffer=128): """setup the pyo (sound) server """ global pyoSndServer, Sound, audioDriver, duplex, maxChnls Sound = SoundPyo if not "pyo" in locals(): import pyo # microphone.switchOn() calls initPyo even if audioLib is something else # subclass the pyo.Server so that we can insert a __del__ function that shuts it down class _Server(pyo.Server): core = core # make libs class variables so they don't get deleted first logging = logging def __del__(self): self.stop() self.core.wait(0.5) # make sure enough time passes for the server to shutdown self.shutdown() self.core.wait(0.5) # make sure enough time passes for the server to shutdown self.logging.debug("pyo sound server shutdown") # this may never get printed if ".".join(map(str, pyo.getVersion())) < "0.6.4": Server = _Server else: Server = pyo.Server # if we already have a server, just re-initialize it if globals().has_key("pyoSndServer") and hasattr(pyoSndServer, "shutdown"): pyoSndServer.stop() core.wait(0.5) # make sure enough time passes for the server to shutdown pyoSndServer.shutdown() core.wait(0.5) pyoSndServer.reinit(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) pyoSndServer.boot() else: if platform == "win32": # check for output device/driver devNames, devIDs = pyo.pa_get_output_devices() audioDriver, outputID = _bestDriver(devNames, devIDs) if outputID: logging.info("Using sound driver: %s (ID=%i)" % (audioDriver, outputID)) maxOutputChnls = pyo.pa_get_output_max_channels(outputID) else: logging.warning("No audio outputs found (no speakers connected?") return -1 # check for valid input (mic) devNames, devIDs = pyo.pa_get_input_devices() audioInputName, inputID = _bestDriver(devNames, devIDs) if inputID is not None: logging.info("Using sound-input driver: %s (ID=%i)" % (audioInputName, inputID)) maxInputChnls = pyo.pa_get_input_max_channels(inputID) duplex = bool(maxInputChnls > 0) else: duplex = False else: # for other platforms set duplex to True (if microphone is available) audioDriver = prefs.general["audioDriver"][0] maxInputChnls = pyo.pa_get_input_max_channels(pyo.pa_get_default_input()) maxOutputChnls = pyo.pa_get_output_max_channels(pyo.pa_get_default_output()) duplex = bool(maxInputChnls > 0) maxChnls = min(maxInputChnls, maxOutputChnls) if maxInputChnls < 1: logging.warning("%s.initPyo could not find microphone hardware; recording not available" % __name__) maxChnls = maxOutputChnls if maxOutputChnls < 1: logging.error("%s.initPyo could not find speaker hardware; sound not available" % __name__) return -1 # create the instance of the server: if platform in ["darwin", "linux2"]: # for mac/linux we set the backend using the server audio param pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) else: # with others we just use portaudio and then set the OutputDevice below pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer) pyoSndServer.setVerbosity(1) if platform == "win32": pyoSndServer.setOutputDevice(outputID) if inputID: pyoSndServer.setInputDevice(inputID) # do other config here as needed (setDuplex? setOutputDevice?) pyoSndServer.setDuplex(duplex) pyoSndServer.boot() core.wait(0.5) # wait for server to boot before starting te sound stream pyoSndServer.start() try: Sound() # test creation, no play except pyo.PyoServerStateException: msg = "Failed to start pyo sound Server" if platform == "darwin" and audioDriver != "portaudio": msg += "; maybe try prefs.general.audioDriver 'portaudio'?" logging.error(msg) core.quit() logging.debug("pyo sound server started") logging.flush()
def initPyo(rate=44100, stereo=True, buffer=128): """setup the pyo (sound) server """ global pyoSndServer, Sound, audioDriver, duplex, maxChnls Sound = SoundPyo if not 'pyo' in locals(): import pyo # microphone.switchOn() calls initPyo even if audioLib is something else #subclass the pyo.Server so that we can insert a __del__ function that shuts it down class _Server(pyo.Server): core=core #make libs class variables so they don't get deleted first logging=logging def __del__(self): self.stop() self.core.wait(0.5)#make sure enough time passes for the server to shutdown self.shutdown() self.core.wait(0.5)#make sure enough time passes for the server to shutdown self.logging.debug('pyo sound server shutdown')#this may never get printed if '.'.join(map(str, pyo.getVersion())) < '0.6.4': Server = _Server else: Server = pyo.Server # if we already have a server, just re-initialize it if globals().has_key('pyoSndServer') and hasattr(pyoSndServer,'shutdown'): pyoSndServer.stop() core.wait(0.5)#make sure enough time passes for the server to shutdown pyoSndServer.shutdown() core.wait(0.5) pyoSndServer.reinit(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) pyoSndServer.boot() else: if platform=='win32': #check for output device/driver devNames, devIDs=pyo.pa_get_output_devices() audioDriver,outputID=_bestDriver(devNames, devIDs) if outputID: logging.info('Using sound driver: %s (ID=%i)' %(audioDriver, outputID)) maxOutputChnls = pyo.pa_get_output_max_channels(outputID) else: logging.warning('No audio outputs found (no speakers connected?') return -1 #check for valid input (mic) devNames, devIDs = pyo.pa_get_input_devices() audioInputName, inputID = _bestDriver(devNames, devIDs) if inputID is not None: logging.info('Using sound-input driver: %s (ID=%i)' %(audioInputName, inputID)) maxInputChnls = pyo.pa_get_input_max_channels(inputID) duplex = bool(maxInputChnls > 0) else: duplex=False else:#for other platforms set duplex to True (if microphone is available) audioDriver = prefs.general['audioDriver'][0] maxInputChnls = pyo.pa_get_input_max_channels(pyo.pa_get_default_input()) maxOutputChnls = pyo.pa_get_output_max_channels(pyo.pa_get_default_output()) duplex = bool(maxInputChnls > 0) maxChnls = min(maxInputChnls, maxOutputChnls) if maxInputChnls < 1: logging.warning('%s.initPyo could not find microphone hardware; recording not available' % __name__) maxChnls = maxOutputChnls if maxOutputChnls < 1: logging.error('%s.initPyo could not find speaker hardware; sound not available' % __name__) return -1 # create the instance of the server: if platform=='darwin': #for mac we set the backend using the server audio param pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) else: #with others we just use portaudio and then set the OutputDevice below pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer) pyoSndServer.setVerbosity(1) if platform=='win32': pyoSndServer.setOutputDevice(outputID) if inputID: pyoSndServer.setInputDevice(inputID) #do other config here as needed (setDuplex? setOutputDevice?) pyoSndServer.setDuplex(duplex) pyoSndServer.boot() core.wait(0.5)#wait for server to boot before starting te sound stream pyoSndServer.start() try: Sound() # test creation, no play except pyo.PyoServerStateException: msg = "Failed to start pyo sound Server" if platform == 'darwin' and audioDriver != 'portaudio': msg += "; maybe try prefs.general.audioDriver 'portaudio'?" logging.error(msg) core.quit() logging.debug('pyo sound server started') logging.flush()
def initPyo(rate=44100, stereo=True, buffer=128): """setup the pyo (sound) server """ global pyoSndServer, Sound, audioDriver, duplex Sound = SoundPyo if not 'pyo' in locals(): import pyo # microphone.switchOn() calls initPyo even if audioLib is something else #subclass the pyo.Server so that we can insert a __del__ function that shuts it down class Server(pyo.Server): core=core #make libs class variables so they don't get deleted first logging=logging def __del__(self): self.stop() self.core.wait(0.5)#make sure enough time passes for the server to shutdown self.shutdown() self.core.wait(0.5)#make sure enough time passes for the server to shutdown self.logging.debug('pyo sound server shutdown')#this may never get printed maxInputChnls = pyo.pa_get_input_max_channels(pyo.pa_get_default_input()) maxOutputChnls = pyo.pa_get_output_max_channels(pyo.pa_get_default_output()) maxChnls = min(maxInputChnls, maxOutputChnls) if maxInputChnls < 1: logging.warning('%s.initPyo could not find microphone hardware; recording not available' % __name__) maxChnls = maxOutputChnls if maxOutputChnls < 1: logging.error('%s.initPyo could not find speaker hardware; sound not available' % __name__) core.quit() #check if we already have a server and kill it if globals().has_key('pyoSndServer') and hasattr(pyoSndServer,'shutdown'): #if it exists and isn't None! #this doesn't appear to work! pyoSndServer.stop() core.wait(0.5)#make sure enough time passes for the server to shutdown pyoSndServer.shutdown() core.wait(0.5) pyoSndServer.reinit(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) pyoSndServer.boot() else: if platform=='win32': #check for output device/driver devNames, devIDs=pyo.pa_get_output_devices() audioDriver,outputID=_bestDriver(devNames, devIDs) if outputID: logging.info('Using sound driver: %s (ID=%i)' %(audioDriver, outputID)) else: logging.warning('No audio outputs found (no speakers connected?') return -1 #check for valid input (mic) devNames, devIDs = pyo.pa_get_input_devices() junk, inputID=_bestDriver(devNames, devIDs) if inputID: duplex = bool(maxInputChnls > 0) else: duplex=False else:#for other platforms set duplex to True (if microphone is available) audioDriver = prefs.general['audioDriver'][0] duplex = bool(maxInputChnls > 0) # create the instance of the server: if platform=='darwin': #for mac we set the backend using the server audio param pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer, audio=audioDriver) else: #with others we just use portaudio and then set the OutputDevice below pyoSndServer = Server(sr=rate, nchnls=maxChnls, buffersize=buffer) pyoSndServer.setVerbosity(1) if platform=='win32': pyoSndServer.setOutputDevice(outputID) if inputID: pyoSndServer.setInputDevice(inputID) #do other config here as needed (setDuplex? setOutputDevice?) pyoSndServer.setDuplex(duplex) pyoSndServer.boot() core.wait(0.5)#wait for server to boot before starting te sound stream pyoSndServer.start() try: Sound() # test creation, no play except pyo.PyoServerStateException: msg = "Failed to start pyo sound Server" if platform == 'darwin' and audioDriver != 'portaudio': msg += "; maybe try prefs.general.audioDriver 'portaudio'?" logging.error(msg) core.quit() logging.debug('pyo sound server started') logging.flush()
def __init__(self, view): """Controller Class Arguments ---------- view : Class view MVC Parameters ---------- camera : camera.Camera() camera init previous_angle : int previous detected angle feat : np.ndarray [pos, radius, theme] stone_feat : np.ndarray [pos, radius, theme] contour_config_v : int erode and dilate iter value output_device_index : int number of output devices path_finder : [] List of sonic anchors in scene calibration_pts : [] Calibrated Points (edges of the sandbox) path_finder_max : int max number of sonic anchors in scene min_move : int init value of moving steps in pixels stop_flag_init : bool init vaule of stop playining music flag stop_flag : bool opposit of stop playining music flag after init is set music_playing_flag : bool mixer stop music flag stones_act_flag : bool Stone wave animation flag time_stamp_activation = time.time() Time stamp for timing, several usage stop_time : time.time() Timer for stop fading out and in e.g. start_time : time.time() Timer for stop fading out and in e.g. audio_controller : AudioController() AudioController Instance cap : np.ndarray Image cap frame c_saveimg : int iterator for naming saved image file logs : Logs() logs instance for saving params """ import matplotlib print "cv2"+cv2.__version__ print "usb"+usb.__version__ print "matplotlib"+matplotlib.__version__ self.view = view self.camera = camera.Camera() self.view.register(self) # self.previous_angle = 0 self.feat = None self.stone_feat = None self.contour_config_v = 2 self.output_device_index = 0 self.path_finder = [] self.calibration_pts = [] self.path_finder_max = 5 self.min_move = 0 self.stop_flag_init = True self.stop_flag = False self.music_playing_flag = False self.stones_act_flag = False self.time_stamp_activation = time.time() self.stop_time = time.time() self.start_time = time.time() self.audio_controller = None self.cap = None self.c_saveimg = 0 self.maxVol = 80 # self.logs = Logs() for i in range(0,self.path_finder_max): self.path_finder.append(pfc.PathFinder()) self.path_finder[i].set_current_point(randint(100,250),randint(100,250)) self.snapshot_trigger = False view.setSliderDefault() n_out_channel = pa_get_output_max_channels(self.output_device_index+1) self.devicelist = pa_get_output_devices() self.updateDeviceList() self.sched_device = Scheduler() self.sched_device.start() self.sched_device.add_interval_job(self.updateDeviceList, seconds=20) self.theme = audio_theme.AudioTheme('water') self.view.register_buttons() self.view.show()