n8n Workflow
Intermediate

Text to Speech with OpenAI

Automate text-to-speech conversion using the OpenAI TTS API. This n8n workflow takes text input and generates an MP3 audio file with a chosen voice.

Overview

Generates an MP3 audio file from any text input by making a direct API call to OpenAI's Text-to-Speech service.

🎙️ Description & Use Case

This workflow converts text into high-quality spoken audio using the OpenAI Text-to-Speech (TTS) API. It provides a simple, direct way to generate audio files from any text input.

🔄 How It Works:

  1. Trigger:

    • The workflow is initiated manually by clicking 'Test workflow'. This can be replaced with any other trigger (e.g., a webhook, a new row in a spreadsheet) to automate audio generation.
  2. Configure Input:

    • The Set input text and TTS voice node defines the two key parameters:
      • input_text: The text you want to convert to speech.
      • voice: The desired voice for the output. OpenAI offers several options like alloy, echo, fable, onyx, nova, and shimmer.
  3. Generate Audio:

    • The Send HTTP Request to OpenAI's TTS Endpoint node makes a POST request to the OpenAI API.
    • It sends the input_text, voice, and the desired model (tts-1) to the API endpoint.
    • The API processes the request and returns a binary file, which is the generated MP3 audio.

✅ Real-World Use Cases:

  • Content Accessibility: Automatically create audio versions of articles, blog posts, or documentation to assist visually impaired users.
  • Automated Voiceovers: Generate voiceovers for videos, tutorials, or presentations without needing to record manually.
  • Podcast Production: Convert written scripts into audio segments for podcasts or news briefings.
  • IVR & Customer Service: Create dynamic, natural-sounding audio prompts for automated phone systems.
  • Language Learning Tools: Build applications that provide spoken examples of words and phrases for language learners.

Instructions

Basic steps

  1. Download workflow JSON
  2. Import into n8n
  3. Configure node parameters as needed
  4. Test and enable the workflow

💡 Tips

After importing, verify all connectors and credentials match your environment.

Preview

Workflow Visualization

8 nodes
100%
When clicking "Test workflow"manualTriggerSet input text and TTS voicesetSend HTTP Request to OpenAI's TTS EndpointhttpRequestSticky NotestickyNoteSticky Note1stickyNoteSticky Note2stickyNoteSticky Note3stickyNoteSticky Note4stickyNote

Nodes

1

When clicking "Test workflow"

manualTrigger

v1
2

Set input text and TTS voice

set

v3.2
3

Send HTTP Request to OpenAI's TTS Endpoint

httpRequest

v4.1
4

Sticky Note

stickyNote

v1
5

Sticky Note1

stickyNote

v1
6

Sticky Note2

stickyNote

v1
7

Sticky Note3

stickyNote

v1
8

Sticky Note4

stickyNote

v1

Statistics

Total nodes:8
Disabled nodes:0
Node types:4
Connections:2
View full JSON structure
{
  "nodes": [
    {
      "id": "938fedbd-e34c-40af-af2f-b9c669e1a6e9",
      "name": "When clicking \"Test workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        380,
        380
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "1d59db5d-8fe6-4292-a221-a0d0194c6e0c",
      "name": "Set input text and TTS voice",
      "type": "n8n-nodes-base.set",
      "position": [
        760,
        380
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"input_text\": \"The quick brown fox jumped over the lazy dog.\",\n  \"voice\": \"alloy\"\n}\n"
      },
      "typeVersion": 3.2
    },
    {
      "id": "9d54de1d-59b7-4c1f-9e88-13572da5292c",
      "name": "Send HTTP Request to OpenAI's TTS Endpoint",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1120,
        380
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/audio/speech",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "tts-1"
            },
            {
              "name": "input",
              "value": "={{ $json.input_text }}"
            },
            {
              "name": "voice",
              "value": "={{ $json.voice }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer $OPENAI_API_KEY"
            }
          ]
        },
        "nodeCredentialType": "openAiApi"
      },
      "credentials": {
        "openAiApi": {
          "id": "VokTSv2Eg5m5aDg7",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 4.1
    },
    {
      "id": "1ce72c9c-aa6f-4a18-9d5a-3971686a51ec",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        280,
        256
      ],
      "parameters": {
        "width": 273,
        "height": 339,
        "content": "## Workflow Trigger\nYou can replace this manual trigger with another trigger type as required by your use case."
      },
      "typeVersion": 1
    },
    {
      "id": "eb487535-5f36-465e-aeee-e9ff62373e53",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        257
      ],
      "parameters": {
        "width": 273,
        "height": 335,
        "content": "## Manually Set OpenAI TTS Configuration\n"
      },
      "typeVersion": 1
    },
    {
      "id": "36b380bd-0703-4b60-83cb-c4ad9265864d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1020,
        260
      ],
      "parameters": {
        "width": 302,
        "height": 335,
        "content": "## Send Request to OpenAI TTS API\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ff35ff28-62b5-49c8-a657-795aa916b524",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        620
      ],
      "parameters": {
        "color": 4,
        "width": 273,
        "height": 278,
        "content": "### Configuration Options\n- \"input_text\" is the text you would like to be turned into speech, and can be replaced with a programmatic value for your use case. Bear in mind that the maximum number of tokens per API call is 4,000.\n\n- \"voice\" is the voice used by the TTS model. The default is alloy, other options can be found here: [OpenAI TTS Docs](https://platform.openai.com/docs/guides/text-to-speech)"
      },
      "typeVersion": 1
    },
    {
      "id": "5f7ef80e-b5c8-41df-9411-525fafc2d910",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1020,
        620
      ],
      "parameters": {
        "color": 4,
        "width": 299,
        "height": 278,
        "content": "### Output\nThe output returned by OpenAI's TTS endpoint is a .mp3 audio file (binary).\n\n\n### Credentials\nTo use this workflow, you'll have to configure and provide a valid OpenAI credential.\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Set input text and TTS voice": {
      "main": [
        [
          {
            "node": "Send HTTP Request to OpenAI's TTS Endpoint",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \"Test workflow\"": {
      "main": [
        [
          {
            "node": "Set input text and TTS voice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Actions

Share
Categories:
Tags:
manualtriggersethttprequeststickynote

Technical Specs

Complexity:
Intermediate
Node Count:
8 nodes
Published:11 months ago
Updated:11 days ago

Compatibility

Platform:
N8N Cloud & Self-hosted
Min Version:
N8N v1.0.0+
Supports cloud and self-hosted deployment

License

This workflow template follows MIT license, you can freely use, modify and distribute.

Please comply with relevant third-party service terms when using.

Related Workflows