Skip to content

Integrations OpenAI

remsky edited this page Feb 2, 2025 · 5 revisions

OpenAI Integration Guide

Using Kokoro as the Model

You can use Kokoro as the model with OpenAI. Here’s how you can integrate it:

  1. Install OpenAI Python Library:

    • If you haven’t already, install the OpenAI Python library:
      pip install openai
  2. Use the OpenAI Client:

    • Here is an example of how to use the OpenAI client to generate speech:
      from openai import OpenAI
      
      client = OpenAI(
          base_url="http://localhost:8880/v1", api_key="not-needed"
      )
      
      with client.audio.speech.with_streaming_response.create(
          model="kokoro",
          voice="af_sky+af_bella",  # Single or multiple voicepack combo
          input="Hello world!"
      ) as response:
          response.stream_to_file("output.mp3")

Clone this wiki locally