Skip to content

API ‐ Control and Configuration API

erew123 edited this page Oct 2, 2024 · 2 revisions

This set of endpoints allows you to control various aspects of the AllTalk server, including stopping generation, reloading configurations, switching models, and adjusting performance settings.

1. Stop Generation Endpoint

Interrupt the current TTS generation process, if the currently loaded TTS engine & method supports it. Currently only XTTS Streaming supports this.

  • URL: http://{ipaddress}:{port}/api/stop-generation
  • Method: PUT

Response

{
    "message": "Cancelling current TTS generation"
}

Example Request

curl -X PUT "http://127.0.0.1:7851/api/stop-generation"

Notes

  • This sets tts_stop_generation in the model_engine to True.
  • Stop requests will only be honored if the current TTS engine is capable of handling and can honor a stop request partway through generation.

2. Reload Configuration Endpoint

Reload the TTS engine's configuration and scan for new voices and models.

  • URL: http://{ipaddress}:{port}/api/reload_config
  • Method: GET

Response

Config file reloaded successfully

Example Request

curl -X GET "http://127.0.0.1:7851/api/reload_config"

Notes

  • This ensures that subsequent calls to /api/currentsettings, /api/voices, and /api/rvcvoices return up-to-date information.

3. Reload/Swap Model Endpoint

Load or swap to one of the models presented by /api/currentsettings in the models_available list.

  • URL: http://{ipaddress}:{port}/api/reload
  • Method: POST

Parameters

Parameter Type Description
tts_method string The name of the model to load

Response

{"status": "model-success"}

or

{"status": "model-failure"}

Example Request

curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=xtts%20-%20xttsv2_2.0.2"

4. Switch DeepSpeed Endpoint

Enable or disable DeepSpeed mode, is the currently loaded TTS engine supports it.

  • URL: http://{ipaddress}:{port}/api/deepspeed
  • Method: POST

Parameters

Parameter Type Description
new_deepspeed_value boolean True to enable DeepSpeed, False to disable

Response

{
    "status": "deepspeed-success"
}

Example Request

curl -X POST "http://127.0.0.1:7851/api/deepspeed?new_deepspeed_value=True"

5. Switch Low VRAM Endpoint

Enable or disable Low VRAM mode. Will only benefit TTS Engines that support CUDA.

  • URL: http://{ipaddress}:{port}/api/lowvramsetting
  • Method: POST

Parameters

Parameter Type Description
new_low_vram_value boolean True to enable Low VRAM mode, False to disable

Response

{
    "status": "lowvram-success"
}

Example Request

curl -X POST "http://127.0.0.1:7851/api/lowvramsetting?new_low_vram_value=True"

Usage Tips

  1. Use the Stop Generation endpoint when you need to cancel an ongoing TTS generation process.
  2. The Reload Configuration endpoint is useful after making changes to the AllTalk configuration or adding new voice models.
  3. Use the Reload/Swap Model endpoint to change the active TTS model dynamically.
  4. The DeepSpeed and Low VRAM endpoints allow you to adjust performance settings based on your system's capabilities and current needs.
  5. Always check the response status to ensure your configuration changes were applied successfully.
  6. After making configuration changes, it's a good practice to use the status endpoints (from the AllTalk Server and TTS Engine Status API) to verify the new state of the server.

Code Examples

Python Example

import requests

# Base URL for the API
BASE_URL = "http://127.0.0.1:7851/api"

def stop_generation():
    """Stop the current TTS generation process."""
    response = requests.put(f"{BASE_URL}/stop-generation")
    print(response.json())

def reload_config():
    """Reload the TTS engine's configuration."""
    response = requests.get(f"{BASE_URL}/reload_config")
    print(response.text)

def reload_model(tts_method):
    """Load or swap to a specific TTS model."""
    params = {"tts_method": tts_method}
    response = requests.post(f"{BASE_URL}/reload", params=params)
    print(response.json())

def switch_deepspeed(enable):
    """Enable or disable DeepSpeed mode."""
    params = {"new_deepspeed_value": str(enable).lower()}
    response = requests.post(f"{BASE_URL}/deepspeed", params=params)
    print(response.json())

def switch_low_vram(enable):
    """Enable or disable Low VRAM mode."""
    params = {"new_low_vram_value": str(enable).lower()}
    response = requests.post(f"{BASE_URL}/lowvramsetting", params=params)
    print(response.json())

# Example usage
if __name__ == "__main__":
    stop_generation()
    reload_config()
    reload_model("xtts - xttsv2_2.0.2")
    switch_deepspeed(True)
    switch_low_vram(True)

# Note: Replace the BASE_URL with the correct IP address and port if different from the default
# Error handling can be improved for production use

JavaScript Example

// Base URL for the API
const BASE_URL = "http://127.0.0.1:7851/api";

async function stopGeneration() {
    const response = await fetch(`${BASE_URL}/stop-generation`, { method: 'PUT' });
    console.log(await response.json());
}

async function reloadConfig() {
    const response = await fetch(`${BASE_URL}/reload_config`);
    console.log(await response.text());
}

async function reloadModel(ttsMethod) {
    const params = new URLSearchParams({ tts_method: ttsMethod });
    const response = await fetch(`${BASE_URL}/reload?${params}`, { method: 'POST' });
    console.log(await response.json());
}

async function switchDeepspeed(enable) {
    const params = new URLSearchParams({ new_deepspeed_value: enable });
    const response = await fetch(`${BASE_URL}/deepspeed?${params}`, { method: 'POST' });
    console.log(await response.json());
}

async function switchLowVRAM(enable) {
    const params = new URLSearchParams({ new_low_vram_value: enable });
    const response = await fetch(`${BASE_URL}/lowvramsetting?${params}`, { method: 'POST' });
    console.log(await response.json());
}

// Example usage
async function runExamples() {
    try {
        await stopGeneration();
        await reloadConfig();
        await reloadModel("xtts - xttsv2_2.0.2");
        await switchDeepspeed(true);
        await switchLowVRAM(true);
    } catch (error) {
        console.error("An error occurred:", error);
    }
}

runExamples();

// Note: Replace the BASE_URL with the correct IP address and port if different from the default
// This example uses async/await for better readability, but you can also use .then() chains if preferred
// Error handling can be improved for production use
// For browser usage, ensure CORS is properly configured on the server side
Clone this wiki locally