Preview voice profile edits and restore parent speech
This commit is contained in:
1 parent
1b42dde756
commit
b21fceb311
7 files changed
+175
-11
No files matched your search
@@ -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,7 +108,13 @@ func Run(ctx context.Context, input io.Reader, output io.Writer) error {
|
||||
if response.Preview {
|
||||
previewPending = false
|
||||
if !response.Accepted {
|
||||
status(response.Message, true)
|
||||
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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user