-
-
Notifications
You must be signed in to change notification settings - Fork 247
Open
Description
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(())
}
Metadata
Metadata
Assignees
Labels
No labels
