Consolidate shared UI, hardware transport, and translation tooling

This commit is contained in:
Storm Dragon committed 2026-11-16 20:07:56 -05:00
1 parent ed6951f4cd
commit 2c612de63b
61 files changed
+2417 -1573

No files matched your search

+2 -2
View File
@@ -25,10 +25,10 @@ func DefaultSocketAddress() string {
if uid := os.Getenv("SUDO_UID"); uid != "" {
if parsed, err := strconv.ParseUint(uid, 10, 32); err == nil {
runtimeDirectory := os.Getenv("XDG_RUNTIME_DIR")
if !owned_directory(runtimeDirectory, uint32(parsed)) {
if !ownedDirectory(runtimeDirectory, uint32(parsed)) {
runtimeDirectory = filepath.Join("/run/user", uid)
}
if !owned_directory(runtimeDirectory, uint32(parsed)) {
if !ownedDirectory(runtimeDirectory, uint32(parsed)) {
if account, err := user.LookupId(uid); err == nil {
runtimeDirectory = filepath.Join(account.HomeDir, ".cache")
}
+7 -4
View File
@@ -60,7 +60,10 @@ func ConnectWithAutospawn(ctx context.Context, endpoint Endpoint, dial Dialer, s
return nil, err
}
if spawnErr := spawn(ctx, endpoint); spawnErr != nil {
return nil, fmt.Errorf("%w; autostart Speech Dispatcher: %v", err, spawnErr)
// Wrap only the dial error. Callers classify it as retryable while a
// daemon may still appear; wrapping a failed spawner (fork/exec) would
// make them treat the connection as permanently unavailable.
return nil, fmt.Errorf("%w; autostart Speech Dispatcher: %v", err, spawnErr) //nolint:errorlint // see above
}
retryContext, cancel := context.WithTimeout(ctx, ioTimeout)
defer cancel()
@@ -168,16 +171,16 @@ func ConfigureSudoSpawn(process *exec.Cmd, account *user.User, groups []string)
}
}
runtimeDir := filepath.Join("/run/user", account.Uid)
if candidate := os.Getenv("XDG_RUNTIME_DIR"); owned_directory(candidate, uint32(uid)) {
if candidate := os.Getenv("XDG_RUNTIME_DIR"); ownedDirectory(candidate, uint32(uid)) {
runtimeDir = candidate
}
if owned_directory(runtimeDir, uint32(uid)) {
if ownedDirectory(runtimeDir, uint32(uid)) {
process.Env = append(process.Env, "XDG_RUNTIME_DIR="+runtimeDir)
}
return nil
}
func owned_directory(path string, uid uint32) bool {
func ownedDirectory(path string, uid uint32) bool {
info, err := os.Stat(path)
if err != nil || !info.IsDir() {
return false
+11 -11
View File
@@ -34,7 +34,7 @@ func (client *Client) SpeakFragmentsAndWait(ctx context.Context, fragments []Fra
bytes := 0
for _, part := range fragments {
bytes += len(part.Text)
if bytes > 256*1024 || !valid_fragment(part) {
if bytes > 256*1024 || !validFragment(part) {
return errors.New("invalid speech fragment")
}
}
@@ -57,15 +57,15 @@ func (client *Client) SpeakFragmentsAndWait(ctx context.Context, fragments []Fra
}()
// Query the effective default after initialization: a selected synthesis
// voice may override SET LANGUAGE, and the server default may be unsaved.
defaultLanguage, err := client.fragment_parameter(ctx, "LANGUAGE")
if err != nil || !valid_fragment_language(defaultLanguage, false) {
defaultLanguage, err := client.fragmentParameter(ctx, "LANGUAGE")
if err != nil || !validFragmentLanguage(defaultLanguage, false) {
return errors.Join(ctx.Err(), errors.New("speech default language unavailable"))
}
module, err := client.fragment_parameter(ctx, "OUTPUT_MODULE")
if err != nil || !valid_fragment_language(module, false) {
module, err := client.fragmentParameter(ctx, "OUTPUT_MODULE")
if err != nil || !validFragmentLanguage(module, false) {
return errors.Join(ctx.Err(), errors.New("speech default module unavailable"))
}
voiceType, err := client.fragment_parameter(ctx, "VOICE_TYPE")
voiceType, err := client.fragmentParameter(ctx, "VOICE_TYPE")
if err != nil {
return errors.Join(ctx.Err(), errors.New("speech default voice unavailable"))
}
@@ -119,7 +119,7 @@ func (client *Client) SpeakFragmentsAndWait(ctx context.Context, fragments []Fra
text := strings.ReplaceAll(part.Text, "\r\n", "\n")
text = strings.ReplaceAll(text, "\r", "\n")
text = strings.ReplaceAll(text, "\n", "\r\n")
if err := client.speak_and_wait_locked(ctx, func() error { return client.speak_block(ctx, text) }, nil); err != nil {
if err := client.speakAndWaitLocked(ctx, func() error { return client.speakBlock(ctx, text) }, nil); err != nil {
return err
}
}
@@ -131,7 +131,7 @@ func (client *Client) SpeakFragmentsAndWait(ctx context.Context, fragments []Fra
// These names are fixed by the caller; response values never become commands
// until their bounded token/enum validators have accepted them.
func (client *Client) fragment_parameter(ctx context.Context, name string) (string, error) {
func (client *Client) fragmentParameter(ctx context.Context, name string) (string, error) {
finish, err := prepareIO(ctx, client.conn, client.ioTimeout)
if err != nil {
return "", err
@@ -148,8 +148,8 @@ func (client *Client) fragment_parameter(ctx context.Context, name string) (stri
return response.data[0], nil
}
func valid_fragment(part Fragment) bool {
if part.Text == "" || !utf8.ValidString(part.Text) || !valid_fragment_language(part.Language, true) {
func validFragment(part Fragment) bool {
if part.Text == "" || !utf8.ValidString(part.Text) || !validFragmentLanguage(part.Language, true) {
return false
}
for _, character := range part.Text {
@@ -160,7 +160,7 @@ func valid_fragment(part Fragment) bool {
return true
}
func valid_fragment_language(language string, empty bool) bool {
func validFragmentLanguage(language string, empty bool) bool {
if language == "" {
return empty
}
+2 -2
View File
@@ -19,11 +19,11 @@ func (client *Client) SpeakAndWait(ctx context.Context, text string, began func(
if err := client.ensureConnected(ctx); err != nil {
return err
}
return client.speak_and_wait_locked(ctx, func() error { return client.speak(ctx, text) }, began)
return client.speakAndWaitLocked(ctx, func() error { return client.speak(ctx, text) }, began)
}
// The caller owns the speaking connection until the terminal notification.
func (client *Client) speak_and_wait_locked(ctx context.Context, speak func() error, began func()) (result error) {
func (client *Client) speakAndWaitLocked(ctx context.Context, speak func() error, began func()) (result error) {
if client.conn == nil {
return errors.New("speech client is not connected")
}
+1 -1
View File
@@ -61,7 +61,7 @@ func (client *Client) SpeakText(ctx context.Context, text string) error {
text = strings.ToValidUTF8(strings.ReplaceAll(text, "\x00", ""), "�")
text = strings.ReplaceAll(text, "\r\n", "\n")
text = strings.ReplaceAll(text, "\r", "\n")
return client.speak_block(ctx, strings.ReplaceAll(text, "\n", "\r\n"))
return client.speakBlock(ctx, strings.ReplaceAll(text, "\n", "\r\n"))
}
// Configure applies numeric settings on the current speaking connection and
+2 -2
View File
@@ -385,12 +385,12 @@ func (client *Client) speak(ctx context.Context, text string) (result error) {
if err != nil {
return err
}
return client.speak_block(ctx, text)
return client.speakBlock(ctx, text)
}
// text is validated by the caller. Dot escaping applies to every data line,
// including lines containing what would otherwise be the SSIP terminator.
func (client *Client) speak_block(ctx context.Context, text string) (result error) {
func (client *Client) speakBlock(ctx context.Context, text string) (result error) {
if client.conn == nil {
return errors.New("speech client is not connected")