Improvements to Dectalk driver.

This commit is contained in:
Storm Dragon
2026-07-26 19:44:10 -04:00
parent 6d9260e79b
commit 45bd33f756
4 changed files with 27 additions and 10 deletions
+1 -1
View File
@@ -4,5 +4,5 @@
# Fenrir TTY screen reader # Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributors. # By Chrys, Storm Dragon, and contributors.
version = "2026.07.25" version = "2026.07.26"
code_name = "testing" code_name = "testing"
@@ -10,16 +10,17 @@ from fenrirscreenreader.speechDriver.hardwareSerialDriver import (
class driver(hardware_serial_driver): class driver(hardware_serial_driver):
cancel_command = b"\x18" cancel_command = b"\x03"
use_xon_xoff = True
def _speak_bytes(self, text): def _speak_bytes(self, text):
return self._clean_text(text).encode("ascii", errors="replace") + b"\x01" return self._clean_text(text).encode("ascii", errors="replace") + b"\x0b"
def _rate_command(self, rate): def _rate_command(self, rate):
return self._setting_command("ra", self._scale(rate, 75, 650)) return self._setting_command("ra", self._scale(rate, 75, 650))
def _pitch_command(self, pitch): def _pitch_command(self, pitch):
return self._setting_command("dv ap", self._scale(pitch, 50, 180)) return self._setting_command("dv ap", self._scale(pitch, 50, 350))
def _volume_command(self, volume): def _volume_command(self, volume):
return self._setting_command("vo", self._scale(volume, 0, 100)) return self._setting_command("vo", self._scale(volume, 0, 100))
@@ -27,6 +27,7 @@ class SpeakQueue(Queue):
class hardware_serial_driver(speech_driver): class hardware_serial_driver(speech_driver):
cancel_command = b"" cancel_command = b""
default_baud_rate = 9600 default_baud_rate = 9600
use_xon_xoff = False
def __init__(self): def __init__(self):
speech_driver.__init__(self) speech_driver.__init__(self)
@@ -176,6 +177,10 @@ class hardware_serial_driver(speech_driver):
attrs[5] = baud_rate attrs[5] = baud_rate
attrs[6][termios.VMIN] = 0 attrs[6][termios.VMIN] = 0
attrs[6][termios.VTIME] = 0 attrs[6][termios.VTIME] = 0
if self.use_xon_xoff:
attrs[0] |= termios.IXON
attrs[0] &= ~(termios.IXOFF | termios.IXANY)
else:
attrs[0] &= ~(termios.IXON | termios.IXOFF | termios.IXANY) attrs[0] &= ~(termios.IXON | termios.IXOFF | termios.IXANY)
termios.tcsetattr(port, termios.TCSANOW, attrs) termios.tcsetattr(port, termios.TCSANOW, attrs)
return port return port
+16 -5
View File
@@ -1,5 +1,6 @@
import os import os
import select import select
import termios
import time import time
from unittest.mock import ANY from unittest.mock import ANY
from unittest.mock import Mock from unittest.mock import Mock
@@ -64,7 +65,7 @@ def test_dectalk_driver_speaks_printable_text(serial_pair):
speech_driver, master_fd = initialized_driver(dectalkDriver, serial_pair) speech_driver, master_fd = initialized_driver(dectalkDriver, serial_pair)
try: try:
speech_driver.speak("Hello\nworld ☃") speech_driver.speak("Hello\nworld ☃")
assert read_available(master_fd, 13) == b"Hello world \x01" assert read_available(master_fd, 13) == b"Hello world \x0b"
finally: finally:
speech_driver.shutdown() speech_driver.shutdown()
@@ -73,12 +74,22 @@ def test_dectalk_driver_writes_settings_and_cancel(serial_pair):
speech_driver, master_fd = initialized_driver(dectalkDriver, serial_pair) speech_driver, master_fd = initialized_driver(dectalkDriver, serial_pair)
try: try:
speech_driver.set_rate(1.0) speech_driver.set_rate(1.0)
speech_driver.set_pitch(0.0) speech_driver.set_pitch(1.0)
speech_driver.set_volume(0.5) speech_driver.set_volume(0.5)
speech_driver.cancel() speech_driver.cancel()
assert read_available(master_fd, 33) == ( expected = b"[:ra 650][:dv ap 350][:vo 50]\x03"
b"[:ra 650][:dv ap 50][:vo 50]\x18" assert read_available(master_fd, len(expected)) == expected
) finally:
speech_driver.shutdown()
def test_dectalk_driver_enables_xon_xoff_flow_control(serial_pair):
speech_driver, _ = initialized_driver(dectalkDriver, serial_pair)
try:
input_flags = termios.tcgetattr(speech_driver.serial_port)[0]
assert input_flags & termios.IXON
assert not input_flags & termios.IXOFF
assert not input_flags & termios.IXANY
finally: finally:
speech_driver.shutdown() speech_driver.shutdown()