Skip to content

Add Rust code for https://client.camb.ai/apis/tts documentation  #88

@Adesoji1

Description

@Adesoji1
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
use reqwest::Client;
use serde_json::json;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Define the API endpoint
    let url = "https://client.camb.ai/apis/tts";

    // Define the payload
    let payload = json!({
        "voice_id": 20299,
        "text": "Hello world",
        "language": 40,
        "gender": 1, // Male
        "age": 43,
    });

    // Create the headers
    let mut headers = HeaderMap::new();
    headers.insert(
        HeaderName::from_static("x-api-key"),
        HeaderValue::from_static("xxxxxxx"), // Replace with your API key
    );
    headers.insert(
        HeaderName::from_static("content-type"),
        HeaderValue::from_static("application/json"),
    );

    // Create an HTTP client
    let client = Client::new();

    // Make the POST request
    let response = client
        .post(url)
        .headers(headers) // Attach the headers
        .json(&payload) // Attach the JSON payload
        .send()
        .await?;

    // Handle the response
    if response.status().is_success() {
        let response_text = response.text().await?;
        println!("Response: {}", response_text);
    } else {
        let error_text = response.text().await?;
        eprintln!("Error: {}", error_text);
    }

    Ok(())
}

Screenshot from 2024-11-29 17-03-32
@pieterscholtz @victorchall

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions