Add primary voice profiles from shared reader core v0.6.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0f5c2db158
commit
764a289071
26 files changed
+820
-5
No files matched your search
@@ -39,6 +39,7 @@ func (worker *preferencesWorker) apply(ctx context.Context, request preferences.
|
||||
// application preferences, so an application-scoped Apply never
|
||||
// edits them: the base values pass through unchanged and only a
|
||||
// global Apply can republish the governing Wine list.
|
||||
request.Values.VoiceProfiles = base.VoiceProfiles.Clone()
|
||||
request.Values.Wine = config.WineSettings{ControllerOnly: base.Wine.ControllerOnly,
|
||||
ExcludedPrograms: append([]string(nil), base.Wine.ExcludedPrograms...)}
|
||||
}
|
||||
|
||||
@@ -169,6 +169,9 @@ func (host *quickSettingsHost) categories() []quicksettings.Category {
|
||||
quicksettings.Entry{ID: "speech.language", Label: "Speech-dispatcher language", Kind: quicksettings.Choice, EmptyIsDefault: true},
|
||||
quicksettings.Entry{ID: "speech.voice", Label: "Speech-dispatcher voice", Kind: quicksettings.Choice, EmptyIsDefault: true})
|
||||
}
|
||||
if len(host.settings.VoiceProfiles.Profiles) > 0 {
|
||||
voice = append(voice, quicksettings.Entry{ID: "speech.profile", Label: "Voice profile", Kind: quicksettings.Choice})
|
||||
}
|
||||
reading := []quicksettings.Entry{
|
||||
{ID: "reading.punctuation", Label: "Punctuation level", Kind: quicksettings.Choice},
|
||||
{ID: "reading.indentation", Label: "Indentation", Kind: quicksettings.Choice},
|
||||
@@ -218,6 +221,8 @@ func (host *quickSettingsHost) Value(entry quicksettings.Entry) quicksettings.Va
|
||||
return quicksettings.Value{Number: int(math.Round(*value))}
|
||||
}
|
||||
switch entry.ID {
|
||||
case "speech.profile":
|
||||
return quicksettings.Value{Choice: settings.VoiceProfiles.Matching(config.Primary_voice(settings))}
|
||||
case "speech.rate":
|
||||
return number(settings.DefaultVoice.Rate, 0)
|
||||
case "speech.pitch":
|
||||
@@ -266,6 +271,15 @@ func (host *quickSettingsHost) catalog() bool {
|
||||
|
||||
func (host *quickSettingsHost) Options(entry quicksettings.Entry) []quicksettings.Option {
|
||||
switch entry.ID {
|
||||
case "speech.profile":
|
||||
options := []quicksettings.Option{}
|
||||
if host.settings.VoiceProfiles.Matching(config.Primary_voice(host.settings)) == "" {
|
||||
options = append(options, quicksettings.Option{ID: "", Label: "Custom"})
|
||||
}
|
||||
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":
|
||||
var options []quicksettings.Option
|
||||
if host.hardware() {
|
||||
@@ -396,7 +410,23 @@ func (worker *preferencesWorker) apply_quick_setting(ctx context.Context, host *
|
||||
return worker.handle_extension_quick(ctx, setting, result.Value.Choice)
|
||||
}
|
||||
next := host.settings
|
||||
speechChanged := host.set(&next, result.Entry, result.Value)
|
||||
var speechChanged bool
|
||||
if result.Entry.ID == "speech.profile" {
|
||||
p, ok := next.VoiceProfiles.Find(result.Value.Choice)
|
||||
if !ok {
|
||||
worker.announceSpeechSetting("Choose a saved voice profile")
|
||||
return false
|
||||
}
|
||||
var err error
|
||||
next, err = config.Apply_primary_voice(next, p)
|
||||
if err != nil {
|
||||
worker.announceSpeechSetting("Voice profile was not changed: " + err.Error())
|
||||
return false
|
||||
}
|
||||
speechChanged = true
|
||||
} else {
|
||||
speechChanged = host.set(&next, result.Entry, result.Value)
|
||||
}
|
||||
err := config.Validate(next)
|
||||
if err == nil && speechChanged {
|
||||
err = worker.updateSpeech(ctx, next)
|
||||
@@ -415,6 +445,11 @@ func (worker *preferencesWorker) apply_quick_setting(ctx context.Context, host *
|
||||
if worker.quickSpeech.adjusted == nil {
|
||||
worker.quickSpeech.adjusted = make(map[string]bool)
|
||||
}
|
||||
if result.Entry.ID == "speech.profile" {
|
||||
for _, id := range []string{"speech.rate", "speech.pitch", "speech.volume", "speech.module", "speech.language", "speech.voice"} {
|
||||
delete(worker.quickSpeech.adjusted, id)
|
||||
}
|
||||
}
|
||||
worker.quickSpeech.settings = next
|
||||
worker.quickSpeech.adjusted[result.Entry.ID] = true
|
||||
change := quickSpeechSettings{settings: next, adjusted: map[string]bool{result.Entry.ID: true}}
|
||||
@@ -447,6 +482,14 @@ func (quick quickSpeechSettings) apply(settings config.Settings) config.Settings
|
||||
entry.Kind = quicksettings.Toggle
|
||||
}
|
||||
value := host.Value(entry)
|
||||
if id == "speech.profile" {
|
||||
settings.SpeechServerFactory = quick.settings.SpeechServerFactory
|
||||
settings.SpeechOutputModule = quick.settings.SpeechOutputModule
|
||||
settings.HardwareSpeechDevice = quick.settings.HardwareSpeechDevice
|
||||
settings.HardwareSpeechBaudRate = quick.settings.HardwareSpeechBaudRate
|
||||
settings.DefaultVoice = quick.settings.DefaultVoice
|
||||
continue
|
||||
}
|
||||
if id == "speech.module" || id == "speech.language" || id == "speech.voice" {
|
||||
// A voice belongs to its synthesizer, and a hardware synthesizer also
|
||||
// needs its transport. Keep this selection valid across app profiles.
|
||||
@@ -468,6 +511,13 @@ func sortedQuickIDs(ids map[string]bool) []string {
|
||||
result = append(result, id)
|
||||
}
|
||||
sort.Strings(result)
|
||||
// Apply the preset before individual adjustments.
|
||||
for index, id := range result {
|
||||
if id == "speech.profile" {
|
||||
result = append([]string{id}, append(result[:index], result[index+1:]...)...)
|
||||
break
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"git.stormux.org/storm/cthulhu/internal/config"
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
"git.stormux.org/storm/cthulhu/internal/speech"
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
"log/slog"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestQuickVoiceProfilesFailurePersistenceAndApplicationInheritance(t *testing.T) {
|
||||
settings := config.DefaultSettings()
|
||||
settings.Path = filepath.Join(t.TempDir(), "settings.toml")
|
||||
settings.VoiceProfiles.Profiles = []voiceprofiles.Profile{{Name: "Reading", Driver: "speech-dispatcher", Rate: 30, Pitch: 5, Volume: 80}, {Name: "Presentation", Driver: "speech-dispatcher", Rate: -10, Pitch: 0, Volume: 100}}
|
||||
var failure error
|
||||
worker := newPreferencesWorker(slog.New(slog.DiscardHandler), settings, settingsUpdateFunc(func(context.Context, speech.Settings) error { return failure }))
|
||||
selectQuickSetting(t, worker, "speech.profile")
|
||||
failure = errors.New("fixture unavailable")
|
||||
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
|
||||
if !reflect.DeepEqual(worker.settings.DefaultVoice, settings.DefaultVoice) {
|
||||
t.Fatal("failed profile changed current voice")
|
||||
}
|
||||
failure = nil
|
||||
for _, name := range []string{"Reading", "Presentation", "Reading"} {
|
||||
worker.handleSpeechCommand(t.Context(), input.IncreaseSpeechSetting)
|
||||
if got := worker.settings.VoiceProfiles.Matching(config.Primary_voice(worker.settings)); got != name {
|
||||
t.Fatal(got, name, worker.settings.DefaultVoice)
|
||||
}
|
||||
}
|
||||
worker.handleSpeechCommand(t.Context(), input.SaveSpeechSettings)
|
||||
loaded, err := config.Load(settings.Path)
|
||||
if err != nil || *loaded.DefaultVoice.Rate != 30 || len(loaded.VoiceProfiles.Profiles) != 2 {
|
||||
t.Fatal(loaded, err)
|
||||
}
|
||||
application := config.DefaultSettings()
|
||||
application = worker.quickSpeech.apply(application)
|
||||
if *application.DefaultVoice.Rate != 30 || *application.DefaultVoice.Gain != 80 {
|
||||
t.Fatal("profile lost across applications")
|
||||
}
|
||||
if !reflect.DeepEqual(application.EchoVoice, settings.EchoVoice) || !reflect.DeepEqual(application.SystemVoice, settings.SystemVoice) {
|
||||
t.Fatal("profile changed auxiliary voices")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user