-
-
Notifications
You must be signed in to change notification settings - Fork 283
API ‐ Best Practices AllTalk API Integration
erew123 edited this page Oct 2, 2024
·
3 revisions
When integrating the AllTalk API into your project, following these best practices will help ensure smooth operation and optimal performance. Code examples for each type of API request can be found on the relevant API help pages.
At a minimum, you need to store the following information:
- IP address
- Port number
Optionally, you may want to store:
- HTTP/HTTPS protocol (if using AllTalk over tunnels)
- Connection timeout value
Example configuration:
{
"api_alltalk_protocol": "http://",
"api_alltalk_ip_port": "127.0.0.1:7851",
"api_connection_timeout": 5
}- Connect to the IP/Port and check the
/api/readyendpoint for a 'Ready' status. - Implement a loop to check for the duration of the connection timeout.
- If the timeout is reached without a response, set voices, models, and other values as "Server Offline" or similar.
If the connection is available:
- Pull current settings:
/api/currentsettings - Pull available voices:
/api/voices - Pull available RVC voices:
/api/rvcvoices
- Present options based on the retrieved information.
- Respect the
xxxxxx_capablesettings from/api/currentsettings. - Disable options in your UI that aren't supported by the current TTS engine.
Implement a refresh button to:
- Make AllTalk update its settings:
/api/reload_config - Pull current settings and voices again
This ensures users can reconnect to the AllTalk server if it's unavailable at startup or if settings have changed.
When sending requests to /api/tts-generate:
- If presenting all variables/options to the user, send all stored interface values.
- If not presenting all options:
- Send all values but hard-code some settings in your outbound request, or
- Only send required values and let AllTalk use default Global API settings for the rest.
Consider saving settings after each successful generation request to ensure valid settings and correct IP address/port.
- Implement proper error handling for API responses.
- Display user-friendly error messages when API calls fail.
- Consider implementing a retry mechanism for temporary failures.
- Cache frequently used data (e.g., available voices) to reduce API calls.
- Implement request throttling to avoid overwhelming the AllTalk server.
- Use streaming TTS generation for real-time applications when appropriate.
- If exposing AllTalk over the internet, use HTTPS and implement proper authentication.
- Validate and sanitize all user inputs before sending them to the API.
- Keep your AllTalk instance and client application up to date with the latest security patches.