Better errors for mic autodetect
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ LOCAL_DIR = PROGRAM_DIR / "local"
|
|||||||
SETTINGS_PATH = LOCAL_DIR / "settings.json"
|
SETTINGS_PATH = LOCAL_DIR / "settings.json"
|
||||||
SERVICES_DIR = LOCAL_DIR / "services"
|
SERVICES_DIR = LOCAL_DIR / "services"
|
||||||
|
|
||||||
RECORD_SECONDS = 8
|
RECORD_SECONDS = 5
|
||||||
RECORD_RMS_MIN = 30
|
RECORD_RMS_MIN = 30
|
||||||
|
|
||||||
TITLE = "Wyoming Satellite"
|
TITLE = "Wyoming Satellite"
|
||||||
|
|||||||
+16
-4
@@ -31,6 +31,11 @@ def configure_microphone(settings: Settings) -> None:
|
|||||||
gauge("Speak loudly into the microphone.", RECORD_SECONDS)
|
gauge("Speak loudly into the microphone.", RECORD_SECONDS)
|
||||||
for device, future in futures.items():
|
for device, future in futures.items():
|
||||||
device_rms = future.result()
|
device_rms = future.result()
|
||||||
|
if device_rms is None:
|
||||||
|
_LOGGER.warning("Failed to record from microphone %s", device)
|
||||||
|
continue
|
||||||
|
|
||||||
|
_LOGGER.debug("Microphone %s got RMS %s (min: %s)", device, device_rms, RECORD_RMS_MIN)
|
||||||
if device_rms < RECORD_RMS_MIN:
|
if device_rms < RECORD_RMS_MIN:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -43,7 +48,8 @@ def configure_microphone(settings: Settings) -> None:
|
|||||||
settings.mic.device = best_device
|
settings.mic.device = best_device
|
||||||
settings.save()
|
settings.save()
|
||||||
else:
|
else:
|
||||||
msgbox("Audio was not detected from any microphone")
|
msgbox("Audio was not detected from any microphone.\n"
|
||||||
|
"If a satellite is currently running, you may need to stop it.")
|
||||||
elif choice == "list":
|
elif choice == "list":
|
||||||
# arecord -L
|
# arecord -L
|
||||||
microphone_device = radiolist(
|
microphone_device = radiolist(
|
||||||
@@ -90,9 +96,9 @@ def get_microphone_devices() -> List[str]:
|
|||||||
return devices
|
return devices
|
||||||
|
|
||||||
|
|
||||||
def _record_proc(device: str) -> float:
|
def _record_proc(device: str) -> Optional[float]:
|
||||||
try:
|
try:
|
||||||
audio = subprocess.check_output(
|
proc = subprocess.Popen(
|
||||||
[
|
[
|
||||||
"arecord",
|
"arecord",
|
||||||
"-q",
|
"-q",
|
||||||
@@ -109,8 +115,13 @@ def _record_proc(device: str) -> float:
|
|||||||
"-d",
|
"-d",
|
||||||
str(RECORD_SECONDS),
|
str(RECORD_SECONDS),
|
||||||
],
|
],
|
||||||
stderr=subprocess.DEVNULL,
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
|
audio, stderr = proc.communicate()
|
||||||
|
if proc.returncode != 0:
|
||||||
|
_LOGGER.error("Error recording from device %s: %s", device, stderr.decode("utf-8"))
|
||||||
|
return None
|
||||||
|
|
||||||
# 16-bit mono
|
# 16-bit mono
|
||||||
audio_array = array.array("h", audio)
|
audio_array = array.array("h", audio)
|
||||||
@@ -120,6 +131,7 @@ def _record_proc(device: str) -> float:
|
|||||||
return rms
|
return rms
|
||||||
except Exception:
|
except Exception:
|
||||||
_LOGGER.exception("Error recording from device: %s", device)
|
_LOGGER.exception("Error recording from device: %s", device)
|
||||||
|
return None
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user