Attempt to make auto at least somewhat more reliable. Recommend that device be explicitly set if possible.

This commit is contained in:
Storm Dragon
2026-05-23 18:23:58 -04:00
parent 6e3d7fee94
commit 604221a29d
7 changed files with 49 additions and 53 deletions
@@ -166,8 +166,6 @@ class hardware_serial_driver(speech_driver):
)
return
fallback_device = None
fallback_port = None
for device in devices:
port = self._open_configured_serial_port(device)
if port is None:
@@ -178,28 +176,20 @@ class hardware_serial_driver(speech_driver):
)
return
if self._probe_serial_port(port):
if fallback_port is not None:
self._close_port(fallback_port)
self._activate_serial_port(device, port, probe_matched=True)
return
if fallback_port is None:
fallback_device = device
fallback_port = port
else:
self._close_port(port)
self._close_port(port)
if fallback_port is not None:
if auto_detect and self.hardware_probe_command:
self._debug(
"Hardware speech probe did not identify a synth; "
f"falling back to {fallback_device}",
debug.DebugLevel.WARNING,
"Hardware speech auto did not identify a synth; set "
"speech#hardware_device to the known serial device",
debug.DebugLevel.ERROR,
on_any_level=True,
)
self._activate_serial_port(
fallback_device, fallback_port, probe_matched=False
)
def _open_configured_serial_port(self, device):
port = None
try:
port = os.open(device, os.O_RDWR | os.O_NOCTTY)
tty.setraw(port)
@@ -214,6 +204,7 @@ class hardware_serial_driver(speech_driver):
termios.tcsetattr(port, termios.TCSANOW, attrs)
return port
except (OSError, termios.error) as error:
self._close_port(port)
self._debug(
f"Hardware speech device open failed: {device}: {error}",
debug.DebugLevel.ERROR,
@@ -331,7 +322,11 @@ class hardware_serial_driver(speech_driver):
)
return [device]
devices = []
for pattern in ("/dev/ttyACM*", "/dev/ttyUSB*", "/dev/ttyS*"):
for pattern in (
"/dev/serial/by-id/*",
"/dev/ttyACM*",
"/dev/ttyUSB*",
):
matches = sorted(glob.glob(pattern))
self._debug(
f"Hardware speech auto scan {pattern}: {matches}",