Speech Generation
Available Models
The full list of models can be viewed on the Models page or retrieved dynamically via API endpoints: https://openai.bothub.chat/v1/models and https://bothub.chat/api/v2/replicate/v1/models
BotHub supports speech generation via an OpenAI-compatible API. You can convert text to audio, select a voice, audio file format, and playback speed.
Speech generation uses the Text-to-Speech (TTS) family of models:
tts-1— standard model with low latencytts-1-hd— improved model with higher audio quality
Available Voices
When generating speech, you can choose one of the built-in voices: alloy, echo, fable, onyx, nova, shimmer.
Supported Audio Formats
The API supports audio generation in several formats: mp3, opus, aac, flac.
Main Request Parameters
The following parameters are used when creating audio:
| Parameter | Type | Description |
|---|---|---|
model | string | Speech generation model (tts-1 or tts-1-hd) |
voice | string | Voice for speech synthesis |
input | string | Text to convert to speech |
response_format | string | Output audio format |
speed | number | Playback speed (0.25 – 4.0) |
Speech Generation Example
- JS
- Python
- Go
- cURL
import OpenAI from 'openai';
import fs from 'fs';
const openai = new OpenAI({
apiKey: 'YOUR_BOTHUB_API_KEY',
baseURL: 'https://openai.bothub.chat/v1'
});
async function main() {
const response = await openai.audio.speech.create({
model: 'tts-1-hd',
voice: 'nova',
input: 'Hello! This is an example of speech generation via BotHub.',
response_format: 'mp3',
speed: 0.9
});
const buffer = Buffer.from(await response.arrayBuffer());
await fs.promises.writeFile('output.mp3', buffer);
console.log('Audio file saved successfully.');
}
main();
from pathlib import Path
from openai import OpenAI
client = OpenAI(
api_key='YOUR_BOTHUB_API_KEY',
base_url='https://openai.bothub.chat/v1'
)
speech_file_path = Path(__file__).parent / "output.mp3"
response = client.audio.speech.create(
model='tts-1-hd',
voice='nova',
input='Hello! This is an example of speech generation via BotHub.',
response_format='mp3',
speed=0.9
)
response.stream_to_file(speech_file_path)
print('Audio file saved successfully.')
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("YOUR_BOTHUB_API_KEY"),
option.WithBaseURL("https://openai.bothub.chat/v1"),
)
response, err := client.Audio.Speech.New(context.Background(), openai.AudioSpeechNewParams{
Model: openai.SpeechModel("tts-1-hd"),
Voice: "nova",
Input: "Hello! This is an example of speech generation via BotHub.",
ResponseFormat: openai.AudioSpeechNewParamsResponseFormatMP3,
Speed: openai.Float(0.9),
})
if err != nil {
panic(err)
}
defer response.Body.Close()
file, err := os.Create("output.mp3")
if err != nil {
panic(err)
}
defer file.Close()
if _, err := io.Copy(file, response.Body); err != nil {
panic(err)
}
fmt.Println("Audio file saved successfully.")
}
curl https://openai.bothub.chat/v1/audio/speech \
-H "Authorization: Bearer YOUR_BOTHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1-hd",
"voice": "nova",
"input": "Hello! This is an example of speech generation via BotHub.",
"response_format": "mp3",
"speed": 0.9
}' \
--output output.mp3
Recommendations
Usage Recommendations
- For most scenarios, it is recommended to use
tts-1if generation speed is important. - Use
tts-1-hdif audio quality is the priority. - The
mp3format is suitable for most applications and provides a good balance between quality and file size. - A
speedvalue greater than1.0accelerates playback, while a value below1.0makes the speech slower and smoother.
Official OpenAI Documentation