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
|
import pyaudio
import cv2
from desktopmagic.screengrab_win32 import getDisplayRects
def device_support(silent, io_channels):
device_obj = {}
try:
device_obj['monitors'] = len(getDisplayRects())
except:
device_obj['monitors'] = '???'
if silent:
device_obj['cams'] = '???'
else:
cams = [0, []]
while True:
cam = cv2.VideoCapture(cams[0])
check, frame = cam.read()
if not check:
break
cams[0] += 1
cams[1].append(f'[{int(cam.get(3))},{int(cam.get(4))}]')
cam.release()
device_obj['cams'] = '{} {}'.format(cams[0], ', '.join(cams[1]))
try:
p = pyaudio.PyAudio()
CHUNK = 81920
FORMAT = pyaudio.paInt16
RATE = 44100
except:
device_obj['io-channels'] = '???'
else:
try:
try:
stream = p.open(format=FORMAT, channels=2, rate=RATE, input=True, output=False, frames_per_buffer=CHUNK)
stream.stop_stream()
stream.close()
input_channels = '2'
except:
stream = p.open(format=FORMAT, channels=1, rate=RATE, input=True, output=False, frames_per_buffer=CHUNK)
stream.stop_stream()
stream.close()
input_channels = '1'
if io_channels[0] in ('1', '2'):
device_obj['io-channels'] = '{}(+), '.format(input_channels)
else:
device_obj['io-channels'] = '{}(-), '.format(input_channels)
except:
device_obj['io-channels'] = 'None, '
try:
try:
stream = p.open(format=FORMAT, channels=2, rate=RATE, input=False, output=True, frames_per_buffer=CHUNK)
stream.stop_stream()
stream.close()
output_channels = '2'
except:
stream = p.open(format=FORMAT, channels=1, rate=RATE, input=False, output=True, frames_per_buffer=CHUNK)
stream.stop_stream()
stream.close()
output_channels = '1'
if io_channels[1] in ('1', '2'):
device_obj['io-channels'] += '{}(+)'.format(output_channels)
else:
device_obj['io-channels'] += '{}(-)'.format(output_channels)
except:
device_obj['io-channels'] += 'None'
p.terminate()
return device_obj
|