Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Text-to-Speech API Documentation</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
background-color: #f4f4f4; | |
color: #333; | |
margin: 0; | |
padding: 0; | |
} | |
header { | |
background-color: #4CAF50; | |
color: white; | |
padding: 20px; | |
text-align: center; | |
} | |
h1, h2 { | |
margin: 0; | |
} | |
section { | |
margin: 20px; | |
padding: 20px; | |
background-color: white; | |
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); | |
} | |
pre { | |
background-color: #f4f4f4; | |
padding: 10px; | |
border-radius: 5px; | |
font-family: monospace; | |
overflow-x: auto; | |
} | |
footer { | |
text-align: center; | |
padding: 10px 0; | |
background-color: #4CAF50; | |
color: white; | |
} | |
ul { | |
line-height: 1.6; | |
} | |
</style> | |
</head> | |
<body> | |
<header> | |
<h1>Text-to-Speech (TTS) API Documentation</h1> | |
<p>Convert text into high-quality speech using our API</p> | |
</header> | |
<section> | |
<h2>API Overview</h2> | |
<p>This API allows you to convert text into natural-sounding speech. You can specify the voice and model for the TTS generation. It is ideal for use cases such as games, tutorials, and accessibility applications.</p> | |
</section> | |
<section> | |
<h2>API Endpoint</h2> | |
<p>To generate speech, send a POST request to the following URL:</p> | |
<pre>https://imseldrith-tts-openai-free.hf.space/v1/audio/speech</pre> | |
</section> | |
<section> | |
<h2>Request Example</h2> | |
<p>Here’s an example of the JSON payload you’ll need to send in your POST request:</p> | |
<pre> | |
{ | |
"model": "tts-1", | |
"input": "Today is a wonderful day to build something people love!", | |
"voice": "echo" | |
} | |
</pre> | |
</section> | |
<section> | |
<h2>Voice Options</h2> | |
<p>Choose from the following voices for speech synthesis:</p> | |
<ul> | |
<li><strong>alloy</strong>: A deep and rich voice.</li> | |
<li><strong>echo</strong>: A soft, echoing voice.</li> | |
<li><strong>fable</strong>: A calm, neutral voice.</li> | |
<li><strong>onyx</strong>: A slightly robotic, futuristic voice.</li> | |
<li><strong>nova</strong>: A bright and clear voice.</li> | |
<li><strong>shimmer</strong>: A soft, dreamy voice.</li> | |
</ul> | |
</section> | |
<section> | |
<h2>Audio Quality Options</h2> | |
<p>You can choose between two models based on the quality of the audio and latency requirements:</p> | |
<ul> | |
<li><strong>tts-1</strong>: The standard model that provides low latency but may have some static or lower quality in certain situations. Ideal for real-time applications.</li> | |
<li><strong>tts-1-hd</strong>: A high-definition model that produces better quality audio at the cost of higher latency. Recommended for non-realtime applications where quality is a priority.</li> | |
</ul> | |
</section> | |
<section> | |
<h2>How to Use the API</h2> | |
<p>Use the following code examples to make requests to the API. You can copy and modify the code as needed.</p> | |
<h3>Python Code Example</h3> | |
<p>This Python example demonstrates how to send a POST request to the API and save the generated speech as an MP3 file:</p> | |
<pre> | |
import requests | |
# API URL and Headers | |
url = "https://imseldrith-tts-openai-free.hf.space/v1/audio/speech" | |
headers = { | |
"Content-Type": "application/json" | |
} | |
# Payload with input text and desired voice | |
data = { | |
"model": "tts-1", # Use "tts-1-hd" for higher quality audio | |
"input": "Today is a wonderful day to build something people love!", | |
"voice": "echo" # Choose a voice (e.g., "alloy", "echo", "fable", etc.) | |
} | |
# Make the POST request | |
response = requests.post(url, headers=headers, json=data) | |
# Save the response content to an MP3 file if the request is successful | |
if response.status_code == 200: | |
with open("speech.mp3", "wb") as f: | |
f.write(response.content) | |
print("Speech file saved as 'speech.mp3'") | |
else: | |
print(f"Failed to generate speech: {response.status_code}, {response.text}") | |
</pre> | |
<h3>cURL Command Example</h3> | |
<p>If you prefer using cURL, you can make the request like this:</p> | |
<pre> | |
curl -X POST https://imseldrith-tts-openai-free.hf.space/v1/audio/speech \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"model": "tts-1", | |
"input": "Today is a wonderful day to build something people love!", | |
"voice": "echo" | |
}' --output speech.mp3 | |
</pre> | |
<h3>JavaScript (Fetch) Example</h3> | |
<p>Here’s how you can make a POST request to the TTS API using JavaScript (for example, in a web application):</p> | |
<pre> | |
fetch("https://imseldrith-tts-openai-free.hf.space/v1/audio/speech", { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json" | |
}, | |
body: JSON.stringify({ | |
model: "tts-1", // Use "tts-1-hd" for higher quality audio | |
input: "Today is a wonderful day to build something people love!", | |
voice: "echo" // Choose a voice (e.g., "alloy", "echo", "fable", etc.) | |
}) | |
}) | |
.then(response => response.blob()) | |
.then(blob => { | |
const link = document.createElement("a"); | |
link.href = URL.createObjectURL(blob); | |
link.download = "speech.mp3"; | |
link.click(); | |
}) | |
.catch(error => console.error("Error:", error)); | |
</pre> | |
</section> | |
<footer> | |
<p></p> | |
</footer> | |
</body> | |
</html> | |