check_audio_device_id.py
· 454 B · Python
Raw
import pyaudio
def list_audio_devices():
p = pyaudio.PyAudio()
print("Available audio devices:")
for i in range(p.get_device_count()):
device_info = p.get_device_info_by_index(i)
# 只打印输出设备
if device_info['maxOutputChannels'] > 0:
print(f"Device ID: {i}, Name: {device_info['name']}, Max Output Channels: {device_info['maxOutputChannels']}")
p.terminate()
list_audio_devices()
1 | import pyaudio |
2 | |
3 | def list_audio_devices(): |
4 | p = pyaudio.PyAudio() |
5 | |
6 | print("Available audio devices:") |
7 | for i in range(p.get_device_count()): |
8 | device_info = p.get_device_info_by_index(i) |
9 | # 只打印输出设备 |
10 | if device_info['maxOutputChannels'] > 0: |
11 | print(f"Device ID: {i}, Name: {device_info['name']}, Max Output Channels: {device_info['maxOutputChannels']}") |
12 | |
13 | p.terminate() |
14 | |
15 | list_audio_devices() |
16 |