From ed6951f4cde94a74df47af675b477349379bd782 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sun, 15 Nov 2026 17:55:27 -0500 Subject: [PATCH] Share saved and custom quick voice profile choices --- README.md | 17 +++++++---- voiceprofiles/editor.go | 2 +- voiceprofiles/quick.go | 51 +++++++++++++++++++++++++++++++++ voiceprofiles/quick_test.go | 57 +++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 voiceprofiles/quick.go create mode 100644 voiceprofiles/quick_test.go diff --git a/README.md b/README.md index 64b8621..54f7d51 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,13 @@ the selected entry disappeared so a reader can refuse to change a different setting by mistake. `MessageIDs` lists the menu's own English messages for translation catalogs. +`voiceprofiles` supplies the shared Voice profile quick setting: `Quick_options` +lists "Default" for the saved voice, then each profile, and adds "Custom" only +while the current voice matches neither. These helpers are available starting +with v0.7.0. `Quick_choice` reports the current +choice and `Quick_profile` resolves a selection. Readers pass the voice that +"Default" restores, such as the focused application's saved voice. + Both readers store rate, pitch and volume on Speech Dispatcher's -100..100 scale, which the hardware protocol also uses. `speechdispatcher.DiscoverQuery` validates module and voice lists, drops repeated voice aliases and keeps @@ -60,7 +67,7 @@ checks. Leave submission to the contributor after their review and testing. The shared quick menu and validated discovery API are available starting with v0.5.0. Shared translation message ID lists are available starting with v0.6.1. -Both readers pin v0.6.1 for standalone builds. +Both readers pin v0.7.0 for standalone builds. ## License @@ -190,7 +197,7 @@ and 0..9 pitch/volume values at the boundary. It no longer has a separate DECtalk encoding. Port opening, serial/USB I/O, flush timing and cancellation synchronization remain the responsibility of the device-owning reader. -These additions are available starting with v0.4.0. Both readers pin v0.6.1 +These additions are available starting with v0.4.0. Both readers pin v0.7.0 for standalone builds. Verify pinned dependencies with `GOWORK=off`; physical keyboard, audible speech, braille, and hardware acceptance remain separate live checks. @@ -198,8 +205,8 @@ separate live checks. ## Primary voice profiles `voiceprofiles` supplies the shared primary-voice preset model, collection -validation/copying, unique automatic names, management-tab controls, and editor -forms for software and hardware speech. `Editor.Refresh_session` maintains +validation/copying, automatic names with duplicate rejection, management-tab +controls, and editor forms for software and hardware speech. `Editor.Refresh_session` maintains module/language/voice dependencies in the shared UI toolkit; native GTK hosts use the same form and dependent-control updates. Catalog discovery, native widget rendering, speech preparation/rollback and atomic settings persistence @@ -210,6 +217,6 @@ settings and never modifies unrelated preferences. `internalui.Session.Focus_control` restores a control when a child editor returns to its parent form. `quicksettings.Option.Literal` preserves user-chosen profile names without translation. These APIs are available starting with v0.6.0; -both readers pin v0.6.1 for standalone builds. Run `go test -race ./...` here and the +both readers pin v0.7.0 for standalone builds. Run `go test -race ./...` here and the consumer settings/speech regressions with `GOWORK=off` in both readers. The sibling workspace supports local development without machine-specific replaces. diff --git a/voiceprofiles/editor.go b/voiceprofiles/editor.go index 41e7bd7..6a32ac3 100644 --- a/voiceprofiles/editor.go +++ b/voiceprofiles/editor.go @@ -228,7 +228,7 @@ func (c Collection) Tab() ui.Tab { // Synthesizer, module, language and voice names are presented literally. func MessageIDs() []string { return []string{ - "Add Voice Profile", "Baud rate", "Cancel", "Default", "Edit Voice Profile", "Language", + "Add Voice Profile", "Baud rate", "Cancel", "Custom", "Default", "Edit Voice Profile", "Language", "Module", "Pitch", "Rate", "Remove Voice Profile", "Save Voice Profile", "Serial device", "Synthesizer", "Use Voice Profile", "Voice", "Voice Profile", "Voice Profile Name", "Voice Profiles", "Volume", diff --git a/voiceprofiles/quick.go b/voiceprofiles/quick.go new file mode 100644 index 0000000..481d426 --- /dev/null +++ b/voiceprofiles/quick.go @@ -0,0 +1,51 @@ +// Copyright (c) 2026 Storm Dragon +// SPDX-License-Identifier: GPL-3.0-or-later + +package voiceprofiles + +import "git.stormux.org/storm/screenreader-common/quicksettings" + +// QuickSavedChoice is the quick settings choice for the saved voice, announced +// as "Default". Profile names are visible text, so this ID cannot collide. +const QuickSavedChoice = "\x00saved" + +// Quick_choice names the profile matching current, then QuickSavedChoice when +// current is the saved voice, and otherwise "" for a voice changed this session. +// saved is the voice the reader would use without session changes, such as the +// focused application's saved voice; nil when unknown. +func (c Collection) Quick_choice(current Profile, saved *Profile) string { + if name := c.Matching(current); name != "" { + return name + } + if saved != nil && Same_voice(*saved, current) { + return QuickSavedChoice + } + return "" +} + +// Quick_options lists "Custom" only while current matches no saved voice, then +// "Default" for the saved voice, then each profile by name. +func (c Collection) Quick_options(current Profile, saved *Profile) []quicksettings.Option { + options := []quicksettings.Option{} + if c.Quick_choice(current, saved) == "" { + options = append(options, quicksettings.Option{ID: "", Label: "Custom"}) + } + if saved != nil { + options = append(options, quicksettings.Option{ID: QuickSavedChoice, Label: "Default"}) + } + for _, p := range c.Profiles { + options = append(options, quicksettings.Option{ID: p.Name, Label: p.Name, Literal: true}) + } + return options +} + +// Quick_profile returns the voice a quick settings choice selects. +func (c Collection) Quick_profile(choice string, saved *Profile) (Profile, bool) { + if choice == QuickSavedChoice { + if saved == nil { + return Profile{}, false + } + return *saved, true + } + return c.Find(choice) +} diff --git a/voiceprofiles/quick_test.go b/voiceprofiles/quick_test.go new file mode 100644 index 0000000..cb28a5d --- /dev/null +++ b/voiceprofiles/quick_test.go @@ -0,0 +1,57 @@ +// Copyright (c) 2026 Storm Dragon +// SPDX-License-Identifier: GPL-3.0-or-later + +package voiceprofiles + +import ( + "reflect" + "testing" + + "git.stormux.org/storm/screenreader-common/quicksettings" +) + +func TestQuickChoicesNameSavedVoiceDefault(t *testing.T) { + saved := fixture_profile() + named := fixture_profile() + named.Name, named.Rate = "Fast", 50 + collection := Collection{Profiles: []Profile{named}} + labels := func(options []quicksettings.Option) []string { + var result []string + for _, option := range options { + result = append(result, option.Label) + } + return result + } + + if choice := collection.Quick_choice(saved, &saved); choice != QuickSavedChoice { + t.Fatalf("unchanged voice choice = %q", choice) + } + if got := labels(collection.Quick_options(saved, &saved)); !reflect.DeepEqual(got, []string{"Default", "Fast"}) { + t.Fatalf("unchanged voice options = %q", got) + } + if choice := collection.Quick_choice(named, &saved); choice != "Fast" { + t.Fatalf("profile choice = %q", choice) + } + + changed := saved + changed.Rate = 20 + if choice := collection.Quick_choice(changed, &saved); choice != "" { + t.Fatalf("changed voice choice = %q", choice) + } + if got := labels(collection.Quick_options(changed, &saved)); !reflect.DeepEqual(got, []string{"Custom", "Default", "Fast"}) { + t.Fatalf("changed voice options = %q", got) + } + if got := labels((Collection{}).Quick_options(saved, &saved)); !reflect.DeepEqual(got, []string{"Default"}) { + t.Fatalf("options without profiles = %q", got) + } + + if p, ok := collection.Quick_profile(QuickSavedChoice, &saved); !ok || p != saved { + t.Fatal("saved choice did not return the saved voice") + } + if _, ok := collection.Quick_profile(QuickSavedChoice, nil); ok { + t.Fatal("unknown saved voice was selectable") + } + if p, ok := collection.Quick_profile("Fast", &saved); !ok || p.Name != "Fast" { + t.Fatal("profile choice did not return the profile") + } +}