| Crates.io | alltalk |
| lib.rs | alltalk |
| version | 0.1.0 |
| created_at | 2025-10-12 14:01:05.701827+00 |
| updated_at | 2025-10-12 14:01:05.701827+00 |
| description | A client for the AllTalk API |
| homepage | |
| repository | https://github.com/aparo/alltalk-client |
| max_upload_size | |
| id | 1879317 |
| size | 72,945 |
A Rust client library for the AllTalk Text-to-Speech (TTS) API. This library provides a convenient way to interact with AllTalk's TTS services from Rust applications.
Add this to your Cargo.toml:
[dependencies]
alltalk = "0.1.0"
use alltalk::{AllTalkClient, TTSModelOptions, Language};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create client from environment variable ALLTALK_URL
let client = AllTalkClient::from_environment()?;
// Check if service is ready
if !client.is_ready().await? {
println!("AllTalk service is not ready");
return Ok(());
}
// Generate speech
let options = TTSModelOptions {
text_input: "Hello, world! This is a test.".to_string(),
character_voice_gen: "female_01.wav".to_string(),
language: Language::English,
output_file_name: "hello_world".to_string(),
..Default::default()
};
let response = client.generate_tts(&options).await?;
println!("Generated audio: {}", response.output_file_url);
// Download the generated audio file
client.download_file(&response.output_file_url, "./hello_world.wav").await?;
Ok(())
}
ALLTALK_URL: The base URL of your AllTalk server (e.g., http://127.0.0.1:7851)use alltalk::AllTalkClient;
use url::Url;
// From environment variable
let client = AllTalkClient::from_environment()?;
// From explicit URL
let url = Url::parse("http://127.0.0.1:7851")?;
let client = AllTalkClient::from_url(url)?;
// Check if the TTS service is ready
let is_ready = client.is_ready().await?;
// Get list of available voices
let voices = client.get_voices().await?;
// Preview a voice with sample text
let preview_url = client.preview_voice("female_01.wav").await?;
// Get current settings
let settings = client.get_current_settings().await?;
// Switch TTS model
client.switch_model("XTTSv2 Local").await?;
// Toggle DeepSpeed
client.switch_deepspeed(true).await?;
// Toggle Low VRAM mode
client.switch_low_vram_setting(true).await?;
use alltalk::{TTSModelOptions, Language, TextFiltering};
let options = TTSModelOptions {
text_input: "Your text here".to_string(),
character_voice_gen: "voice_file.wav".to_string(),
language: Language::English,
text_filtering: TextFiltering::Standard,
output_file_name: "output".to_string(),
output_file_timestamp: true,
autoplay: false,
autoplay_volume: 0.8,
..Default::default()
};
let response = client.generate_tts(&options).await?;
let options = TTSModelOptions {
text_input: "*This is narrator text* \"This is character speech\"".to_string(),
character_voice_gen: "character_voice.wav".to_string(),
narrator_enabled: true,
narrator_voice_gen: "narrator_voice.wav".to_string(),
text_not_inside: TextNotInside::Character,
language: Language::English,
..Default::default()
};
let response = client.generate_tts(&options).await?;
// Download generated audio file
client.download_file(&response.output_file_url, "./my_audio.wav").await?;
| Language | Code |
|---|---|
| Arabic | ar |
| Chinese (Simplified) | zh-cn |
| Czech | cs |
| Dutch | nl |
| English | en |
| French | fr |
| German | de |
| Hindi | hi |
| Hungarian | hu |
| Italian | it |
| Japanese | ja |
| Korean | ko |
| Polish | pl |
| Portuguese | pt |
| Russian | ru |
| Spanish | es |
| Turkish | tr |
The client supports switching between different TTS models:
/models/trainedmodel/)The library uses the AllTalkError enum for error handling:
use alltalk::AllTalkError;
match client.generate_tts(&options).await {
Ok(response) => println!("Success: {}", response.output_file_url),
Err(AllTalkError::ResponseError(msg)) => eprintln!("API Error: {}", msg),
Err(AllTalkError::ReqwestError(e)) => eprintln!("Network Error: {}", e),
Err(AllTalkError::JsonParserError { json, target }) => {
eprintln!("JSON Parse Error: Failed to parse {} into {}", json, target);
},
Err(e) => eprintln!("Other Error: {}", e),
}
use alltalk::{AllTalkClient, TTSModelOptions, Language, TextFiltering};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AllTalkClient::from_environment()?;
// Check service status
println!("Checking if AllTalk is ready...");
if !client.is_ready().await? {
eprintln!("AllTalk service is not ready");
return Ok(());
}
// List available voices
let voices = client.get_voices().await?;
println!("Available voices: {:?}", voices);
// Preview a voice
if let Some(voice) = voices.first() {
let preview_url = client.preview_voice(voice).await?;
println!("Preview URL: {}", preview_url);
}
// Get current settings
let settings = client.get_current_settings().await?;
println!("Current model: {}", settings.current_model_loaded);
// Generate TTS
let options = TTSModelOptions {
text_input: "Hello! This is a demonstration of the AllTalk TTS service.".to_string(),
character_voice_gen: voices.first().unwrap_or(&"default.wav".to_string()).clone(),
language: Language::English,
text_filtering: TextFiltering::Standard,
output_file_name: "demo".to_string(),
output_file_timestamp: true,
autoplay: false,
autoplay_volume: 0.8,
..Default::default()
};
let response = client.generate_tts(&options).await?;
println!("Generated TTS: {}", response.output_file_url);
// Download the file
client.download_file(&response.output_file_url, "./demo.wav").await?;
println!("Downloaded audio file to ./demo.wav");
Ok(())
}
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Alberto Paro alberto.paro@gmail.com