Attempt to make audio and speech discovery more robust.

This commit is contained in:
Storm Dragon committed 2026-11-03 13:21:50 -05:00
1 parent a27f274099
commit dc945ff392
21 files changed
+1314 -60

No files matched your search

+11 -4
View File
@@ -4,6 +4,7 @@
package speech
import (
"context"
"fmt"
"os"
"sort"
@@ -45,7 +46,7 @@ func Discover(options Options) (Catalog, error) {
if err != nil {
return result, err
}
defer w.conn.Close()
defer w.close()
deadline := time.Now().Add(4 * time.Second)
query := func(command string) ([]string, error) {
if time.Now().After(deadline) {
@@ -176,6 +177,12 @@ func Language_voices(voices []Voice, language string) []Voice {
// Prepare checks membership because SSIP SET may accept unknown synthesis
// names without verifying them. The resulting client has not spoken anything.
func Prepare(driver string, options Options) (Transport, error) {
return Prepare_context(context.Background(), driver, options)
}
// Prepare_context bounds discovery and connection setup together.
func Prepare_context(ctx context.Context, driver string, options Options) (Transport, error) {
options.context = ctx
if err := Validate_selection(options.Module, options.Language, options.Voice); err != nil {
return nil, err
}
@@ -185,7 +192,7 @@ func Prepare(driver string, options Options) (Transport, error) {
}
if d.Voices == nil {
if options.Module == "" && options.Language == "" && options.Voice == "" {
return Open_driver(driver, options)
return Open_driver_context(ctx, driver, options)
}
return nil, fmt.Errorf("speech driver does not support voice discovery")
}
@@ -219,7 +226,7 @@ func Prepare(driver string, options Options) (Transport, error) {
if !languageFound || !voiceFound {
return nil, fmt.Errorf("speech language or voice is unavailable for module %q", options.Module)
}
return Open_driver(driver, options)
return Open_driver_context(ctx, driver, options)
}
// A live change queries only its target, so a slow unrelated module cannot
@@ -232,7 +239,7 @@ func discover_voices(options Options) ([]Voice, error) {
if err != nil {
return nil, err
}
defer w.conn.Close()
defer w.close()
if options.Module != "" {
if _, err = w.command("SET SELF OUTPUT_MODULE " + options.Module); err != nil {
return nil, err