0

I am trying to implement a method of PyAudio library, I am suppose to change the default input device since I have connected a USB based Mic to my Laptop and not using the builtin MIC, but I am facing issues doing so,

Here is the complete details of the method,

Help on method open in module pyaudio:

open(self, *args, **kwargs) method of pyaudio.PyAudio instance
    Open a new stream. See constructor for
    :py:func:`Stream.__init__` for parameter details.

    :returns: A new :py:class:`Stream`

.

class pyaudio.Stream(PA_manager, rate, channels, format, input=False, output=False, input_device_index=None, output_device_index=None, frames_per_buffer=1024, start=True, input_host_api_specific_stream_info=None, output_host_api_specific_stream_info=None, stream_callback=None)
PortAudio Stream Wrapper. 

Use PyAudio.open() to make a new Stream.

__init__(PA_manager, rate, channels, format, input=False, output=False, input_device_index=None, output_device_index=None, frames_per_buffer=1024, start=True, input_host_api_specific_stream_info=None, output_host_api_specific_stream_info=None, stream_callback=None)

Initialize a stream; this should be called by PyAudio.open(). A stream can either be input, output, or both.

What I want to do is to use

PyAudio.open() 

method and set the value of input_device_index= to 1

But I couldn't understand how to pass the arguments in this function and how to use this init ?

What I have already tried is,

p = pyaudio.PyAudio()
p.open(__init__(input_device_index=1))

But it gives the error.

Here is the complete documentation of the methods, init">http://people.csail.mit.edu/hubert/pyaudio/docs/#pyaudio.Stream.init

Sufiyan Ghori
  • 18,164
  • 14
  • 82
  • 110
  • Possible duplicated of http://stackoverflow.com/questions/287085/what-do-args-and-kwargs-mean – Nacib Neme Sep 29 '13 at 15:01
  • my question is much more specific than simply asking about args and kwargs – Sufiyan Ghori Sep 29 '13 at 15:02
  • 1
    Xufyan, you could be more specific in question because now it's a little misleading. If I understand it correctly you are asking how to use PyAudio.open method (how to use library) rather then how to implement a function. – spinus Sep 29 '13 at 15:32
  • I am desperately sorry for any inconvenience caused, I have fixed the question , hopefully it is not irritating now. – Sufiyan Ghori Sep 29 '13 at 15:38

2 Answers2

2

*args will let any positional arguments be passed to the function as list.

**kwargs will let any associative arguments be passed to the function as dict.

Example:

def a(*args,**kwargs):
     print args
     print kwargs

a('abc','75449',test=None,abc=-1)

Prints:

['abc','75449']
{'test':None,'abc':-1}
Nacib Neme
  • 859
  • 1
  • 17
  • 28
2
p = pyaudio.PyAudio()
p.open(__init__(input_device_index=1))

Makes no sense because __init__ is not defined. PyAudio.__init__ is called by initialising PyAudio, so that would be

p = pyaudio.PyAudio(input_device_index=1)
p.open()

although it seems that open passes all its attributes through, using *args and **kwargs, so it might be

p = pyaudio.PyAudio()
p.open(input_device_index=1)

Anything more precise than that will require a better question or experience with PyAudio, neither of which I have.

Veedrac
  • 58,273
  • 15
  • 112
  • 169