Preview voice profile edits and restore parent speech
This commit is contained in:
1 parent
1b42dde756
commit
b21fceb311
7 files changed
+174
-10
No files matched your search
@@ -663,8 +663,14 @@ changes since the last Apply. Voice Profiles is global and is absent from
|
||||
application preferences. Explicit key echo and system-message voice settings
|
||||
retain their existing behavior, including inheritance from the primary voice.
|
||||
|
||||
The Speech quick-settings category also offers **Voice profile** when profiles
|
||||
exist. Cycling switches immediately for the session; the ordinary quick-settings
|
||||
Software voice and numeric changes in the profile editor are previewed through
|
||||
the ordinary speech-settings path. Saving or cancelling the child restores the
|
||||
parent preferences voice; **Use Voice Profile** previews the selected profile.
|
||||
Apply/OK makes added or edited profiles available immediately in quick settings.
|
||||
|
||||
The Speech quick-settings category offers **Voice profile**, with Default
|
||||
available even when no named profiles are saved. Cycling switches immediately
|
||||
for the session; the ordinary quick-settings
|
||||
save command persists it. Adjusting individual speech settings does not rewrite
|
||||
the preset. Failed speech changes retain the previous configuration. Cthulhu's
|
||||
existing restriction on combining hardware primary speech with a separate echo
|
||||
|
||||
@@ -14,18 +14,24 @@ CTHULHU_BINARY=/tmp/cthulhu-voice-profiles CTHULHU_PREFS_VOICE_PROFILES_ONLY=1 p
|
||||
|
||||
This exercises actual GTK widgets on a private X display/accessibility bus. It
|
||||
checks name focus, Tab/Shift+Tab, backend-specific fields, automatic names,
|
||||
duplicate rejection, editing, cancellation, selection and removal. Go regressions
|
||||
cover atomic storage, global/application boundaries, auxiliary voices and failed
|
||||
runtime selection. These checks do not prove audible output or physical hardware.
|
||||
duplicate rejection, editing, cancellation, selection and removal. It also checks
|
||||
preview requests for edited voices and numeric values, restoration of the parent
|
||||
voice when a preview is still pending, and Use Voice Profile previews. Go
|
||||
regressions cover backend preview delivery, atomic storage, immediate quick-menu
|
||||
availability after Apply, global/application boundaries, auxiliary voices and
|
||||
failed runtime selection. These checks do not prove audible output or physical
|
||||
hardware.
|
||||
|
||||
Before submitting, review all three diffs and test with the intended reader:
|
||||
|
||||
1. Add two installed software voices, leaving one name blank. Save preferences,
|
||||
reopen them and verify both complete profiles.
|
||||
2. Change rate/pitch/volume in a preset. Cancel once, then save and Apply; verify
|
||||
only the saved edit survives reopening and restarting.
|
||||
2. Change voice/rate/pitch/volume in a preset and listen to the editor's feedback
|
||||
before saving. Cancel once and verify the parent voice returns, then save and
|
||||
Apply; verify only the saved edit survives reopening and restarting.
|
||||
3. Use the profile selector in quick settings to cycle both directions. Listen
|
||||
to an article in each voice. Save the selection and verify it after restart.
|
||||
to an article in each voice. Confirm a newly applied profile appears without
|
||||
restarting. Save the selection and verify it after restart.
|
||||
4. Check typing echo and system messages with explicit custom settings and with
|
||||
inheritance. Check uppercase/hyperlink speech and application window changes.
|
||||
5. Select an unavailable module/device. Confirm an error and continued speech
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"git.stormux.org/storm/cthulhu/internal/config"
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
"git.stormux.org/storm/cthulhu/internal/preferences"
|
||||
"git.stormux.org/storm/cthulhu/internal/speech"
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
"log/slog"
|
||||
@@ -115,3 +116,64 @@ func TestQuickVoiceProfileDefaultIsFocusedApplicationVoice(t *testing.T) {
|
||||
t.Fatal("inherited application voice was not the global voice", saved)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppliedNewVoiceProfileIsImmediatelyAvailableAcrossApplications(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
settings.Path = filepath.Join(t.TempDir(), "settings.toml")
|
||||
store, err := config.NewStore(settings.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.Save(settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.SaveForApplication("Mapped Application", settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), settings, settingsUpdateFunc(func(context.Context, speech.Settings) error { return nil }))
|
||||
worker.switchApplication(t.Context(), "Mapped Application")
|
||||
if !worker.beginEdit(t.Context(), "") {
|
||||
t.Fatal("global preferences did not open")
|
||||
}
|
||||
values := preferences.FromSettings(worker.editing)
|
||||
values.VoiceProfiles.Profiles = []voiceprofiles.Profile{{Name: "Reading", Driver: "speech-dispatcher", Rate: 30, Volume: 80}}
|
||||
if result := worker.apply(t.Context(), preferences.Request{Values: values, Save: true}); !result.Accepted {
|
||||
t.Fatal(result.Message)
|
||||
}
|
||||
loaded, err := store.Load()
|
||||
if err != nil || len(loaded.VoiceProfiles.Profiles) != 1 {
|
||||
t.Fatal("new profile was not saved", loaded.VoiceProfiles, err)
|
||||
}
|
||||
for _, application := range []string{"Mapped Application", "Other Application"} {
|
||||
worker.switchApplication(t.Context(), application)
|
||||
selectQuickSetting(t, worker, "speech.profile")
|
||||
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
|
||||
if got := config.Primary_voice(worker.settings); got.Rate != 30 || got.Volume != 80 {
|
||||
t.Fatal("new profile unavailable without restart", application, got)
|
||||
}
|
||||
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting) // Return to Default.
|
||||
}
|
||||
}
|
||||
|
||||
func TestProfileVoicePreviewReachesBackendWithoutCommitting(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
updater := &voiceConfigurationRecorder{}
|
||||
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), settings, updater)
|
||||
profile := voiceprofiles.Profile{Name: "Reading", Driver: "speech-dispatcher", Module: "fixture", Language: "es", Voice: "Reading voice", Rate: 30, Pitch: -10, Volume: 80}
|
||||
draft, err := config.Apply_primary_voice(settings, profile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if response := worker.preview(t.Context(), preferences.Request{Values: preferences.FromSettings(draft), Preview: true}); !response.Accepted {
|
||||
t.Fatal(response.Message)
|
||||
}
|
||||
if got := config.Primary_voice(updater.settings); !voiceprofiles.Same_voice(got, profile) {
|
||||
t.Fatal("profile preview did not reach the speech backend", got)
|
||||
}
|
||||
if !reflect.DeepEqual(worker.settings, settings) || len(worker.settings.VoiceProfiles.Profiles) != 0 {
|
||||
t.Fatal("profile preview committed reader settings")
|
||||
}
|
||||
if response := worker.restorePreview(t.Context()); !response.Accepted || !reflect.DeepEqual(updater.settings, settings) {
|
||||
t.Fatal("profile preview did not restore the working voice", response)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,9 @@ type uiSession struct {
|
||||
profileEditor *voiceprofiles.Editor
|
||||
profileIndex int
|
||||
profileControls []ui.Control
|
||||
profileBase Values
|
||||
profileVoice *voiceprofiles.Profile
|
||||
profilePreview *Values
|
||||
extensionPages []ExtensionPage
|
||||
progressBar config.ProgressBarSettings
|
||||
wine config.WineSettings
|
||||
|
||||
@@ -108,8 +108,14 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
|
||||
if response.Preview {
|
||||
previewPending = false
|
||||
if !response.Accepted {
|
||||
if session.profileEditor != nil {
|
||||
message := C.CString(response.Message)
|
||||
C.prefs_profile_status(message)
|
||||
C.free(unsafe.Pointer(message))
|
||||
} else {
|
||||
status(response.Message, true)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
if response.Close {
|
||||
@@ -145,7 +151,15 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
|
||||
status(response.Message, !response.Accepted)
|
||||
case <-ticker.C:
|
||||
C.prefs_iterate()
|
||||
if session.profile_tick() {
|
||||
profileActive := session.profile_tick()
|
||||
if session.profilePreview != nil && !previewPending && !busy {
|
||||
if err := encoder.Encode(Request{Values: *session.profilePreview, Preview: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
session.profilePreview = nil
|
||||
previewPending = true
|
||||
}
|
||||
if profileActive {
|
||||
continue
|
||||
}
|
||||
session.refreshEchoVoices()
|
||||
@@ -224,6 +238,7 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
|
||||
}
|
||||
busy = true
|
||||
previewDirty = false
|
||||
session.profilePreview = nil
|
||||
C.prefs_busy(1, boolean(canSave))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ func (session *uiSession) profile_action(action int) {
|
||||
}
|
||||
session.activeVoiceType = 0
|
||||
session.setSpeechVoice(FromSettings(next))
|
||||
preview := profile_preview_values(values, next)
|
||||
session.profilePreview = &preview
|
||||
return
|
||||
}
|
||||
values, err := session.getValues()
|
||||
@@ -84,6 +86,8 @@ func (session *uiSession) profile_action(action int) {
|
||||
}
|
||||
}
|
||||
session.profileEditor = voiceprofiles.New_editor(p, drivers, session.catalog)
|
||||
session.profileBase = values
|
||||
session.profileVoice = nil
|
||||
session.profileIndex = index
|
||||
session.profileControls = session.profileEditor.Form().Tabs[0].Controls
|
||||
C.prefs_profile_begin()
|
||||
@@ -170,6 +174,7 @@ func (session *uiSession) profile_tick() bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
session.preview_profile(values)
|
||||
response := int(C.prefs_profile_response())
|
||||
if response == 0 {
|
||||
return true
|
||||
@@ -191,10 +196,42 @@ func (session *uiSession) profile_tick() bool {
|
||||
}
|
||||
C.prefs_profile_close()
|
||||
session.profileEditor = nil
|
||||
session.profileVoice = nil
|
||||
// Both Save and Cancel return to the unchanged parent speech draft.
|
||||
preview := session.profileBase
|
||||
session.profilePreview = &preview
|
||||
session.populate_profiles(max(0, session.profileIndex))
|
||||
return true
|
||||
}
|
||||
|
||||
func (session *uiSession) preview_profile(values map[string]ui.Control) {
|
||||
profile, err := session.profileEditor.Read(values)
|
||||
if err != nil || session.profileVoice != nil && voiceprofiles.Same_voice(*session.profileVoice, profile) {
|
||||
return
|
||||
}
|
||||
next, err := config.Apply_primary_voice(primary_settings(session.profileBase), profile)
|
||||
if err != nil {
|
||||
return // Incomplete or unsupported edits retain the working voice.
|
||||
}
|
||||
preview := profile_preview_values(session.profileBase, next)
|
||||
session.profileVoice = &profile
|
||||
session.profilePreview = &preview
|
||||
}
|
||||
|
||||
// Profile previews change only primary speech. The parent form and its other
|
||||
// voice drafts remain intact and are restored when the child editor closes.
|
||||
func profile_preview_values(base Values, settings config.Settings) Values {
|
||||
voice := FromSettings(settings)
|
||||
base.Rate, base.Pitch, base.Volume = voice.Rate, voice.Pitch, voice.Volume
|
||||
base.SpeechServerFactory = voice.SpeechServerFactory
|
||||
base.SpeechOutputModule = voice.SpeechOutputModule
|
||||
base.HardwareSpeechDevice = voice.HardwareSpeechDevice
|
||||
base.HardwareSpeechBaudRate = voice.HardwareSpeechBaudRate
|
||||
base.SpeechVoiceFamily = voice.SpeechVoiceFamily
|
||||
base.VoiceType = "default"
|
||||
return base
|
||||
}
|
||||
|
||||
func primary_settings(values Values) config.Settings {
|
||||
settings := config.DefaultSettings()
|
||||
settings.SpeechServerFactory = values.SpeechServerFactory
|
||||
|
||||
@@ -53,13 +53,40 @@ def check_profiles(window, initial, send, request, windowNodes):
|
||||
def choose(editor, label, index):
|
||||
assert named(editor, label, pyatspi.ROLE_COMBO_BOX).querySelection().selectChild(index), label
|
||||
|
||||
def preview_until(matches, description, acknowledge=True):
|
||||
for _ in range(30):
|
||||
preview = request()
|
||||
assert preview.get("Preview"), (description, preview)
|
||||
values = preview["Values"]
|
||||
assert values["EchoVoice"] == initial["Values"]["EchoVoice"], values
|
||||
assert values["SystemVoice"] == initial["Values"]["SystemVoice"], values
|
||||
if matches(values):
|
||||
if acknowledge:
|
||||
send({"Preview": True, "Accepted": True})
|
||||
return values
|
||||
send({"Preview": True, "Accepted": True})
|
||||
raise AssertionError(description)
|
||||
|
||||
def parent_voice(values):
|
||||
return (values["Rate"] == initial["Values"]["Rate"]
|
||||
and values["SpeechOutputModule"] == initial["Values"].get("SpeechOutputModule", ""))
|
||||
|
||||
tabs = next(node for node in windowNodes if node.getRole() == pyatspi.ROLE_PAGE_TAB_LIST)
|
||||
index = next(i for i, child in enumerate(tabs) if child.name == "Voice Profiles")
|
||||
assert tabs.querySelection().selectChild(index)
|
||||
editor = open_editor("Add Voice Profile")
|
||||
preview_until(parent_voice, "new editor did not preview its initial voice")
|
||||
named(editor, "Rate", pyatspi.ROLE_SPIN_BUTTON).queryValue().currentValue = 25
|
||||
preview_until(lambda values: values["Rate"] == 25, "profile rate was not previewed", acknowledge=False)
|
||||
# Keep that preview in flight, then supersede it and cancel the child.
|
||||
rate = named(editor, "Rate", pyatspi.ROLE_SPIN_BUTTON)
|
||||
rate.queryValue().currentValue = 35
|
||||
wait_for(lambda: rate.queryValue().currentValue == 35, "newer profile rate missing")
|
||||
named(editor, "Voice Profile Name", pyatspi.ROLE_ENTRY).queryEditableText().setTextContents("Discarded")
|
||||
activate(editor, "Cancel")
|
||||
wait_for(lambda: dialog() is None, "Cancel did not close child")
|
||||
send({"Preview": True, "Accepted": True})
|
||||
preview_until(parent_voice, "Cancel did not restore the parent voice")
|
||||
assert not any(n.name == "Discarded" for n in walk(window)), "cancelled profile retained"
|
||||
|
||||
editor = open_editor("Add Voice Profile")
|
||||
@@ -69,6 +96,7 @@ def check_profiles(window, initial, send, request, windowNodes):
|
||||
device.queryEditableText().setTextContents("/dev/fixture-synth")
|
||||
activate(editor, "Save Voice Profile")
|
||||
wait_for(lambda: dialog() is None, "hardware profile did not save")
|
||||
preview_until(parent_voice, "Save did not restore the parent voice")
|
||||
|
||||
editor = open_editor("Add Voice Profile")
|
||||
choose(editor, "Module", 1)
|
||||
@@ -80,20 +108,27 @@ def check_profiles(window, initial, send, request, windowNodes):
|
||||
wait_for(lambda: any(n.name.startswith("Spanish test voice") for n in walk(voice)), "Spanish voice missing")
|
||||
choose(editor, "Voice", 1)
|
||||
named(editor, "Rate", pyatspi.ROLE_SPIN_BUTTON).queryValue().currentValue = 20
|
||||
preview_until(lambda values: values["Rate"] == 20 and values["SpeechOutputModule"] == "test-module"
|
||||
and values.get("SpeechVoiceFamily", {}).get("Name") == "Spanish test voice",
|
||||
"module, language, voice and rate were not previewed in the child editor")
|
||||
activate(editor, "Save Voice Profile")
|
||||
wait_for(lambda: dialog() is None, "software profile did not save")
|
||||
preview_until(parent_voice, "saving a software profile did not restore the parent voice")
|
||||
|
||||
profilesControl = named(window, "Voice Profiles", pyatspi.ROLE_COMBO_BOX)
|
||||
assert profilesControl.querySelection().selectChild(1)
|
||||
editor = open_editor("Edit Voice Profile")
|
||||
preview_until(lambda values: values["Rate"] == 20, "Edit did not preview the saved profile")
|
||||
assert named(editor, "Voice Profile Name", pyatspi.ROLE_ENTRY).queryText().getText(0, -1) == "test-module Spanish test voice"
|
||||
named(editor, "Voice Profile Name", pyatspi.ROLE_ENTRY).queryEditableText().setTextContents("DECtalk")
|
||||
activate(editor, "Save Voice Profile")
|
||||
wait_for(lambda: any("already exists" in n.name for n in walk(editor)), "duplicate name not rejected")
|
||||
activate(editor, "Cancel")
|
||||
wait_for(lambda: dialog() is None, "duplicate cancellation failed")
|
||||
preview_until(parent_voice, "Edit cancellation did not restore the parent voice")
|
||||
activate(window, "Use Voice Profile")
|
||||
wait_for(lambda: named(window,"Rate",pyatspi.ROLE_SLIDER).queryValue().currentValue==20, "Use did not load primary controls")
|
||||
preview_until(lambda values: values["Rate"] == 20, "Use did not preview the selected profile")
|
||||
activate(window, "Apply")
|
||||
while True:
|
||||
applied = request()
|
||||
@@ -117,4 +152,4 @@ def check_profiles(window, initial, send, request, windowNodes):
|
||||
send({"Preview": True, "Accepted": True})
|
||||
applied = request()
|
||||
assert len(applied["Values"]["VoiceProfiles"]["Profiles"]) == 1, applied
|
||||
print("PASS: GTK profile name focus, Tab traversal, hardware/software settings, naming, duplicates, cancel, use, remove, and auxiliary voices")
|
||||
print("PASS: GTK profile previews, parent restoration, Tab traversal, naming, duplicates, cancel, use, remove, and auxiliary voices")
|
||||
Reference in new issue
Block a user