Skip to content
On this page

Examples

In order to make the API as easy to use as possible, we've provided a few examples in a couple languages.

cURL

Variables

sh
API_KEY="YOUR_API_KEY_HERE"
BASE_URL="https://api.speechify.ai" # production endpoint (not yet available)
BASE_URL="https://api.dev.speechify.ai" # dev endpoint

/tts/v0/get

sh
curl --request POST \
  --url "$BASE_URL/tts/v0" \
  --header "Authorization: ApiKey $API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "ssml": "<speak>Hello, World!</speak>",
    "voice": {
        "engine": "speechify-1",
        "language": "en-US",
        "name": "gwyneth"
    }
}'

/tts/v0/voices

sh
curl --request GET \
  --url "$BASE_URL/tts/v0/voices" \
  --header "Authorization: ApiKey $API_KEY" \

JavaScript

Variables

js
const API_KEY = 'YOUR_API_KEY_HERE'
const BASE_URL = 'https://api.speechify.ai' // production endpoint (not yet available)
const BASE_URL = 'https://api.dev.speechify.ai' // dev endpoint

/tts/v0/get

js
const data = await fetch(`${BASE_URL}/tts/v0/get`, {
  method: 'POST',
  headers: new Headers({
    Authorization: `ApiKey ${API_KEY}`,
  }),
  body: JSON.stringify({
    ssml: '<speak>Hello, World!</speak>',
    voice: {
      engine: 'speechify-1',
      language: 'en-US',
      name: 'gwyneth',
    },
  }),
}).then((response) => response.json())

console.log(data)

/tts/v0/voices

js
const voices = await fetch(`${BASE_URL}/tts/v0/voices`, {
  headers: new Headers({
    Authorization: `ApiKey ${API_KEY}`,
  }),
}).then((response) => response.json())

console.log(voices)

Python

Variables

py
API_KEY = 'YOUR_API_KEY_HERE'
BASE_URL = 'https://api.speechify.ai' # production endpoint (not yet available)
BASE_URL = 'https://api.dev.speechify.ai' # dev endpoint

/tts/v0/get

py
import requests

payload = {
    "ssml": "<speak>Hello, World!</speak>",
    "voice": {
        "engine": "speechify-1",
        "language": "en-US",
        "name": "gwyneth"
    }
}

response = requests.post(f"{BASE_URL}/tts/v0/get", headers={ "Authorization": f"ApiKey {API_KEY}" }, json=payload)
data = response.json()

print(data)

/tts/v0/voices

py
import requests

response = requests.get(f"{BASE_URL}/tts/v0/voices", headers={ "Authorization": f"ApiKey {API_KEY}" })
voices = response.json()

print(voices)