API Reference

Text To Speech · WebSocket

WSSwss://stream.shabd.tech/v1/text-to-speech

Connection headers

  • x-api-keystringrequired

    API key for authentication.

Message flow

  • Outgoing Message (↑): The client sends a JSON object with the necessary parameters for speech synthesis.
  • Incoming Message (↓): The server responds with a stream of raw PCM-16 bit audio data in chunks.

Send Message (↑):

Sending Text Message

{  "requestId": "a216e43a-9d81-444c-a9ae-3c1e400fcb02",  "text": "नमस्ते, आपका दिन शुभ हो!",  "language": "hindi",  "gender": "female",  "sampleRate": 8000,  "speed": "normal"}

Initial messageapplication/json

  • requestIdstringrequired

    Unique identifier for the request

  • textstringrequired

    Text content to be converted to speech

  • languagestringrequired

    Language of the text for synthesis

  • genderstringoptional
    Allowed:
    male
    female
    Default:
    male
  • sampleRatenumber or nulloptional

    Audio sample rate for synthesis (e.g., 22050)

  • speedstringoptional
    Allowed:
    slow
    normal
    fast
    Default:
    normal

Server messages

  • 101The server sends back synthesized audio as continuous streams of raw PCM-16 bit audio data.The response consists of 48-byte header containing metadata.Raw PCM-16 bit audio data following the header.

    Receive Message (↓):

    Streaming PCM-16 bit audio data in chunks...

    Field Breakdown

    FieldDescriptionSizeByte Offset
    requestIdUnique ID for the request360 - 35
    status0 (error) or 1 (success)136
    completed0 (in progress) or 1 (finished)137
    sampleRateSampling rate of the audio (e.g., 8, 16, 22, 48)138
    gender0 (female) or 1 (male)139
    contentLengthLength of the audio content (in bytes)440 - 43
    chunkIdID for each audio chunk144
    Audio content begins from byte 48

    Messages

    Message TypeExampleDescription
    Send (↑){ "requestId": "a216e43a-9d81-444c-a9ae-3c1e400fcb02", "text": "नमस्ते, आपका दिन शुभ हो!", "language": "hindi", "gender": "female", "sampleRate": 8000, "speed": "normal" }The client sends parameters for speech synthesis.
    Receive (↓)Continuous stream of raw PCM-16 bit audio data in chunks until byte header completed trueThe server sends back the synthesized audio as PCM-16 bit.