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
@@ -102,6 +102,9 @@ func migrateSpeechScale(document *writableDocument) {
|
||||
}
|
||||
|
||||
func effectiveSettings(document writableDocument) (Settings, error) {
|
||||
if err := document.VoiceProfiles.Validate(); err != nil {
|
||||
return Settings{}, err
|
||||
}
|
||||
if strings.TrimSpace(document.ActiveProfile) == "" {
|
||||
return Settings{}, errors.New("validate configuration: active-profile is empty")
|
||||
}
|
||||
@@ -137,6 +140,7 @@ func effectiveSettings(document writableDocument) (Settings, error) {
|
||||
}
|
||||
settings := DefaultSettings()
|
||||
applyProfile(&settings, profile)
|
||||
settings.VoiceProfiles = document.VoiceProfiles.Clone()
|
||||
settings.ActiveProfile = document.ActiveProfile
|
||||
return settings, nil
|
||||
}
|
||||
@@ -156,6 +160,7 @@ func encodeWritable(settings Settings) ([]byte, error) {
|
||||
if profileName == "" {
|
||||
profileName = document.ActiveProfile
|
||||
}
|
||||
document.VoiceProfiles = settings.VoiceProfiles.Clone()
|
||||
document.ActiveProfile = profileName
|
||||
document.Profiles = map[string]writableProfile{profileName: profileFromSettings(settings)}
|
||||
return encodeDocument(document)
|
||||
|
||||
@@ -19,6 +19,7 @@ package config
|
||||
|
||||
import (
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
)
|
||||
|
||||
const CurrentSchemaVersion = 3
|
||||
@@ -27,6 +28,7 @@ const CurrentSchemaVersion = 3
|
||||
const speechScaleSchemaVersion = 3
|
||||
|
||||
type writableDocument struct {
|
||||
VoiceProfiles voiceprofiles.Collection `toml:"voice-profiles,omitempty"`
|
||||
SchemaVersion int `toml:"schema-version"`
|
||||
ActiveProfile string `toml:"active-profile"`
|
||||
Profiles map[string]writableProfile `toml:"profiles"`
|
||||
|
||||
@@ -19,6 +19,7 @@ package config
|
||||
|
||||
import (
|
||||
"git.stormux.org/storm/cthulhu/internal/input"
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
)
|
||||
|
||||
type VoiceFamily struct {
|
||||
@@ -124,6 +125,7 @@ type WineSettings struct {
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
VoiceProfiles voiceprofiles.Collection
|
||||
Wine WineSettings
|
||||
StructuralNavigationTriggersFocusMode bool
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func cloneSettings(settings Settings) Settings {
|
||||
settings.VoiceProfiles = settings.VoiceProfiles.Clone()
|
||||
settings.Wine.ExcludedPrograms = append([]string(nil), settings.Wine.ExcludedPrograms...)
|
||||
settings.SpeechInterruption.Keys = append([]string(nil), settings.SpeechInterruption.Keys...)
|
||||
settings.KeyBindings = input.CloneBindingOverrides(settings.KeyBindings)
|
||||
|
||||
@@ -167,6 +167,9 @@ func (store *Store) save(settings Settings, application string) error {
|
||||
if application != "" {
|
||||
profile = applicationProfileDifference(global, settings)
|
||||
}
|
||||
if application == "" {
|
||||
document.VoiceProfiles = settings.VoiceProfiles.Clone()
|
||||
}
|
||||
document.Profiles[profileName] = profile
|
||||
contents, err := encodeDocument(document)
|
||||
if err != nil {
|
||||
|
||||
@@ -42,6 +42,9 @@ func ValidWineProgramName(name string) bool {
|
||||
}
|
||||
|
||||
func validate(settings Settings) error {
|
||||
if err := settings.VoiceProfiles.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(settings.Wine.ExcludedPrograms) > 256 {
|
||||
return errors.New("too many Wine hook exclusions")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Primary_voice(settings Settings) voiceprofiles.Profile {
|
||||
p := voiceprofiles.Profile{Driver: "speech-dispatcher", Module: settings.SpeechOutputModule, Volume: 100}
|
||||
number := func(v *float64, fallback int) int {
|
||||
if v != nil {
|
||||
return int(math.Round(*v))
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
p.Rate = number(settings.DefaultVoice.Rate, 0)
|
||||
p.Pitch = number(settings.DefaultVoice.AveragePitch, 0)
|
||||
p.Volume = number(settings.DefaultVoice.Gain, 100)
|
||||
if f := settings.DefaultVoice.Family; f != nil {
|
||||
p.Voice = f.Name
|
||||
p.Language = strings.TrimSuffix(f.Lang+"-"+f.Dialect, "-")
|
||||
p.Variant = f.Variant
|
||||
}
|
||||
if settings.SpeechServerFactory == "hardwarefactory" {
|
||||
p.Driver = settings.SpeechOutputModule
|
||||
p.Module = ""
|
||||
p.Voice = ""
|
||||
p.Language = ""
|
||||
p.Variant = ""
|
||||
p.Device = settings.HardwareSpeechDevice
|
||||
p.BaudRate = settings.HardwareSpeechBaudRate
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func Apply_primary_voice(settings Settings, p voiceprofiles.Profile) (Settings, error) {
|
||||
if err := p.Normalize().Validate(); err != nil {
|
||||
return settings, err
|
||||
}
|
||||
next := settings
|
||||
next.SpeechServerFactory = "speechdispatcherfactory"
|
||||
next.SpeechOutputModule = p.Module
|
||||
voice := Voice{}
|
||||
rate, pitch, volume := float64(p.Rate), float64(p.Pitch), float64(p.Volume)
|
||||
voice.Rate = &rate
|
||||
voice.AveragePitch = &pitch
|
||||
voice.Gain = &volume
|
||||
if p.Driver != "speech-dispatcher" {
|
||||
if p.Driver == "dectalk-usb" {
|
||||
return settings, fmt.Errorf("DECtalk USB is not supported by Cthulhu")
|
||||
}
|
||||
next.SpeechServerFactory = "hardwarefactory"
|
||||
next.SpeechOutputModule = p.Driver
|
||||
next.HardwareSpeechDevice = p.Device
|
||||
next.HardwareSpeechBaudRate = p.BaudRate
|
||||
} else if p.Voice != "" || p.Language != "" {
|
||||
voice.Family = &VoiceFamily{Name: p.Voice, Lang: p.Language, Variant: p.Variant}
|
||||
}
|
||||
next.DefaultVoice = voice
|
||||
if err := Validate(next); err != nil {
|
||||
return settings, err
|
||||
}
|
||||
return next, nil
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
package config
|
||||
|
||||
import (
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVoiceProfilesPersistencePrimaryScopeAndApplicationSave(t *testing.T) {
|
||||
settings := DefaultSettings()
|
||||
settings.Path = filepath.Join(t.TempDir(), "settings.toml")
|
||||
rate := float64(25)
|
||||
settings.EchoVoice = Voice{Rate: &rate, Family: &VoiceFamily{Name: "Echo", Lang: "en"}}
|
||||
settings.SystemVoice = Voice{Rate: &rate}
|
||||
settings.UseCustomEchoVoice = true
|
||||
p := voiceprofiles.Profile{Name: "Reading", Driver: "speech-dispatcher", Module: "fixture", Voice: "Reader", Language: "es", Rate: 30, Pitch: -5, Volume: 80}
|
||||
settings.VoiceProfiles.Profiles = []voiceprofiles.Profile{p}
|
||||
store, err := NewStore(settings.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = store.Save(settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := store.Load()
|
||||
if err != nil || !reflect.DeepEqual(loaded.VoiceProfiles, settings.VoiceProfiles) {
|
||||
t.Fatal(loaded.VoiceProfiles, err)
|
||||
}
|
||||
loaded, err = Apply_primary_voice(loaded, p)
|
||||
if err != nil || loaded.DefaultVoice.Family.Name != "Reader" || *loaded.DefaultVoice.Rate != 30 {
|
||||
t.Fatal(loaded, err)
|
||||
}
|
||||
if !reflect.DeepEqual(loaded.EchoVoice, settings.EchoVoice) || !reflect.DeepEqual(loaded.SystemVoice, settings.SystemVoice) || loaded.UseCustomEchoVoice != settings.UseCustomEchoVoice {
|
||||
t.Fatal("profile changed echo/system voices")
|
||||
}
|
||||
loaded.VoiceProfiles.Profiles[0].Name = "Application must not change catalog"
|
||||
if err = store.SaveForApplication("fixture-application", loaded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
global, err := store.Load()
|
||||
if err != nil || global.VoiceProfiles.Profiles[0].Name != "Reading" {
|
||||
t.Fatal(global.VoiceProfiles, err)
|
||||
}
|
||||
current := store.Current()
|
||||
current.VoiceProfiles.Profiles[0].Name = "Mutated"
|
||||
if store.Current().VoiceProfiles.Profiles[0].Name != "Reading" {
|
||||
t.Fatal("profile list aliased store")
|
||||
}
|
||||
global.VoiceProfiles = global.VoiceProfiles.Remove(0)
|
||||
if err = store.Save(global); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
global, err = store.Load()
|
||||
if err != nil || len(global.VoiceProfiles.Profiles) != 0 {
|
||||
t.Fatal(global.VoiceProfiles, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user