> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reverieinc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Text to Speech API

> Reverie’s TTS (Text-to-Speech) is a solution that turns text into lifelike speech, allowing you to create applications that talk in multiple Indic languages and build comprehensive speech-enabled products.



## OpenAPI

````yaml POST /
openapi: 3.0.1
info:
  title: Localization API
  description: An API for translating text content into multiple languages
  version: 1.0.0
servers:
  - url: https://revapi.reverieinc.com
security: []
paths:
  /:
    post:
      parameters:
        - name: Content-Type
          in: header
          required: true
          schema:
            type: string
            enum:
              - application/json
            example: application/json
            description: The format of the data to be posted.
        - name: REV-API-KEY
          in: header
          required: true
          schema:
            type: string
            example: <YOUR API KEY>
            description: >-
              A unique key/token provided by Reverie to identify the user using
              the Localization API.
        - name: REV-APP-ID
          in: header
          required: true
          schema:
            type: string
            example: <YOUR APP-ID>
            description: >-
              The unique account ID to identify the user and the default account
              settings.
        - name: REV-APPNAME
          in: header
          required: true
          schema:
            type: string
            enum:
              - tts
            example: tts
            description: The parameter to identify the API.
        - name: speaker
          in: header
          required: true
          schema:
            type: string
            example: hi_male
            enum:
              - hi_male
              - hi_male_2
              - hi_male_3
              - hi_male_4
              - hi_female
              - hi_female_2
              - hi_female_3
              - bn_male
              - bn_male_2
              - bn_female
              - bn_female_2
              - kn_male
              - kn_male_2
              - kn_female
              - kn_female_2
              - ml_male
              - ml_female
              - ta_male
              - ta_female
              - te_male
              - te_male_2
              - te_female
              - te_female_2
              - gu_male
              - gu_female
              - or_male
              - or_female
              - as_male
              - as_female
              - mr_male
              - mr_male_2
              - mr_male_3
              - mr_female
              - mr_female_2
              - mr_female_3
              - pa_male
              - pa_female
              - en_male
              - en_male_2
              - en_female
              - en_female_2
            description: >-
              The desired language and voice code for synthesizing the audio
              file
      requestBody:
        description: Text content to be generated to speech
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TTSRequest'
        required: true
      responses:
        '200':
          description: TTS response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TTSResponse'
        '400':
          description: no spkr given
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: The error message describing the issue.
                    example: no spkr given
                  description:
                    type: string
                    description: A detailed description of the error.
                    example: Speaker code not entered
                required:
                  - error
                  - description
        '403':
          description: Invalid REV-API-KEY or REV-APP-ID
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: The error message describing the issue.
                    example: Invalid REV-API-KEY or REV-APP-ID
                  description:
                    type: string
                    description: A detailed description of the error.
                    example: Entered Invalid credentials
                required:
                  - error
                  - description
      x-codeSamples:
        - lang: curl
          source: |-
            curl --location --request POST 'https://revapi.reverieinc.com/' \
            --header 'REV-API-KEY: <YOUR API KEY>' \
            --header 'REV-APP-ID: <YOUR APP-ID>' \
            --header 'REV-APPNAME: tts' \
            --header 'speaker: hi_female' \
            --header 'Content-Type: application/json' \
            --data-raw '{
              "text": ["भारत मेरा देश है।", "मेरी कंपनी का नाम रेवेरी लैंग्वेज टेक्नोलॉजीज है।"],
              "speed": 1,
              "pitch": 0,
              "format": "WAV"
            }'
        - lang: javascript
          source: |-
            const ReverieClient = require("reverie-client");

            const reverieClient = new ReverieClient({
              apiKey: "YOUR-API-KEY",
              appId: "YOUR-APP-ID",
            });

            try {
              const audioBlob = await reverieClient.text_to_speech({
                text: text,
                speaker: speaker,
                speed: speed,
                pitch: pitch,
              });

              const audioUrl = URL.createObjectURL(audioBlob);
              console.log("Audio URL is:", audioUrl);
            } catch (error) {
              console.error("Error:", error);
            }
        - lang: python
          source: |-
            from reverie_sdk import ReverieClient

            client = ReverieClient(
                api_key="MY_API_KEY",
                app_id="MY_APP_ID",
            )

            with open("./big_text.txt", encoding="utf-8") as f:
                text = f.read()

            for resp_idx, resp in enumerate(
                client.tts.tts_streaming(
                    text=text,
                    speaker="en_male",
                    max_words_per_chunk=5,
                    fast_sentence_fragment=False,
                )
            ):
                print(f"{resp_idx:08d} {resp.duration:10.3f}")
                resp.save_audio(
                    f".path/to/output/{resp_idx:08d}.wav",
                    create_parents=True,
                    overwrite_existing=True,
                )
        - lang: go
          source: "package main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc sendRequest(payload string, filename string) {\n\turl := \"https://revapi.reverieinc.com/\"\n\n\treq, err := http.NewRequest(\"POST\", url, bytes.NewBuffer([]byte(payload)))\n\tif err != nil {\n\t\tfmt.Println(\"Request creation error:\", err)\n\t\treturn\n\t}\n\n\t// Set Headers\n\treq.Header.Set(\"REV-API-KEY\", \"<YOUR-API-KEY>\")\n\treq.Header.Set(\"REV-APP-ID\", \"<YOUR-APP-ID>\")\n\treq.Header.Set(\"REV-APPNAME\", \"tts\")\n\treq.Header.Set(\"speaker\", \"hi_female\") //Set Speaker\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\n\tclient := &http.Client{}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\tfmt.Println(\"Request error:\", err)\n\t\treturn\n\t}\n\tdefer resp.Body.Close()\n\n\t// Create a file to save the response\n\tfile, err := os.Create(filename)\n\tif err != nil {\n\t\tfmt.Println(\"File creation error:\", err)\n\t\treturn\n\t}\n\tdefer file.Close()\n\n\t// Copy response body to file\n\t_, err = io.Copy(file, resp.Body)\n\tif err != nil {\n\t\tfmt.Println(\"File write error:\", err)\n\t\treturn\n\t}\n\tfmt.Println(\"Audio saved as\", filename)\n}\n\nfunc main() {\n\t// Request 1: Plain text TTS\n\tpayload1 := `{\\n\\t\"text\": [\"भारत मेरा देश है।\", \"मेरी कंपनी का नाम रेवेरी लैंग्वेज टेक्नोलॉजीज है।\"],\\n\\t\"speed\": 1,\\n\\t\"pitch\": 0,\\n\\t\"format\": \"WAV\"\\n}`\nsendRequest(payload1, \"output1.wav\")\n\n\t// Request 2: SSML-based TTS\n\tpayload2 := `{\\n\\t\"ssml\": \"<speak> <voice name=\\\"en_female\\\"> Hello. </voice> </speak>\",\\n\\t\"speed\": 1,\\n\\t\"pitch\": 0,\\n\\t\"format\": \"mp3\"\\n}`\nsendRequest(payload2, \"output2.mp3\")\n}"
components:
  schemas:
    TTSRequest:
      type: object
      properties:
        text:
          type: array
          description: The text you want to process to generate the speech.
          items:
            type: string
        speed:
          type: number
          description: >-
            The speech rate of the audio file. Allows values from 0.5 (slowest
            speed) up to 1.5 (fastest speed).
        pitch:
          type: number
          description: >-
            Speaking pitch, in the range from -3 to 3. 3 indicates an increase
            of 3 semitones; -3 indicates a decrease of 3 semitones.
        sample_rate:
          type: integer
          description: The sampling rate (in hertz) to synthesize the audio output.
        format:
          type: string
          description: The speech audio format to generate the audio file (e.g., WAV, MP3).
      required:
        - text
    TTSResponse:
      type: string
      format: binary
      description: Audio data in MP3 format
      example: Audio Response

````