Fixed cutting end of sound, developing micro restreaming
This commit is contained in:
1
modules/restream/__init__.py
Normal file
1
modules/restream/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .devices import get_streaming_devices
|
||||
24
modules/restream/devices.py
Normal file
24
modules/restream/devices.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from dataclasses import dataclass
|
||||
import sounddevice as sd
|
||||
|
||||
|
||||
@dataclass
|
||||
class StreamingDevices:
|
||||
output: dict
|
||||
out_l: list
|
||||
input: dict
|
||||
in_l: list
|
||||
|
||||
|
||||
def get_streaming_devices() -> StreamingDevices:
|
||||
devices = StreamingDevices(dict(), list(), dict(), list())
|
||||
|
||||
for device in sd.query_hostapis()[0]['devices']:
|
||||
if sd.query_devices(device)['max_output_channels'] == 0:
|
||||
devices.input[sd.query_devices(device)['name']] = sd.query_devices(device)['index']
|
||||
devices.in_l.append(sd.query_devices(device)['name'])
|
||||
else:
|
||||
devices.output[sd.query_devices(device)['name']] = sd.query_devices(device)['index']
|
||||
devices.out_l.append(sd.query_devices(device)['name'])
|
||||
|
||||
return devices
|
||||
21
modules/restream/restream.py
Normal file
21
modules/restream/restream.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from gui.gui import Ui_MainWindow
|
||||
import sounddevice as sd
|
||||
from . import get_streaming_devices
|
||||
|
||||
|
||||
class Restreamer(object):
|
||||
def __init__(self):
|
||||
self.stream = sd.Stream()
|
||||
|
||||
@staticmethod
|
||||
def callback(indata, outdata, frames, time, status):
|
||||
if status:
|
||||
print(status)
|
||||
outdata[:] = indata
|
||||
|
||||
def restart(self, ui: Ui_MainWindow):
|
||||
self.stream.stop()
|
||||
self.stream = sd.Stream(device=(get_streaming_devices().input[ui.input_device_restream_box.currentText()],
|
||||
get_streaming_devices().output[ui.output_device_restream_box.currentText()]),
|
||||
callback=Restreamer.callback)
|
||||
self.stream.start()
|
||||
Reference in New Issue
Block a user