Fix quick voice defaults and combo history with shared core v0.7.0
This commit is contained in:
1 parent
cad3360bd8
commit
1b42dde756
12 files changed
+149
-42
No files matched your search
@@ -670,7 +670,7 @@ the preset. Failed speech changes retain the previous configuration. Cthulhu's
|
|||||||
existing restriction on combining hardware primary speech with a separate echo
|
existing restriction on combining hardware primary speech with a separate echo
|
||||||
synthesizer still applies.
|
synthesizer still applies.
|
||||||
|
|
||||||
Standalone builds pin `screenreader-common v0.6.1`, which supplies the shared
|
Standalone builds pin `screenreader-common v0.7.0`, which supplies the shared
|
||||||
profile model and editor. A sibling Go workspace can use local common-module
|
profile model and editor. A sibling Go workspace can use local common-module
|
||||||
changes during development.
|
changes during development.
|
||||||
See [profile verification](docs/testing/voice-profiles.md).
|
See [profile verification](docs/testing/voice-profiles.md).
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Primary voice profiles
|
# Primary voice profiles
|
||||||
|
|
||||||
Standalone builds pin screenreader-common v0.6.1. Use `GOWORK=off` to verify
|
Standalone builds pin screenreader-common v0.7.0. Use `GOWORK=off` to verify
|
||||||
the released dependency; a sibling workspace remains useful for development.
|
the released dependency; a sibling workspace remains useful for development.
|
||||||
Run shared tests with `GOWORK=off go test -race ./...` in screenreader-common.
|
Run shared tests with `GOWORK=off go test -race ./...` in screenreader-common.
|
||||||
In Cthulhu, run `GOWORK=off go test ./internal/config ./internal/preferences
|
In Cthulhu, run `GOWORK=off go test ./internal/config ./internal/preferences
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ require github.com/godbus/dbus/v5 v5.1.0
|
|||||||
|
|
||||||
require github.com/gorilla/websocket v1.5.3
|
require github.com/gorilla/websocket v1.5.3
|
||||||
|
|
||||||
require git.stormux.org/storm/screenreader-common v0.6.1
|
require git.stormux.org/storm/screenreader-common v0.7.0
|
||||||
@@ -12,6 +12,8 @@ git.stormux.org/storm/screenreader-common v0.6.0 h1:iXsUBBjHOQTPu3ROTR9ysrPOi3iI
|
|||||||
git.stormux.org/storm/screenreader-common v0.6.0/go.mod h1:iLmD0KXRvR4ar3U80JMwbaNUOyR82/gY7xHUY+zeIoY=
|
git.stormux.org/storm/screenreader-common v0.6.0/go.mod h1:iLmD0KXRvR4ar3U80JMwbaNUOyR82/gY7xHUY+zeIoY=
|
||||||
git.stormux.org/storm/screenreader-common v0.6.1 h1:IVIVyihIjI38XWsxGlI3hwdSrNNSyGbxa9rPgfan0Ac=
|
git.stormux.org/storm/screenreader-common v0.6.1 h1:IVIVyihIjI38XWsxGlI3hwdSrNNSyGbxa9rPgfan0Ac=
|
||||||
git.stormux.org/storm/screenreader-common v0.6.1/go.mod h1:iLmD0KXRvR4ar3U80JMwbaNUOyR82/gY7xHUY+zeIoY=
|
git.stormux.org/storm/screenreader-common v0.6.1/go.mod h1:iLmD0KXRvR4ar3U80JMwbaNUOyR82/gY7xHUY+zeIoY=
|
||||||
|
git.stormux.org/storm/screenreader-common v0.7.0 h1:AUrvGrAFwT+7TTZVqq6sgdEeESsHnj7gFt1xPtbARC4=
|
||||||
|
git.stormux.org/storm/screenreader-common v0.7.0/go.mod h1:iLmD0KXRvR4ar3U80JMwbaNUOyR82/gY7xHUY+zeIoY=
|
||||||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
|
|||||||
@@ -31,10 +31,12 @@ func (history *comboPresentation) observe(event atspi.Event) (text string, updat
|
|||||||
text = presentation.ComboBoxSelectionText(event.Source)
|
text = presentation.ComboBoxSelectionText(event.Source)
|
||||||
update = !focusGain || event.Source.ID() == history.focus
|
update = !focusGain || event.Source.ID() == history.focus
|
||||||
duplicate = update && event.Source.ID() == history.focus && text == history.value
|
duplicate = update && event.Source.ID() == history.focus && text == history.value
|
||||||
history.value = text
|
|
||||||
if focusGain {
|
if focusGain {
|
||||||
history.focus = event.Source.ID()
|
history.focus = event.Source.ID()
|
||||||
}
|
}
|
||||||
|
if event.Source.ID() == history.focus {
|
||||||
|
history.value = text
|
||||||
|
}
|
||||||
return text, update, duplicate
|
return text, update, duplicate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,3 +90,18 @@ func TestClosedGTKComboSelectionSpeaksOnlyNewValue(t *testing.T) {
|
|||||||
t.Fatalf("speech = %q, want %q", got, want)
|
t.Fatalf("speech = %q, want %q", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestComboHistoryKeepsFocusedValueAcrossOtherComboUpdates(t *testing.T) {
|
||||||
|
var history comboPresentation
|
||||||
|
combo := atspi.Snapshot{BusName: ":1.70", Path: "/focused", Role: "combo box", ValueText: "Selected"}
|
||||||
|
history.observe(atspi.NewEvent(atspi.FocusEvent, combo))
|
||||||
|
other := combo
|
||||||
|
other.Path, other.ValueText = "/other", "Other selection"
|
||||||
|
history.observe(atspi.NewEvent(atspi.AccessibleNameEvent, other))
|
||||||
|
item := atspi.Snapshot{BusName: combo.BusName, Path: "/item", Role: "menu item", Name: "Selected"}
|
||||||
|
selection := atspi.NewEvent(atspi.SelectionChangedEvent, item)
|
||||||
|
selection.OriginPath = combo.Path
|
||||||
|
if !history.echoesSelection(selection) {
|
||||||
|
t.Fatal("another combo replaced the focused combo's remembered selection")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,7 +49,10 @@ type preferencesWorker struct {
|
|||||||
globalSettings config.Settings
|
globalSettings config.Settings
|
||||||
appSettings map[string]config.Settings
|
appSettings map[string]config.Settings
|
||||||
quickSpeech quickSpeechSettings
|
quickSpeech quickSpeechSettings
|
||||||
savedVoice *voiceprofiles.Profile // Quick settings "Default"; nil when unknown.
|
savedVoice *voiceprofiles.Profile // Global quick settings "Default"; nil when unknown.
|
||||||
|
// savedApplications holds each mapped application's saved settings for
|
||||||
|
// its quick settings "Default" voice.
|
||||||
|
savedApplications map[string]savedApplicationSettings
|
||||||
laptopLayout bool
|
laptopLayout bool
|
||||||
activeApp string
|
activeApp string
|
||||||
editApp string
|
editApp string
|
||||||
@@ -97,6 +100,12 @@ func (worker *preferencesWorker) setGlobalSettings(settings config.Settings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// savedApplicationSettings is an application's saved settings and the global
|
||||||
|
// settings they were saved over.
|
||||||
|
type savedApplicationSettings struct {
|
||||||
|
global, application config.Settings
|
||||||
|
}
|
||||||
|
|
||||||
func newPreferencesWorker(logger *slog.Logger, settings config.Settings, updater any) *preferencesWorker {
|
func newPreferencesWorker(logger *slog.Logger, settings config.Settings, updater any) *preferencesWorker {
|
||||||
saved := config.Primary_voice(settings)
|
saved := config.Primary_voice(settings)
|
||||||
return &preferencesWorker{savedVoice: &saved, logger: logger, settings: settings, globalSettings: settings, appSettings: make(map[string]config.Settings), updater: updater,
|
return &preferencesWorker{savedVoice: &saved, logger: logger, settings: settings, globalSettings: settings, appSettings: make(map[string]config.Settings), updater: updater,
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ func (worker *preferencesWorker) applicationSettings(application string) (config
|
|||||||
if !mapped {
|
if !mapped {
|
||||||
return worker.globalSettings, nil
|
return worker.globalSettings, nil
|
||||||
}
|
}
|
||||||
|
worker.remember_application(application, persistedGlobal, settings)
|
||||||
settings = config.RebaseApplicationSettings(persistedGlobal, worker.globalSettings, settings)
|
settings = config.RebaseApplicationSettings(persistedGlobal, worker.globalSettings, settings)
|
||||||
worker.appSettings[application] = settings
|
worker.appSettings[application] = settings
|
||||||
return worker.quickSpeech.apply(settings), nil
|
return worker.quickSpeech.apply(settings), nil
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ func (worker *preferencesWorker) applyNext(ctx context.Context, next config.Sett
|
|||||||
// An explicit preferences Apply replaces the session's quick speech choices.
|
// An explicit preferences Apply replaces the session's quick speech choices.
|
||||||
if worker.editingActive {
|
if worker.editingActive {
|
||||||
worker.quickSpeech = quickSpeechSettings{}
|
worker.quickSpeech = quickSpeechSettings{}
|
||||||
worker.remember_saved_voice(next)
|
worker.remember_saved_voice(next, scopeApp)
|
||||||
}
|
}
|
||||||
if worker.editingActive {
|
if worker.editingActive {
|
||||||
worker.editing = next
|
worker.editing = next
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ import (
|
|||||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||||
)
|
)
|
||||||
|
|
||||||
// quickSavedVoice is the voice-profile choice for the saved speech settings.
|
|
||||||
// Profile names are visible text, so this identifier cannot collide.
|
|
||||||
const quickSavedVoice = "\x00saved"
|
|
||||||
|
|
||||||
// Use the settings worker's bounded mailbox, keeping discovery, disk writes,
|
// Use the settings worker's bounded mailbox, keeping discovery, disk writes,
|
||||||
// and speech connection replacement off the input and focus paths.
|
// and speech connection replacement off the input and focus paths.
|
||||||
func (worker *preferencesWorker) SpeechCommand(command input.Command) {
|
func (worker *preferencesWorker) SpeechCommand(command input.Command) {
|
||||||
@@ -176,9 +172,8 @@ func (host *quickSettingsHost) categories() []quicksettings.Category {
|
|||||||
quicksettings.Entry{ID: "speech.rate", Label: "Rate", Kind: quicksettings.Range, Min: -100, Max: 100, Step: quickVoiceStep},
|
quicksettings.Entry{ID: "speech.rate", Label: "Rate", Kind: quicksettings.Range, Min: -100, Max: 100, Step: quickVoiceStep},
|
||||||
quicksettings.Entry{ID: "speech.pitch", Label: "Pitch", Kind: quicksettings.Range, Min: -100, Max: 100, Step: quickVoiceStep},
|
quicksettings.Entry{ID: "speech.pitch", Label: "Pitch", Kind: quicksettings.Range, Min: -100, Max: 100, Step: quickVoiceStep},
|
||||||
quicksettings.Entry{ID: "speech.volume", Label: "Volume", Kind: quicksettings.Range, Min: -100, Max: 100, Step: quickVoiceStep})
|
quicksettings.Entry{ID: "speech.volume", Label: "Volume", Kind: quicksettings.Range, Min: -100, Max: 100, Step: quickVoiceStep})
|
||||||
if len(host.settings.VoiceProfiles.Profiles) > 0 {
|
// Always offered so "Default" can restore the saved voice without profiles.
|
||||||
voice = append(voice, quicksettings.Entry{ID: "speech.profile", Label: "Voice profile", Kind: quicksettings.Choice})
|
voice = append(voice, quicksettings.Entry{ID: "speech.profile", Label: "Voice profile", Kind: quicksettings.Choice})
|
||||||
}
|
|
||||||
reading := []quicksettings.Entry{
|
reading := []quicksettings.Entry{
|
||||||
{ID: "reading.punctuation", Label: "Punctuation level", Kind: quicksettings.Choice},
|
{ID: "reading.punctuation", Label: "Punctuation level", Kind: quicksettings.Choice},
|
||||||
{ID: "reading.indentation", Label: "Indentation", Kind: quicksettings.Choice},
|
{ID: "reading.indentation", Label: "Indentation", Kind: quicksettings.Choice},
|
||||||
@@ -279,22 +274,12 @@ func (host *quickSettingsHost) catalog() bool {
|
|||||||
func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksettings.Option {
|
func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksettings.Option {
|
||||||
switch entry.ID {
|
switch entry.ID {
|
||||||
case "speech.profile":
|
case "speech.profile":
|
||||||
options := []quicksettings.Option{}
|
return host.settings.VoiceProfiles.Quick_options(config.Primary_voice(host.settings), host.saved_voice())
|
||||||
if host.voice_profile_choice(host.settings) == "" {
|
|
||||||
options = append(options, quicksettings.Option{ID: "", Label: "Custom"})
|
|
||||||
}
|
|
||||||
if host.worker != nil && host.worker.savedVoice != nil {
|
|
||||||
options = append(options, quicksettings.Option{ID: quickSavedVoice, Label: "Default"})
|
|
||||||
}
|
|
||||||
for _, p := range host.settings.VoiceProfiles.Profiles {
|
|
||||||
options = append(options, quicksettings.Option{ID: p.Name, Label: p.Name, Literal: true})
|
|
||||||
}
|
|
||||||
return options
|
|
||||||
case "speech.module":
|
case "speech.module":
|
||||||
var options []quicksettings.Option
|
var options []quicksettings.Option
|
||||||
if host.hardware() {
|
if host.hardware() {
|
||||||
for _, module := range hardwareSynthesizers {
|
for _, module := range hardwareSynthesizers {
|
||||||
options = append(options, quicksettings.Option{ID: module, Label: module})
|
options = append(options, quicksettings.Option{ID: module, Label: module, Literal: true})
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
@@ -304,7 +289,7 @@ func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksetting
|
|||||||
options = []quicksettings.Option{{ID: "", Label: "default"}}
|
options = []quicksettings.Option{{ID: "", Label: "default"}}
|
||||||
for module := range host.worker.catalog {
|
for module := range host.worker.catalog {
|
||||||
if module != "" {
|
if module != "" {
|
||||||
options = append(options, quicksettings.Option{ID: module, Label: module})
|
options = append(options, quicksettings.Option{ID: module, Label: module, Literal: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Slice(options[1:], func(i, j int) bool { return options[1+i].ID < options[1+j].ID })
|
sort.Slice(options[1:], func(i, j int) bool { return options[1+i].ID < options[1+j].ID })
|
||||||
@@ -320,7 +305,7 @@ func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksetting
|
|||||||
normalized := sd.NormalizeLanguage(language)
|
normalized := sd.NormalizeLanguage(language)
|
||||||
if language != "" && !seen[normalized] {
|
if language != "" && !seen[normalized] {
|
||||||
seen[normalized] = true
|
seen[normalized] = true
|
||||||
options = append(options, quicksettings.Option{ID: language, Label: language})
|
options = append(options, quicksettings.Option{ID: language, Label: language, Literal: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
@@ -336,7 +321,7 @@ func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksetting
|
|||||||
voices = quickSpeechVoices(host.settings.SpeechOutputModule, voices)
|
voices = quickSpeechVoices(host.settings.SpeechOutputModule, voices)
|
||||||
}
|
}
|
||||||
for _, voice := range voices {
|
for _, voice := range voices {
|
||||||
options = append(options, quicksettings.Option{ID: voiceOptionID(&config.VoiceFamily{Name: voice.Name, Lang: voice.Language, Variant: voice.Variant}), Label: voice.Name})
|
options = append(options, quicksettings.Option{ID: voiceOptionID(&config.VoiceFamily{Name: voice.Name, Lang: voice.Language, Variant: voice.Variant}), Label: voice.Name, Literal: true})
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
case "reading.punctuation":
|
case "reading.punctuation":
|
||||||
@@ -422,10 +407,7 @@ func (worker *preferencesWorker) apply_quick_setting(ctx context.Context, host *
|
|||||||
next := host.settings
|
next := host.settings
|
||||||
var speechChanged bool
|
var speechChanged bool
|
||||||
if result.Entry.ID == "speech.profile" {
|
if result.Entry.ID == "speech.profile" {
|
||||||
p, ok := next.VoiceProfiles.Find(result.Value.Choice)
|
p, ok := next.VoiceProfiles.Quick_profile(result.Value.Choice, host.saved_voice())
|
||||||
if result.Value.Choice == quickSavedVoice && worker.savedVoice != nil {
|
|
||||||
p, ok = *worker.savedVoice, true
|
|
||||||
}
|
|
||||||
if !ok {
|
if !ok {
|
||||||
worker.announceSpeechSetting("Choose a saved voice profile")
|
worker.announceSpeechSetting("Choose a saved voice profile")
|
||||||
return false
|
return false
|
||||||
@@ -547,19 +529,49 @@ func quickSpeechVoices(module string, voices []speech.Voice) []speech.Voice {
|
|||||||
// voice_profile_choice names the matching profile, then the saved voice, and
|
// voice_profile_choice names the matching profile, then the saved voice, and
|
||||||
// otherwise reports a custom session voice.
|
// otherwise reports a custom session voice.
|
||||||
func (host *quickSettingsHost) voice_profile_choice(settings config.Settings) string {
|
func (host *quickSettingsHost) voice_profile_choice(settings config.Settings) string {
|
||||||
primary := config.Primary_voice(settings)
|
return settings.VoiceProfiles.Quick_choice(config.Primary_voice(settings), host.saved_voice())
|
||||||
if name := settings.VoiceProfiles.Matching(primary); name != "" {
|
}
|
||||||
return name
|
|
||||||
|
func (host *quickSettingsHost) saved_voice() *voiceprofiles.Profile {
|
||||||
|
if host.worker == nil {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
if host.worker != nil && host.worker.savedVoice != nil && voiceprofiles.Same_voice(*host.worker.savedVoice, primary) {
|
return host.worker.saved_voice()
|
||||||
return quickSavedVoice
|
}
|
||||||
|
|
||||||
|
// saved_voice is the voice quick settings "Default" restores: the focused
|
||||||
|
// application's saved voice when it has its own, otherwise the global voice
|
||||||
|
// from startup or the last explicit Apply.
|
||||||
|
func (worker *preferencesWorker) saved_voice() *voiceprofiles.Profile {
|
||||||
|
saved, ok := worker.savedApplications[worker.activeApp]
|
||||||
|
if worker.savedVoice == nil || !ok {
|
||||||
|
return worker.savedVoice
|
||||||
}
|
}
|
||||||
return ""
|
// Rebase onto the saved global voice so an application that inherits the
|
||||||
|
// global voice keeps following it.
|
||||||
|
global, err := config.Apply_primary_voice(saved.global, *worker.savedVoice)
|
||||||
|
if err != nil {
|
||||||
|
global = saved.global
|
||||||
|
}
|
||||||
|
voice := config.Primary_voice(worker.effective_settings(config.RebaseApplicationSettings(saved.global, global, saved.application)))
|
||||||
|
return &voice
|
||||||
}
|
}
|
||||||
|
|
||||||
// remember_saved_voice records the voice that quick settings "Default"
|
// remember_saved_voice records the voice that quick settings "Default"
|
||||||
// restores: the one in the settings at startup or the last explicit Apply.
|
// restores after an explicit Apply. An application Apply records only that
|
||||||
func (worker *preferencesWorker) remember_saved_voice(settings config.Settings) {
|
// application's saved settings, over the global settings it was edited from.
|
||||||
|
func (worker *preferencesWorker) remember_saved_voice(settings config.Settings, application string) {
|
||||||
|
if application != "" {
|
||||||
|
worker.remember_application(application, worker.globalSettings, settings)
|
||||||
|
return
|
||||||
|
}
|
||||||
saved := config.Primary_voice(worker.effective_settings(settings))
|
saved := config.Primary_voice(worker.effective_settings(settings))
|
||||||
worker.savedVoice = &saved
|
worker.savedVoice = &saved
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (worker *preferencesWorker) remember_application(application string, global, settings config.Settings) {
|
||||||
|
if worker.savedApplications == nil {
|
||||||
|
worker.savedApplications = make(map[string]savedApplicationSettings)
|
||||||
|
}
|
||||||
|
worker.savedApplications[application] = savedApplicationSettings{global: global, application: settings}
|
||||||
|
}
|
||||||
@@ -68,7 +68,7 @@ func TestSpeechShortcutsApplySaveAndFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
updateError = nil
|
updateError = nil
|
||||||
worker.catalog = speech.Catalog{"": {{Name: "default", Language: "en"}}, "alpha": {{Name: "one", Language: "en"}, {Name: "two", Language: "en"}}, "beta": {{Name: "three", Language: "en"}}}
|
worker.catalog = speech.Catalog{"": {{Name: "default", Language: "en"}}, "alpha": {{Name: "one", Language: "en"}, {Name: "two", Language: "en"}}, "beta": {{Name: "three", Language: "en"}}}
|
||||||
for _, want := range []string{"Pitch 0", "Volume 100", "Speech-dispatcher module default"} {
|
for _, want := range []string{"Pitch 0", "Volume 100", "Voice profile Custom", "Speech-dispatcher module default"} {
|
||||||
command(input.SelectNextSpeechSetting)
|
command(input.SelectNextSpeechSetting)
|
||||||
if message != want {
|
if message != want {
|
||||||
t.Fatalf("got %q, want %q", message, want)
|
t.Fatalf("got %q, want %q", message, want)
|
||||||
@@ -453,7 +453,7 @@ func TestHardwareQuickSettingsOfferSynthesizersWithoutVoices(t *testing.T) {
|
|||||||
}
|
}
|
||||||
var messages []string
|
var messages []string
|
||||||
worker.announce = func(text string) { messages = append(messages, text) }
|
worker.announce = func(text string) { messages = append(messages, text) }
|
||||||
for _, want := range []string{"Rate 0", "Pitch 0", "Volume 100", "Hardware synthesizer doubletalk"} {
|
for _, want := range []string{"Rate 0", "Pitch 0", "Volume 100", "Voice profile Default", "Hardware synthesizer doubletalk"} {
|
||||||
worker.handleSpeechCommand(t.Context(), input.SelectNextSpeechSetting)
|
worker.handleSpeechCommand(t.Context(), input.SelectNextSpeechSetting)
|
||||||
if got := messages[len(messages)-1]; got != want {
|
if got := messages[len(messages)-1]; got != want {
|
||||||
t.Fatalf("got %q, want %q", got, want)
|
t.Fatalf("got %q, want %q", got, want)
|
||||||
@@ -551,6 +551,28 @@ func TestQuickSettingsRetainPartialDiscovery(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestQuickSpeechNamesBypassTranslation(t *testing.T) {
|
||||||
|
settings := config.DefaultSettings()
|
||||||
|
settings.SpeechOutputModule = "all"
|
||||||
|
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), settings, nil)
|
||||||
|
worker.catalog = speech.Catalog{"all": {{Name: "default", Language: "en"}}}
|
||||||
|
host := &quickSettingsHost{worker: worker, ctx: t.Context(), settings: settings}
|
||||||
|
menu := quicksettings.New(nil, quicksettings.Messages{Translate: func(text string) string { return "translated " + text }})
|
||||||
|
for _, id := range []string{"module", "language", "voice"} {
|
||||||
|
entry := quicksettings.Entry{ID: "speech." + id, Kind: quicksettings.Choice}
|
||||||
|
options := host.Options(entry)
|
||||||
|
if len(options) != 2 {
|
||||||
|
t.Fatal(id, options)
|
||||||
|
}
|
||||||
|
if got := menu.Describe(entry, quicksettings.Value{Choice: options[1].ID}, options); got != options[1].Label {
|
||||||
|
t.Fatalf("%s name translated: %q", id, got)
|
||||||
|
}
|
||||||
|
if got := menu.Describe(entry, quicksettings.Value{}, options); got != "translated default" {
|
||||||
|
t.Fatalf("%s default label not translated: %q", id, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestQuickSpeechLanguageFiltersVoicesAndKeepsDefaultLanguage(t *testing.T) {
|
func TestQuickSpeechLanguageFiltersVoicesAndKeepsDefaultLanguage(t *testing.T) {
|
||||||
settings := config.DefaultSettings()
|
settings := config.DefaultSettings()
|
||||||
settings.Path = filepath.Join(t.TempDir(), "settings.toml")
|
settings.Path = filepath.Join(t.TempDir(), "settings.toml")
|
||||||
|
|||||||
@@ -71,3 +71,47 @@ func TestQuickVoiceProfileDefaultRestoresSavedVoiceFromCustom(t *testing.T) {
|
|||||||
t.Fatal("Default did not restore the saved voice", messages, worker.settings.DefaultVoice)
|
t.Fatal("Default did not restore the saved voice", messages, worker.settings.DefaultVoice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestQuickVoiceProfileDefaultIsFocusedApplicationVoice(t *testing.T) {
|
||||||
|
global := config.DefaultSettings()
|
||||||
|
global.Path = filepath.Join(t.TempDir(), "settings.toml")
|
||||||
|
store, err := config.NewStore(global.Path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := store.Save(global); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
application := global
|
||||||
|
rate, volume := 82.0, 40.0
|
||||||
|
application.DefaultVoice.Rate, application.DefaultVoice.Gain = &rate, &volume
|
||||||
|
if err := store.SaveForApplication("Voiced Application", application); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := store.SaveForApplication("Plain Application", global); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), global, settingsUpdateFunc(func(context.Context, speech.Settings) error { return nil }))
|
||||||
|
var messages []string
|
||||||
|
worker.announce = func(text string) { messages = append(messages, text) }
|
||||||
|
worker.switchApplication(t.Context(), "Voiced Application")
|
||||||
|
selectQuickSetting(t, worker, "speech.profile")
|
||||||
|
if got := messages[len(messages)-1]; got != "Voice profile Default" {
|
||||||
|
t.Fatal("application voice not reported as Default", got)
|
||||||
|
}
|
||||||
|
selectQuickSetting(t, worker, "speech.rate")
|
||||||
|
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
|
||||||
|
selectQuickSetting(t, worker, "speech.profile")
|
||||||
|
if got := messages[len(messages)-1]; got != "Voice profile Custom" {
|
||||||
|
t.Fatal("changed application voice not reported as Custom", got)
|
||||||
|
}
|
||||||
|
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
|
||||||
|
if got := messages[len(messages)-1]; got != "Default" || *worker.settings.DefaultVoice.Rate != 82 || *worker.settings.DefaultVoice.Gain != 40 {
|
||||||
|
t.Fatal("Default did not restore the application voice", messages, worker.settings.DefaultVoice)
|
||||||
|
}
|
||||||
|
// An application without its own voice follows the global saved voice.
|
||||||
|
worker.switchApplication(t.Context(), "Plain Application")
|
||||||
|
if saved := worker.saved_voice(); saved == nil || !voiceprofiles.Same_voice(*saved, config.Primary_voice(global)) {
|
||||||
|
t.Fatal("inherited application voice was not the global voice", saved)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user