AI Dev Kit
API ReferencesDiscordGlitch9
  • Introduction
    • AI DevKit 3.7.0
    • Troubleshooting
    • FAQ
    • Update Logs
  • Provider Setup
    • OpenAI
    • Google Gemini
    • ElevenLabs
    • Ollama
    • OpenRouter
  • Editor Tools
    • Introduction
    • Editor Chat
    • Model Library
    • Voice Library
  • GEN Tasks
    • Introduction - Prefixes
    • Text/Content Generation
      • Structured Outputs (JSON Mode)
    • Chat Session
    • Image Generation
    • Video Generation
    • Sound FX Generation
    • Text to Speech (TTS)
    • Speech to Text (STT)
    • Voice Change
    • Audio Isolation
  • Advanced APIs (Pro)
    • Assistants API
      • How it works
      • Creating custom functions
      • Creating assistants API
    • Realtime API
  • Legacy API
    • OpenAI
      • 💬Chat completions
      • 🖼️Image operations
      • 🗣️Text to speech
      • 🎙️Speech to text
        • Recording real-time in Unity
      • 💾Files
      • 🔎Embeddings
      • 🛡️Moderations
      • ⚙️Fine-tuning
    • Google Gemini
      • 📝System instructions
      • 💬Text generation
      • ⚙️Fine-tuning
      • ▶️Fucntion calling
      • 🔎Embeddings
      • 🛡️Safety
      • 💻Code execution
  • Legacy Documents
    • AI DevKit 1.0 - 2.0
      • AI DevKit 2.0
      • AI DevKit 1.0
      • Preperation
      • Event Handlers
      • Scriptable Toolkits
        • Chat Streamer
        • Image Generator
        • Voice Transcriber
        • Voice Generator
      • Editor Tools
      • Troubleshooting (Legacy)
        • ❗Build Error: The name 'UnityMenu' does not exist in the current context
        • ❗The type or namespace name 'AndroidJavaObject' could not be found
        • ❗The type or namaspace name 'Plastic' does not exist
        • ❗Build Error: The name 'Asset Database' does not exist in the current context
        • ❗'ModelData.Create(Provider, string, UnixTime?, string)': not all code paths return a value
      • Code Generators
        • C# Script Generator
        • Unity Component Generator
      • Generation Menu
      • Editor Chat
      • Editor Vision (TTI, ITI)
      • Editor Speech (TTS)
      • Management Tools
        • Prompt History Viewer
        • AI Model Manager
        • TTS Voice Manager
        • OpenAI File Manager
        • OpenAI Assistant Manager
        • ElevenLabs Voice Library
Powered by GitBook
On this page
  1. Legacy API
  2. OpenAI

Text to speech

PreviousImage operationsNextSpeech to text

Last updated 10 months ago

Text-to-Speech (TTS) is a process where written text is converted into spoken voice output. TTS technologies allow applications to "read" text aloud, providing an auditory version of written materials. This is particularly useful in applications requiring auditory feedback, such as navigational aids, accessibility features for visually impaired users, or interactive voice responses in games and apps.

For a deep dive into the technical details and options available for these requests, refer to the .

Sample Code for Speech Requests:

var request = new SpeechRequest.Builder()
    .SetModel(TTSModel.TTS1)
    .SetVoice(VoiceActor.Alloy)
    .SetInput("The quick brown fox jumped over the lazy dog.")
    .Build();

var result = await request.ExecuteAsync();

AudioClip audioClip = result.AudioOutput;

// Now you can use the audio clip in your project.
// For example:
var audioSource = gameObject.AddComponent<AudioSource>();
audioSource.clip = audioClip;
from pathlib import Path
import openai

speech_file_path = Path(__file__).parent / "speech.mp3"
response = openai.audio.speech.create(
  model="tts-1",
  voice="alloy",
  input="The quick brown fox jumped over the lazy dog."
)
response.stream_to_file(speech_file_path)
🗣️
Speech API Reference