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
5aef0be169
commit
1d49f5021d
17 files changed
+613
-19
No files matched your search
+17
-12
@@ -28,6 +28,7 @@ import (
|
||||
"git.stormux.org/storm/fenrir/internal/punctuation"
|
||||
"git.stormux.org/storm/fenrir/internal/sound"
|
||||
"git.stormux.org/storm/fenrir/internal/speech"
|
||||
"git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -53,18 +54,19 @@ type InternalUI struct {
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
Version int `toml:"version"`
|
||||
Presentation Presentation `toml:"presentation" label:"Presentation"`
|
||||
Keyboard Keyboard `toml:"keyboard" label:"Keyboard"`
|
||||
Reading Reading `toml:"reading" label:"Reading"`
|
||||
InternalUI InternalUI `toml:"internal_ui" label:"Internal UI"`
|
||||
Review Review `toml:"review"`
|
||||
Screen Screen `toml:"screen"`
|
||||
Clipboard Clipboard `toml:"clipboard" label:"Clipboard"`
|
||||
General General `toml:"general"`
|
||||
Scripts Scripts `toml:"scripts"`
|
||||
Remote Remote `toml:"remote"`
|
||||
Prompt Prompt `toml:"prompt"`
|
||||
VoiceProfiles voiceprofiles.Collection `toml:"voice_profiles"`
|
||||
Version int `toml:"version"`
|
||||
Presentation Presentation `toml:"presentation" label:"Presentation"`
|
||||
Keyboard Keyboard `toml:"keyboard" label:"Keyboard"`
|
||||
Reading Reading `toml:"reading" label:"Reading"`
|
||||
InternalUI InternalUI `toml:"internal_ui" label:"Internal UI"`
|
||||
Review Review `toml:"review"`
|
||||
Screen Screen `toml:"screen"`
|
||||
Clipboard Clipboard `toml:"clipboard" label:"Clipboard"`
|
||||
General General `toml:"general"`
|
||||
Scripts Scripts `toml:"scripts"`
|
||||
Remote Remote `toml:"remote"`
|
||||
Prompt Prompt `toml:"prompt"`
|
||||
}
|
||||
|
||||
// Screen policy is file-only; VT numbers apply only to the console backend.
|
||||
@@ -174,6 +176,9 @@ func Defaults() Settings {
|
||||
}
|
||||
|
||||
func (s Settings) Validate() error {
|
||||
if err := s.VoiceProfiles.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := sound.Validate_selection(s.Presentation.Sound.Driver, s.Presentation.Sound.Device); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -168,6 +168,19 @@ func (d *Document) Save(settings Settings) error {
|
||||
var encode func([]Section) error
|
||||
encode = func(sections []Section) error {
|
||||
for _, section := range Ordered_sections(sections, d.Order) {
|
||||
if section.ID == "voice_profiles" {
|
||||
if len(settings.VoiceProfiles.Profiles) == 0 {
|
||||
continue
|
||||
}
|
||||
// Qualify array tables; an unqualified [[profiles]] escapes the section.
|
||||
encoded, err := toml.Marshal(map[string]any{"voice_profiles": settings.VoiceProfiles})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
output.Write(encoded)
|
||||
continue
|
||||
}
|
||||
|
||||
value := setting_value(reflect.ValueOf(settings), section.ID)
|
||||
fields := make(map[string]any)
|
||||
for index := range value.NumField() {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package config
|
||||
|
||||
import "git.stormux.org/storm/screenreader-common/voiceprofiles"
|
||||
|
||||
func Primary_voice(settings Settings) voiceprofiles.Profile {
|
||||
s := settings.Presentation.Speech
|
||||
p := voiceprofiles.Profile{Driver: s.Driver, Module: s.Module, Language: s.Language, Voice: s.Voice, Rate: s.Rate, Pitch: s.Pitch, Volume: s.Volume}
|
||||
if s.Driver != "speech-dispatcher" {
|
||||
p.Module = ""
|
||||
p.Language = ""
|
||||
p.Voice = ""
|
||||
p.Device = s.HardwareDevice
|
||||
p.BaudRate = s.HardwareBaudRate
|
||||
if s.Driver == "dectalk-usb" {
|
||||
p.Device = ""
|
||||
p.BaudRate = 0
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func Apply_primary_voice(settings Settings, p voiceprofiles.Profile) (Settings, error) {
|
||||
if err := p.Normalize().Validate(); err != nil {
|
||||
return settings, err
|
||||
}
|
||||
s := settings.Presentation.Speech
|
||||
s.Driver = p.Driver
|
||||
s.Module = p.Module
|
||||
s.Language = p.Language
|
||||
s.Voice = p.Voice
|
||||
s.Rate = p.Rate
|
||||
s.Pitch = p.Pitch
|
||||
s.Volume = p.Volume
|
||||
if p.Driver != "speech-dispatcher" {
|
||||
s.HardwareDevice = p.Device
|
||||
s.HardwareBaudRate = p.BaudRate
|
||||
}
|
||||
settings.Presentation.Speech = s
|
||||
return settings, settings.Validate()
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// 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 TestVoiceProfilesPersistenceAndPrimaryScope(t *testing.T) {
|
||||
settings := Defaults()
|
||||
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}
|
||||
path := filepath.Join(t.TempDir(), "settings.toml")
|
||||
doc, err := Open_document(path, settings)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = doc.Save(settings); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, _, err := Load(path, nil)
|
||||
if err != nil || !reflect.DeepEqual(loaded.VoiceProfiles, settings.VoiceProfiles) {
|
||||
t.Fatal(loaded.VoiceProfiles, err)
|
||||
}
|
||||
original := loaded
|
||||
loaded, err = Apply_primary_voice(loaded, p)
|
||||
if err != nil || loaded.Presentation.Speech.Voice != "Reader" || loaded.Presentation.Speech.Rate != 30 {
|
||||
t.Fatal(loaded, err)
|
||||
}
|
||||
if !reflect.DeepEqual(loaded.Keyboard, original.Keyboard) || loaded.Reading != original.Reading || loaded.Presentation.Speech.Enabled != original.Presentation.Speech.Enabled {
|
||||
t.Fatal("profile changed unrelated settings")
|
||||
}
|
||||
loaded.VoiceProfiles = loaded.VoiceProfiles.Remove(0)
|
||||
doc, err = Open_document(path, loaded)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = doc.Save(loaded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, _, err = Load(path, nil)
|
||||
if err != nil || len(loaded.VoiceProfiles.Profiles) != 0 {
|
||||
t.Fatal(loaded.VoiceProfiles, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user