0

我正在尝试实现 PyAudio 库的方法,我想更改默认输入设备,因为我已经将基于 USB 的麦克风连接到我的笔记本电脑并且没有使用内置 MIC,但是这样做我遇到了问题,

这是该方法的完整详细信息,

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. 

用于PyAudio.open()制作新的 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)

初始化一个流;这应该由 PyAudio.open(). 流可以是输入、输出或两者兼而有之。

我想做的是使用

PyAudio.open() 

方法并将值设置input_device_index=1

但我不明白如何在这个函数中传递参数以及如何使用这个init

我已经尝试过的是,

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

但它给出了错误。

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

4

2 回答 2

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}
于 2013-09-29T14:57:49.113 回答
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.

于 2013-09-29T15:17:33.507 回答