python-sounddevice-音频设备

摘要:
//pypi.douban.com/simple importsounddeviceassddev=sd。query_ Devices()#返回系统的所有声音设备。下面是我电脑上的音响设备。如果需要录制系统声音,则需要将声音设备切换到立体声混音#Run sd。可以看到来自上述设备()的查询。

python-sounddevice-音频设备第1张

安装:pip install sounddevice -i https://pypi.douban.com/simple      

import sounddevice as sd
dev=sd.query_devices()  #返回系统所有的声音设备

下面是我计算机上的声音设备,>标示为默认输入设备,<表示默认的输出设备,声音设备名称之前是序号

0 Microsoft 声音映射器 - Input, MME (2 in, 0 out)
> 1 Microphone (Realtek High Defini, MME (2 in, 0 out)
2 立体声混音 (Realtek High Defini, MME (2 in, 0 out)
3 Microsoft 声音映射器 - Output, MME (0 in, 2 out)
< 4 喇叭/耳机 (Realtek High Definit, MME (0 in, 2 out)
5 主声音捕获驱动程序, Windows DirectSound (2 in, 0 out)
6 Microphone (Realtek High Definition Audio), Windows DirectSound (2 in, 0 out)
7 立体声混音 (Realtek High Definition Audio), Windows DirectSound (2 in, 0 out)
8 主声音驱动程序, Windows DirectSound (0 in, 2 out)
9 喇叭/耳机 (Realtek High Definition Audio), Windows DirectSound (0 in, 2 out)
10 喇叭/耳机 (Realtek High Definition Audio), Windows WASAPI (0 in, 2 out)
11 立体声混音 (Realtek High Definition Audio), Windows WASAPI (2 in, 0 out)
12 Microphone (Realtek High Definition Audio), Windows WASAPI (2 in, 0 out)
13 Speakers (Realtek HD Audio output), Windows WDM-KS (0 in, 2 out)
14 麦克风 (Realtek HD Audio Mic input), Windows WDM-KS (2 in, 0 out)
15 立体声混音 (Realtek HD Audio Stereo input), Windows WDM-KS (2 in, 0 out)

dev1=sd.default.device  #返回默认声音设备
#[1, 4]
#返回的是一个列表,有两个元素。第一个元素为默认的输入设备,第二个元素为默认的输出设备,设备是用序号来表示的
sd.default.device[0] = 2  #修改默认的输入设备为系统输出声音(捕获系统声音)
#系统默认的声音输入设备是麦克风,如果需要录制系统声音则需要将声音设备切换成立体声混音
#通过上面运行sd.query_devices()可以看到,我的计算机立体声混音设备序号为2

 注意:有的电脑还需要修改

python-sounddevice-音频设备第2张

 把相应的设备设为默认值

遍历:

import sounddevice as sd
devs=sd.query_devices()  #返回系统所有的声音设备
i=0
for dev in devs:
    print('第{0}个'.format(i),dev)
    i+=1

说明:dev是个字典(每个设备的信息),如下:

第0个 {'name': 'Microsoft 声音映射器 - Input', 'hostapi': 0, 'max_input_channels': 2, 'max_output_channels': 0, 'default_low_input_latency':
0.09, 'default_low_output_latency': 0.09, 'default_high_input_latency': 0.18, 'default_high_output_latency': 0.18, 'default_samplerate': 4410
0.0}
第1个 {'name': '麦克风 (Realtek High Definition', 'hostapi': 0, 'max_input_channels': 2, 'max_output_channels': 0, 'default_low_input_latency
': 0.09, 'default_low_output_latency': 0.09, 'default_high_input_latency': 0.18, 'default_high_output_latency': 0.18, 'default_samplerate': 4
4100.0}
第2个 {'name': 'Microsoft 声音映射器 - Output', 'hostapi': 0, 'max_input_channels': 0, 'max_output_channels': 2, 'default_low_input_latency':
0.09, 'default_low_output_latency': 0.09, 'default_high_input_latency': 0.18, 'default_high_output_latency': 0.18, 'default_samplerate': 441
00.0}
第3个 {'name': '扬声器 (Realtek High Definition', 'hostapi': 0, 'max_input_channels': 0, 'max_output_channels': 2, 'default_low_input_latency
': 0.09, 'default_low_output_latency': 0.09, 'default_high_input_latency': 0.18, 'default_high_output_latency': 0.18, 'default_samplerate': 4
4100.0}
第4个 {'name': '主声音捕获驱动程序', 'hostapi': 1, 'max_input_channels': 2, 'max_output_channels': 0, 'default_low_input_latency': 0.12, 'def
ault_low_output_latency': 0.0, 'default_high_input_latency': 0.24, 'default_high_output_latency': 0.0, 'default_samplerate': 44100.0}
第5个 {'name': '麦克风 (Realtek High Definition Audio)', 'hostapi': 1, 'max_input_channels': 2, 'max_output_channels': 0, 'default_low_input_
latency': 0.12, 'default_low_output_latency': 0.0, 'default_high_input_latency': 0.24, 'default_high_output_latency': 0.0, 'default_samplerat
e': 44100.0}
第6个 {'name': '主声音驱动程序', 'hostapi': 1, 'max_input_channels': 0, 'max_output_channels': 2, 'default_low_input_latency': 0.0, 'default_
low_output_latency': 0.12, 'default_high_input_latency': 0.0, 'default_high_output_latency': 0.24, 'default_samplerate': 44100.0}
第7个 {'name': '扬声器 (Realtek High Definition Audio)', 'hostapi': 1, 'max_input_channels': 0, 'max_output_channels': 2, 'default_low_input_
latency': 0.0, 'default_low_output_latency': 0.12, 'default_high_input_latency': 0.0, 'default_high_output_latency': 0.24, 'default_samplerat
e': 44100.0}
第8个 {'name': '扬声器 (Realtek High Definition Audio)', 'hostapi': 3, 'max_input_channels': 0, 'max_output_channels': 2, 'default_low_input_
latency': 0.0, 'default_low_output_latency': 0.003, 'default_high_input_latency': 0.0, 'default_high_output_latency': 0.01, 'default_samplera
te': 48000.0}
第9个 {'name': '麦克风 (Realtek High Definition Audio)', 'hostapi': 3, 'max_input_channels': 2, 'max_output_channels': 0, 'default_low_input_
latency': 0.0013333, 'default_low_output_latency': 0.0, 'default_high_input_latency': 0.01, 'default_high_output_latency': 0.0, 'default_samp
lerate': 48000.0}
第10个 {'name': '麦克风 (Realtek HD Audio Mic input)', 'hostapi': 4, 'max_input_channels': 2, 'max_output_channels': 0, 'default_low_input_la
tency': 0.01, 'default_low_output_latency': 0.01, 'default_high_input_latency': 0.04, 'default_high_output_latency': 0.04, 'default_samplerat
e': 44100.0}
第11个 {'name': 'Speakers (Realtek HD Audio output)', 'hostapi': 4, 'max_input_channels': 0, 'max_output_channels': 2, 'default_low_input_lat
ency': 0.01, 'default_low_output_latency': 0.01, 'default_high_input_latency': 0.04, 'default_high_output_latency': 0.04, 'default_samplerate
': 44100.0}
第12个 {'name': '立体声混音 (Realtek HD Audio Stereo input)', 'hostapi': 4, 'max_input_channels': 2, 'max_output_channels': 0, 'default_low_i
nput_latency': 0.01, 'default_low_output_latency': 0.01, 'default_high_input_latency': 0.04, 'default_high_output_latency': 0.04, 'default_sa
mplerate': 48000.0}

default_samplerate  默认采样率

max_input_channels  最多输入通道

 

 

python-sounddevice-音频设备第3张

免责声明:文章转载自《python-sounddevice-音频设备》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇转载 ldd3环境配置Maven Eclipse (m2e) SCM connector for subclipse 1.10 (svn 1.8) 无法检测下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

ADB调试技巧记录

一.多个在线设备adb 1. 通过adb devices命令获取所有online设备的serial number。 C:UsersAdministrator>adb devices List of devices attachedemulator-5554   deviceSH0A6PL00243    device 上面表示,当前有两个设备onli...

侦测卡 变色龙侦测卡 chameleon-Mini(迷你变色龙) (一)

参考:http://www.proxmark.orghttps://github.com/emsec/ChameleonMini/wiki https://github.com/nfc-tools/libnfc https://github.com/nfc-tools/mfoc https://github.com/nfc-tools/mfcuk http...

Django之缓存、信号和图片验证码、ORM性能

一、 缓存 1、 介绍 缓存通俗来说:就是把数据先保存在某个地方,下次再读取的时候不用再去原位置读取,让访问速度更快。 缓存机制图解 2、Django中提供了6种缓存方式   1. 开发调试   2. 内存   3. 文件   4. 数据库   5. Memcache缓存(python-memcached模块)   6. Memcache缓存(pyl...

蓝牙协议栈详解

1.概述: 蓝牙协议规范遵循开放系统互连参考模型(OSI/RM),从低到高地定义了蓝牙协议堆栈的各个层次。 SIG所定义的蓝牙技术规范的目的是使符合该规范的各种应用之间能够实现互操作。互操作的远端设备需要使用相同的协议栈,不同的应用需要不同的协议栈。但是,所有的应用都要使用蓝牙技术规范中的数据链路层和物理层。 2.完整的蓝牙协议栈 完整的蓝牙协议栈如图1所...

人工智能与智能家居

1.家庭AI系统的任务 在智能家居中应用人工智能技术,需要构建承载人工智能算法的家庭AI系统。家庭AI系统用以实现两类家庭任务: (1)家庭设备的控制任务。 这类任务需要系统通过分析用户使用数据,按照用户习惯自动控制家庭内部设备、或调整家庭内环境状态。例如Nest温控器,按照用户习惯控制房间温度,并且兼顾节能。 (2)家庭状态的监测任务。 这类任务需要系统...

如何在vm虚拟机中安装linux

1、首先在vm中新建一个虚拟机  2、选择典型 3、点击稍后安装操作系统  4、选择安装linux,版本可以选择centOS64位的,根据自己系统的位数选择即可 5、选择安装路径,建议装在其他盘,..反正最好别装在c盘就行了  6、磁盘大小可以根据自身需求设置,选择多个磁盘  7、最后点击完成就over了 8、安装操作系统,首先现点击编辑虚拟机...