Skip to content

AllTalk Configuration System Documentation

erew123 edited this page Nov 22, 2024 · 1 revision

Overview

The AllTalk configuration system provides a centralized way to manage application settings through three main configuration classes:

  • AlltalkConfig: Main application configuration
  • AlltalkTTSEnginesConfig: TTS engine settings
  • AlltalkNewEnginesConfig: New/available TTS engines configuration

Basic Usage

Importing and Initializing

from config import AlltalkConfig, AlltalkTTSEnginesConfig, AlltalkNewEnginesConfig

def initialize_configs():
    """Initialize all configuration instances"""
    config = AlltalkConfig.get_instance()
    tts_engines_config = AlltalkTTSEnginesConfig.get_instance()
    new_engines_config = AlltalkNewEnginesConfig.get_instance()
    return config, tts_engines_config, new_engines_config

# Load configurations
config, tts_engines_config, new_engines_config = initialize_configs()

Accessing Configuration Values

All configuration classes use a singleton pattern with get_instance(). Configuration values can be accessed directly as attributes:

# Main config examples
print(config.branding)                    # Access branding string
print(config.gradio_port_number)          # Access port number
print(config.output_folder)               # Access output folder path

# TTS engines config examples
print(tts_engines_config.engine_loaded)   # Currently loaded engine
print(tts_engines_config.selected_model)  # Selected model name

# Accessing nested configuration objects
print(config.rvc_settings.pitch)          # Access RVC settings
print(config.tgwui.tgwui_language)        # Access TGWUI settings
print(config.api_def.api_port_number)     # Access API settings

Modifying and Saving Configuration

Changes to configuration values persist only in memory until explicitly saved:

# Modify configuration values
config.branding = "New Branding"
config.gradio_port_number = 7853
config.rvc_settings.pitch = 1

# Save changes to disk
config.save()  # Saves to default location
config.save("custom_config.json")  # Save to custom location

# Save TTS engine changes
tts_engines_config.engine_loaded = "new_engine"
tts_engines_config.save()

Engine Management

The TTS engines configuration provides methods for managing TTS engines:

# Check available engines
engine_names = tts_engines_config.get_engine_names_available()

# Validate engine names
is_valid = tts_engines_config.is_valid_engine("piper")

# Change active engine
tts_engines_config.change_engine("vits")

Advanced Features

Reloading Configuration

Configurations can be forcefully reloaded from disk:

# Force reload all configs
config = AlltalkConfig.get_instance(force_reload=True)
tts_engines_config = AlltalkTTSEnginesConfig.get_instance(force_reload=True)
new_engines_config = AlltalkNewEnginesConfig.get_instance(force_reload=True)

# Or reload individual instances
config.reload()

Output Directory Management

The main configuration provides helpers for managing output directories:

output_dir = config.get_output_directory()  # Returns Path object

Configuration Paths

Access configuration file paths:

default_path = AlltalkConfig.default_config_path()
current_path = config.get_config_path()

Configuration Sections

RVC Settings

rvc = config.rvc_settings
rvc.rvc_enabled = True
rvc.pitch = 0
rvc.filter_radius = 3
rvc.index_rate = 0.75
etc...

TGWUI Settings

tgwui = config.tgwui
tgwui.tgwui_language = "English"
tgwui.tgwui_pitch_set = 0
tgwui.tgwui_show_text = True
etc...

API Settings

api = config.api_def
api.api_port_number = 7851
api.api_language = "en"
api.api_autoplay = False
etc...

Debug Settings

debug = config.debugging
debug.debug_tts = True
debug.debug_rvc = False
etc...

Gradio Pages Settings

pages = config.gradio_pages
pages.Generate_Help_page = True
pages.TTS_Generator_page = True
etc...

Important Notes

  1. The configuration system automatically creates necessary directories and backup files during saves.

  2. File locking is used to prevent concurrent access issues.

  3. Configuration files are monitored for changes and automatically reloaded after a 5-second interval.

  4. All configuration classes use a singleton pattern - always use get_instance() instead of constructing directly.

  5. The system maintains backup files during saves to prevent data loss.

Best Practices

  1. Always use the get_instance() method to access configurations.
  2. Save changes explicitly using the save() method when modifications are made.
  3. Use the provided helper methods instead of accessing file paths directly.
  4. Check engine validity before changing engines using is_valid_engine().
  5. Use the force_reload parameter sparingly, as the system automatically reloads when needed.
Clone this wiki locally