-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathsystem_info.py
134 lines (110 loc) · 4.31 KB
/
system_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
PyAudio Example:
Query and print PortAudio HostAPIs, Devices, and their
support rates.
"""
import pyaudio
standard_sample_rates = [8000.0, 9600.0, 11025.0, 12000.0,
16000.0, 22050.0, 24000.0, 32000.0,
44100.0, 48000.0, 88200.0, 96000.0,
192000.0]
p = pyaudio.PyAudio()
max_apis = p.get_host_api_count()
max_devs = p.get_device_count()
print("\nPortAudio System Info:\n======================")
print("Version: %d" % pyaudio.get_portaudio_version())
print("Version Text: %s" % pyaudio.get_portaudio_version_text())
print("Number of Host APIs: %d" % max_apis)
print("Number of Devices : %d" % max_devs)
print("\nHost APIs:\n==========")
for i in range(max_apis):
apiinfo = p.get_host_api_info_by_index(i)
for k in list(apiinfo.items()):
print("%s: %s" % k)
print("--------------------------")
print("\nDevices:\n========")
for i in range(max_devs):
devinfo = p.get_device_info_by_index(i)
# print out device parameters
for k in list(devinfo.items()):
name, value = k
# if host API, then get friendly name
if name == 'hostApi':
value = str(value) + \
" (%s)" % p.get_host_api_info_by_index(k[1])['name']
# Crashing? See http://stackoverflow.com/a/5146914
print("\t%s: %s" % (name, value))
# print out supported format rates
input_supported_rates = []
output_supported_rates = []
full_duplex_rates = []
for f in standard_sample_rates:
if devinfo['maxInputChannels'] > 0:
try:
if p.is_format_supported(
f,
input_device = devinfo['index'],
input_channels = devinfo['maxInputChannels'],
input_format = pyaudio.paInt16):
input_supported_rates.append(f)
except ValueError:
pass
if devinfo['maxOutputChannels'] > 0:
try:
if p.is_format_supported(
f,
output_device = devinfo['index'],
output_channels = devinfo['maxOutputChannels'],
output_format = pyaudio.paInt16):
output_supported_rates.append(f)
except ValueError:
pass
if (devinfo['maxInputChannels'] > 0) and \
(devinfo['maxOutputChannels'] > 0):
try:
if p.is_format_supported(
f,
input_device = devinfo['index'],
input_channels = devinfo['maxInputChannels'],
input_format = pyaudio.paInt16,
output_device = devinfo['index'],
output_channels = devinfo['maxOutputChannels'],
output_format = pyaudio.paInt16):
full_duplex_rates.append(f)
except ValueError:
pass
if len(input_supported_rates):
print("\tInput rates: %s" % input_supported_rates)
if len(output_supported_rates):
print("\tOutput rates: %s" % output_supported_rates)
if len(full_duplex_rates):
print("\tFull duplex: %s" % full_duplex_rates)
print("\t--------------------------------")
print("\nDefault Devices:\n================")
try:
def_index = p.get_default_input_device_info()['index']
print("Default Input Device : %s" % def_index)
devinfo = p.get_device_info_by_index(def_index)
for k in list(devinfo.items()):
name, value = k
if name == 'hostApi':
value = str(value) + \
" (%s)" % p.get_host_api_info_by_index(k[1])['name']
print("\t%s: %s" % (name, value))
print("\t--------------------------------")
except IOError as e:
print("No Input devices: %s" % e[0])
try:
def_index = p.get_default_output_device_info()['index']
print("Default Output Device: %s" % def_index)
devinfo = p.get_device_info_by_index(def_index)
for k in list(devinfo.items()):
name, value = k
if name == 'hostApi':
value = str(value) + \
" (%s)" % p.get_host_api_info_by_index(k[1])['name']
print("\t%s: %s" % (name, value))
print("\t--------------------------------")
except IOError as e:
print("No Output devices: %s" % e[0])
p.terminate()