Python 在类中使用进程池 通过sounddevice, 进行不同声卡驱动和通道的音频文件播放

看代码吧…
写代码写到半夜太累, 不想解说了, 直接上代码

# 获取与电脑连接的声卡设备详细信息

import sys
import sounddevice as sd
from python_audio_packages.sounddevice_example.my_exception_class import MyException


def get_pool_object():
    # po 的名字在main函数中定义
    #  __main__ 模块在sys.modules 的键是"__mp_main__"
    return sys.modules["__mp_main__"].po


def get_audio_devices_all_msg_dict():
	# 使用sounddevice 获取电脑连接的声卡以及系统自带的所有音频驱动信息(驱动, 声道名, id)
    audio_drivers_and_channels_msg_dict = {}
    audio_input_channels_msg_dict = {}
    audio_output_channels_msg_dict = {}
    this_tmp_dict = {}
    host_api_tuple = sd.query_hostapis()

    for temp_dict in host_api_tuple:
        this_tmp_dict[temp_dict["name"]] = temp_dict["devices"]

    channels_list = sd.query_devices()
    for driver_name in this_tmp_dict:
        audio_drivers_and_channels_msg_dict[driver_name] = []
        audio_input_channels_msg_dict[driver_name] = []
        audio_output_channels_msg_dict[driver_name] = []

        for id in this_tmp_dict[driver_name]:
            audio_drivers_and_channels_msg_dict[driver_name].append((id, channels_list[id]["name"]))

            if channels_list[id]["max_input_channels"] > 0:
                audio_input_channels_msg_dict[driver_name].append((id, channels_list[id]['name']))

            if channels_list[id]["max_output_channels"] > 0:
                audio_output_channels_msg_dict[driver_name].append((id, channels_list[id]['name']))

    return audio_drivers_and_channels_msg_dict, audio_input_channels_msg_dict, audio_output_channel
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值