diff options
author | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
---|---|---|
committer | AL-LCL <alvin@alvinhavel.com> | 2023-05-19 11:01:49 +0200 |
commit | 20dbeb2f38684c65ff0a4b99012c161295708e88 (patch) | |
tree | a5b8445f55da2fbbb92443b68e9d7354a290c598 /domestic/utility/get_io_channels.py |
Diffstat (limited to 'domestic/utility/get_io_channels.py')
-rw-r--r-- | domestic/utility/get_io_channels.py | 43 |
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 |