summaryrefslogtreecommitdiff
path: root/domestic/utility/get_io_channels.py
diff options
context:
space:
mode:
Diffstat (limited to 'domestic/utility/get_io_channels.py')
-rw-r--r--domestic/utility/get_io_channels.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/domestic/utility/get_io_channels.py b/domestic/utility/get_io_channels.py
new file mode 100644
index 0000000..c5fa5e2
--- /dev/null
+++ b/domestic/utility/get_io_channels.py
@@ -0,0 +1,43 @@
+import pyaudio
+
+from domestic.global_state import *
+
+
+def get_io_channels():
+ try:
+ p = pyaudio.PyAudio()
+ CHUNK = 81920
+ FORMAT = pyaudio.paInt16
+ RATE = 44100
+ except:
+ pass
+ else:
+ try:
+ stream = p.open(format=FORMAT, channels=2, rate=RATE, input=True, output=False, frames_per_buffer=CHUNK)
+ stream.stop_stream()
+ stream.close()
+ state['settings']['io-channels'][0] = '2'
+ except:
+ try:
+ stream = p.open(format=FORMAT, channels=1, rate=RATE, input=True, output=False, frames_per_buffer=CHUNK)
+ stream.stop_stream()
+ stream.close()
+ state['settings']['io-channels'][0] = '1'
+ except:
+ pass
+
+ try:
+ stream = p.open(format=FORMAT, channels=2, rate=RATE, input=False, output=True, frames_per_buffer=CHUNK)
+ stream.stop_stream()
+ stream.close()
+ state['settings']['io-channels'][1] = '2'
+ except:
+ try:
+ stream = p.open(format=FORMAT, channels=1, rate=RATE, input=False, output=True, frames_per_buffer=CHUNK)
+ stream.stop_stream()
+ stream.close()
+ state['settings']['io-channels'][1] = '1'
+ except:
+ pass
+
+ p.terminate() \ No newline at end of file