# Convert Text to Speech (TTS) — OpenAI (ChatGPT)

> Generates audio from the input text. See the documentation

- Key: `openai-convert-text-to-speech`
- Type: Action (Write)
- Version: 0.0.19
- App: OpenAI (ChatGPT) (`openai`) — https://pipedream.com/apps/openai.md
- This page (HTML): https://pipedream.com/apps/openai/actions/convert-text-to-speech
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/openai/actions/convert-text-to-speech/convert-text-to-speech.mjs

## Description

Generates audio from the input text. [See the documentation](https://platform.openai.com/docs/api-reference/audio/createSpeech)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `model` | `string` | Yes | One of the available TTS models. tts-1 is optimized for speed, while tts-1-hd is optimized for quality. |
| `input` | `string` | Yes | The text to generate audio for. The maximum length is 4096 characters. |
| `voice` | `string` | Yes | The voice to use when generating the audio. |
| `responseFormat` | `string` | No | The format to generate audio in. Supported formats are mp3, opus, aac, flac, wav, and pcm. |
| `speed` | `string` | No | The speed of the generated audio. Provide a value from 0.25 to 4.0. |
| `outputFile` | `string` | Yes | The filename of the output audio file that will be written to the /tmp folder, e.g. myFile.mp3 |
| `syncDir` | `dir` | Yes | SyncDir |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "openai",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "openai-convert-text-to-speech",
  arguments: {
    model: "Model",
    input: "Input",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "openai-convert-text-to-speech",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    openai: { authProvisionId: "apn_xxxxxxx" },
    model: "Model",
    input: "Input",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "openai-convert-text-to-speech",
    "configured_props": {
      "openai": { "authProvisionId": "apn_xxxxxxx" },
      "model": "Model",
      "input": "Input"
    }
  }'
```

---

- App: https://pipedream.com/apps/openai.md · All apps: https://pipedream.com/apps
