Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Create voice

client.Audio.Voices.New(ctx, body) (*Voice, error)
POST/audio/voices

Creates a voice from a text prompt or from a consent recording and an audio sample.

For prompt-based creation, send type: "prompt" with a name and prompt as JSON or multipart form data. For creation from an audio sample, send type: "audio_sample" with a name, audio_sample, and consent recording ID as multipart form data. The type defaults to audio_sample when omitted.

Returns the saved voice’s metadata. Voices created from text prompts are supported only in Live, not in Realtime or the speech endpoint. The response does not include preview audio.

ParametersExpand Collapse
body AudioVoiceNewParams
AudioSample param.Field[string]

The sample audio recording file. Maximum size is 10 MiB.

Supported MIME types: audio/mpeg, audio/wav, audio/x-wav, audio/ogg, audio/aac, audio/flac, audio/webm, audio/mp4.

Name param.Field[string]

The name of the new voice.

Type param.Field[Consent]Optional

The voice creation method. Defaults to audio_sample when omitted.

ReturnsExpand Collapse
type Voice struct{…}

A custom voice that can be used for audio output. Voices created from text prompts are supported only in Live.

ID string

The voice identifier, which can be referenced in API endpoints.

CreatedAt int64

The Unix timestamp (in seconds) for when the voice was created.

formatunixtime
Name string

The name of the voice.

Object AudioVoice

The object type, which is always audio.voice.

Type VoiceType

How the voice was created. Voices created from text prompts are supported only in Live.

Create voice

package main

import (
  "bytes"
  "context"
  "fmt"
  "io"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/option"
)

func main() {
  client := openai.NewClient(
    option.WithAPIKey("My API Key"),
  )
  voice, err := client.Audio.Voices.New(context.TODO(), openai.AudioVoiceNewParams{
    AudioSample: io.Reader(bytes.NewBuffer([]byte("Example data"))),
    Consent: "consent",
    Name: "x",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", voice.ID)
}
{
  "id": "id",
  "created_at": 0,
  "name": "name",
  "object": "audio.voice",
  "type": "audio_sample"
}
Returns Examples
{
  "id": "id",
  "created_at": 0,
  "name": "name",
  "object": "audio.voice",
  "type": "audio_sample"
}