Text-to-speech
Generate audio for given content, voice and voice style (optional). Returns generated audio (mp3) file URL and duration in response.
Request
POSThttps://api.fliki.ai/v1/generate/text-to-speech
Headers
{
"Content-type": "application/json",
"Authorization": "Bearer API_KEY"
}
Key | Value | Description |
---|---|---|
Content-Type | application/json | Specifies that the request body format is JSON, allowing the server to parse the data correctly. |
Authorization | Bearer YOUR_API_KEY | Generate your API Key in the account/api. section and replace YOUR_API_KEY with your actual key. |
Body
Body Description
{
"content": String,
"voiceId": String,
"voiceStyleId": String | null,
"sampleRate": 8000 | 24000 | 48000,
"playbackRate": Number,
"format": "mp3" | "wav" | "ogg",
"pronunciations": Array<{ original: String, replace: String }> | undefined
}
Key | Type | Description | Required | Default |
---|---|---|---|---|
content | string | The content to be converted, typically text. Must not exceed the character limit specified. | Yes | N/A |
voiceId | string | The identifier for the voice to be used for the output. | Yes | N/A |
voiceStyleId | string | The identifier for the style of the voice. | - | N/A |
sampleRate | number | The sample rate for the audio. Must be one of 8000, 24000, or 48000. | - | 24000 |
playbackRate | number | The playback rate for the audio. Must be between 0.5 and 3.0. | - | 1.0 |
format | string | The format of the audio file. Must be one of "mp3", "wav", or "ogg". | - | "mp3" |
pronunciations | array | An optional array of objects containing original and replace strings for pronunciation adjustments. | - | N/A |
Obtain voiceId
and voiceStyleId
via the voices endpoint.
Response
{
"audio": String,
"duration": Number
}
Key | Type | Description |
---|---|---|
audio | string | URL of the generated audio file |
duration | number | Total duration of the audio |
Example
- Bash
- TypeScript
- Python
- Go
cURL Request
curl \
-H "Authorization: Bearer <API_KEY>" \
-H "Content-Type: application/json" \
-d '{"content": "...", "voiceId": "...", "voiceStyleId": "..."}' \
-X POST https://api.fliki.ai/v1/generate/text-to-speech
TypeScript Request
const apiKey = '<API_KEY>'; // Replace with your actual API key
const url = 'https://api.fliki.ai/v1/generate/text-to-speech';
const data = {
content: 'Your text content here',
voiceId: '...',
voiceStyleId: '...',
};
async function generateTextToSpeech(apiKey: string) {
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Error: ${response.status} - ${response.statusText}`);
}
const result = await response.json();
console.log(result);
} catch (error) {
console.error('Error generating text-to-speech:', error);
}
}
generateTextToSpeech(apiKey);
Python Request
import requests
api_key = "<API_KEY>"
content = "Your text content here"
voice_id = "..."
voice_style_id = "..."
url = "https://api.fliki.ai/v1/generate/text-to-speech"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
data = {
"content": content,
"voiceId": voice_id,
"voiceStyleId": voice_style_id
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
Go Request
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
apiKey := "<API_KEY>"
content := "Your text content here"
voiceID := "..."
voiceStyleID := "..."
url := "https://api.fliki.ai/v1/generate/text-to-speech"
data := map[string]string{
"content": content,
"voiceId": voiceID,
"voiceStyleId": voiceStyleID,
}
jsonData, _ := json.Marshal(data)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}