improve changing streaming modes
This commit is contained in:
@@ -51,14 +51,11 @@ if audio_mode in ["Webapp", "USB"]:
|
||||
# Input device selection for USB mode
|
||||
if audio_mode == "USB":
|
||||
try:
|
||||
import sounddevice as sd # type: ignore
|
||||
devs = sd.query_devices()
|
||||
log.info('Found audio devices: %s', devs)
|
||||
input_options = [
|
||||
f"{idx}:{d['name']}"
|
||||
for idx, d in enumerate(devs)
|
||||
if d.get('max_input_channels', 0) > 0 and ("(hw:" in d['name'].lower() or "usb" in d['name'].lower())
|
||||
]
|
||||
resp = requests.get(f"{BACKEND_URL}/audio_inputs", timeout=1)
|
||||
if resp.status_code == 200:
|
||||
input_options = [f"{d['id']}:{d['name']}" for d in resp.json().get('inputs', [])]
|
||||
else:
|
||||
input_options = []
|
||||
except Exception:
|
||||
input_options = []
|
||||
|
||||
@@ -75,8 +72,27 @@ if audio_mode in ["Webapp", "USB"]:
|
||||
else:
|
||||
input_device = None
|
||||
start_stream = st.button("Start Auracast")
|
||||
stop_stream = st.button("Stop Auracast")
|
||||
|
||||
if stop_stream:
|
||||
try:
|
||||
r = requests.post(f"{BACKEND_URL}/stop_audio")
|
||||
if r.status_code == 200:
|
||||
st.success("Stream Stopped!")
|
||||
else:
|
||||
st.error(f"Failed to stop: {r.text}")
|
||||
except Exception as e:
|
||||
st.error(f"Error: {e}")
|
||||
|
||||
if start_stream:
|
||||
# Always send stop to ensure backend is in a clean state, regardless of current status
|
||||
try:
|
||||
requests.post(f"{BACKEND_URL}/stop_audio", timeout=5)
|
||||
except Exception:
|
||||
# Ignore connection or 500 errors – backend may not be running yet
|
||||
pass
|
||||
# Small pause lets backend fully release audio devices before re-init
|
||||
import time; time.sleep(0.7)
|
||||
# Prepare config using the model (do NOT send qos_config, only relevant fields)
|
||||
q = quality_map[quality]
|
||||
config = auracast_config.AuracastConfigGroup(
|
||||
|
||||
Reference in New Issue
Block a user