Refactor TTS architecture

This commit is contained in:
dwrz
2026-06-13 18:55:16 +00:00
parent 4b629a2bc7
commit c17c48f269
8 changed files with 274 additions and 563 deletions

View File

@@ -11,11 +11,41 @@ import (
"code.chimeric.al/chimerical/odidere/internal/llm"
"code.chimeric.al/chimerical/odidere/internal/stt"
"code.chimeric.al/chimerical/odidere/internal/tool"
"code.chimeric.al/chimerical/odidere/internal/tts"
"gopkg.in/yaml.v3"
)
// TTS holds the configuration for TTS.
type TTS struct {
// URL is the base URL of kokoro-fastapi.
// For example, "http://localhost:8880".
URL string `yaml:"url"`
// Voice is the default voice ID to use (e.g., "af_heart").
Voice string `yaml:"voice"`
// Timeout is the maximum duration for a synthesis request.
// Defaults to 60s if empty.
Timeout string `yaml:"timeout"`
// VoiceMap maps whisper language names to voice IDs.
// Used by SelectVoice to auto-select voices based on detected
// language.
VoiceMap map[string]string `yaml:"voice_map"`
}
func (cfg TTS) Validate() error {
if cfg.URL == "" {
return fmt.Errorf("missing URL")
}
if cfg.Voice == "" {
return fmt.Errorf("missing voice")
}
if cfg.Timeout != "" {
if _, err := time.ParseDuration(cfg.Timeout); err != nil {
return fmt.Errorf("invalid timeout: %w", err)
}
}
return nil
}
// Config holds all application configuration sections.
type Config struct {
// Address is the host:port to listen on.
@@ -36,7 +66,7 @@ type Config struct {
// Tools defines external commands available to the LLM.
Tools []tool.Tool `yaml:"tools"`
// TTS configures the text-to-speech client.
TTS tts.Config `yaml:"tts"`
TTS TTS `yaml:"tts"`
}
// ApplyDefaults sets default values for optional configuration fields.