Share saved and custom quick voice profile choices
This commit is contained in:
1 parent
8a61bfff04
commit
ed6951f4cd
4 files changed
+121
-6
No files matched your search
@@ -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
|
setting by mistake. `MessageIDs` lists the menu's own English messages for
|
||||||
translation catalogs.
|
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
|
Both readers store rate, pitch and volume on Speech Dispatcher's -100..100
|
||||||
scale, which the hardware protocol also uses. `speechdispatcher.DiscoverQuery`
|
scale, which the hardware protocol also uses. `speechdispatcher.DiscoverQuery`
|
||||||
validates module and voice lists, drops repeated voice aliases and keeps
|
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
|
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.
|
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
|
## 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
|
DECtalk encoding. Port opening, serial/USB I/O, flush timing and cancellation
|
||||||
synchronization remain the responsibility of the device-owning reader.
|
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`;
|
for standalone builds. Verify pinned dependencies with `GOWORK=off`;
|
||||||
physical keyboard, audible speech, braille, and hardware acceptance remain
|
physical keyboard, audible speech, braille, and hardware acceptance remain
|
||||||
separate live checks.
|
separate live checks.
|
||||||
@@ -198,8 +205,8 @@ separate live checks.
|
|||||||
## Primary voice profiles
|
## Primary voice profiles
|
||||||
|
|
||||||
`voiceprofiles` supplies the shared primary-voice preset model, collection
|
`voiceprofiles` supplies the shared primary-voice preset model, collection
|
||||||
validation/copying, unique automatic names, management-tab controls, and editor
|
validation/copying, automatic names with duplicate rejection, management-tab
|
||||||
forms for software and hardware speech. `Editor.Refresh_session` maintains
|
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
|
module/language/voice dependencies in the shared UI toolkit; native GTK hosts
|
||||||
use the same form and dependent-control updates. Catalog discovery, native
|
use the same form and dependent-control updates. Catalog discovery, native
|
||||||
widget rendering, speech preparation/rollback and atomic settings persistence
|
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
|
`internalui.Session.Focus_control` restores a control when a child editor
|
||||||
returns to its parent form. `quicksettings.Option.Literal` preserves user-chosen
|
returns to its parent form. `quicksettings.Option.Literal` preserves user-chosen
|
||||||
profile names without translation. These APIs are available starting with v0.6.0;
|
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
|
consumer settings/speech regressions with `GOWORK=off` in both readers. The
|
||||||
sibling workspace supports local development without machine-specific replaces.
|
sibling workspace supports local development without machine-specific replaces.
|
||||||
@@ -228,7 +228,7 @@ func (c Collection) Tab() ui.Tab {
|
|||||||
// Synthesizer, module, language and voice names are presented literally.
|
// Synthesizer, module, language and voice names are presented literally.
|
||||||
func MessageIDs() []string {
|
func MessageIDs() []string {
|
||||||
return []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",
|
"Module", "Pitch", "Rate", "Remove Voice Profile", "Save Voice Profile", "Serial device",
|
||||||
"Synthesizer", "Use Voice Profile", "Voice", "Voice Profile", "Voice Profile Name",
|
"Synthesizer", "Use Voice Profile", "Voice", "Voice Profile", "Voice Profile Name",
|
||||||
"Voice Profiles", "Volume",
|
"Voice Profiles", "Volume",
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user