当前位置: 首页>>代码示例>>Python>>正文


Python PyAudio.is_format_supported方法代码示例

本文整理汇总了Python中pyaudio.PyAudio.is_format_supported方法的典型用法代码示例。如果您正苦于以下问题:Python PyAudio.is_format_supported方法的具体用法?Python PyAudio.is_format_supported怎么用?Python PyAudio.is_format_supported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyaudio.PyAudio的用法示例。


在下文中一共展示了PyAudio.is_format_supported方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AudioBackend

# 需要导入模块: from pyaudio import PyAudio [as 别名]
# 或者: from pyaudio.PyAudio import is_format_supported [as 别名]

#.........这里部分代码省略.........

    # method
    def select_second_channel(self, index):
        self.second_channel = index
        success = True
        return success, self.second_channel

    # method
    def open_stream(self, device):
        # by default we open the device stream with all the channels
        # (interleaved in the data buffer)
        max_input_channels = self.pa.get_device_info_by_index(device)['maxInputChannels']
        stream = self.pa.open(format=paInt16, channels=max_input_channels, rate=SAMPLING_RATE, input=True,
                              input_device_index=device, stream_callback=self.callback,
                              frames_per_buffer=FRAMES_PER_BUFFER)

        lat_ms = 1000 * stream.get_input_latency()
        self.logger.push("Device claims %d ms latency" % (lat_ms))

        return stream

    # method
    def open_output_stream(self, device, callback):
        # by default we open the device stream with all the channels
        # (interleaved in the data buffer)
        max_output_channels = self.pa.get_device_info_by_index(device)['maxOutputChannels']
        stream = self.pa.open(format=paInt16, channels=max_output_channels, rate=SAMPLING_RATE, output=True,
                              frames_per_buffer=FRAMES_PER_BUFFER, output_device_index=device,
                              stream_callback=callback)
        return stream

    def is_output_format_supported(self, device, output_format):
        max_output_channels = self.pa.get_device_info_by_index(device)['maxOutputChannels']
        success = self.pa.is_format_supported(SAMPLING_RATE, output_device=device, output_channels=max_output_channels, output_format=output_format)
        return success

    # method
    # return the index of the current input device in the input devices list
    # (not the same as the PortAudio index, since the latter is the index
    # in the list of *all* devices, not only input ones)
    def get_readable_current_device(self):
        return self.input_devices.index(self.device)

    # method
    def get_readable_current_channels(self):
        dev_info = self.pa.get_device_info_by_index(self.device)
        nchannels = dev_info['maxInputChannels']

        if nchannels == 2:
            channels = ['L', 'R']
        else:
            channels = []
            for channel in range(0, dev_info['maxInputChannels']):
                channels += ["%d" % channel]

        return channels

    # method
    def get_current_first_channel(self):
        return self.first_channel

    # method
    def get_current_second_channel(self):
        return self.second_channel

    # method
开发者ID:UIKit0,项目名称:friture,代码行数:70,代码来源:audiobackend.py


注:本文中的pyaudio.PyAudio.is_format_supported方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。