Text To Speech API#

This service provides the best performing automatic speechification models from a variety of different vendors.

Time to Integrate#

Less than 1 minute

Service Providers#

You can find a list of all service providers here: slashml.TextToSpeech.ServiceProvider

Instructions#

  1. Send a POST request to https://api.slashml.com/text-to-speech/v1/upload/ with the text in the body. Save the id in the response object returned.

  2. Check the status of the speechification by sending a GET request to https://api.slashml.com/speech-to-text/v1/jobs/YOUR-JOB-ID/

Code Blocks#

Convert text to audio#

The body of the request should contain a field text, the value of which shall contain the relevant text that you want to generate an audio file for.

POST https://api.slashml.com/text-to-speech/v1/jobs/

Request#

import requests

url = 'https://api.slashml.com/text-to-speech/v1/jobs/'

payload = {
  "text": "this is my text that I want to convert to an audio file"
  "service_provider": 'google'
}
headers = {
    "Authorization": "Token <YOUR_API_KEY>",
}

response = requests.post(url, headers=headers, data=payload)
print(response.text)

Response (200)#

{
    # keep track of the id for later
    "id": "dbe42f9c-f0ce-4683-af80-e6c250b21460",
    "status": "COMPLETED",

    # url to publicly hosted audio file
    "audio_url": "https://slashml.s3.ca-central-1.amazonaws.com/70c34009-8149-4b47-8a6e-29dcb5bd3d3d.mp3"
}

Response (400)#

{
    "error" : {
        "message" : "something bad happened"
    }
}

Note: The ‘id’ will be used to fetch the status of the job, in the status endpoint.

Check status of job#

The request API is similar to all job submissions. We can make requests to GET the status of the jobs, and eventually the result of the submitted job, i.e. transcription, or speechification.

GET https://api.slashml.com/speech-to-text/v1/jobs/YOUR-JOB-ID/

Request#

import requests

url = 'https://api.slashml.com/speech-to-text/v1/jobs/YOUR-JOB-ID/?service_provider=assembly'

headers = {
  'Authorization': 'Token <YOUR_API_KEY>'
}

response = requests.get(url, headers=headers, data=payload)
print(response.text)

Response (200) - In Progress#

{
    # keep track of the id for later
    "id": "ozfv3zim7-9725-4b54-9b71-f527bc21e5ab",
    # note that the status is now "processing"
    "status": "IN_PROGESS",
    "acoustic_model": "assemblyai_default",
    "language_model": "assemblyai_default",
    "audio_duration": null,
    "audio_url": "https://s3-us-west-2.amazonaws.com/blog.assemblyai.com/audio/8-7-2018-post/7510.mp3",
    "confidence": null,
    "dual_channel": null,
    "text": null,
    "words": null
}

Response (200) - Completed#

{
    "id": "5551722-f677-48a6-9287-39c0aafd9ac1",
    "status": "COMPLETED",
    "acoustic_model": "assemblyai_default",
    "language_model": "assemblyai_default",
    "audio_duration": 12.0960090702948,
    "audio_url": "https://s3-us-west-2.amazonaws.com/blog.assemblyai.com/audio/8-7-2018-post/7510.mp3",
    "confidence": 0.956,
    "dual_channel": null,
    "text": "You know Demons on TV like that and and for people to expose themselves to being rejected on TV or humiliated by fear factor or.",
    "words": [
        {
            "confidence": 1.0,
            "end": 440,
            "start": 0,
            "text": "You"
        },
        ...
        {
            "confidence": 0.96,
            "end": 10060,
            "start": 9600,
            "text": "factor"
        },
        {
            "confidence": 0.97,
            "end": 10260,
            "start": 10080,
            "text": "or."
        }
    ]
}

Response (400) - Error#

{
    "error" : {
        "message" : "something bad happened"
    }
}

Note: The status will go from ‘QUEUED’ to ‘IN_PROGRESS’ to ‘COMPLETED’. If there’s an error processing your input, the status will go to ‘ERROR’ and there will be an ‘ERROR’ key in the response JSON which will contain more information.