File size: 5,950 Bytes
8ec60ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<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>