Bosphorus

← Knowledge base

Text to speech from Python: a ready-made client

Download a small Python client that turns text into speech with your gateway's own speech model, and listen to a sample it made.

APIText to speechPythonDevelopersChecked against the product on

The gateway turns text into speech. It answers POST /v1/audio/speech, in the same shape as OpenAI’s speech endpoint, with a speech model that runs inside your installation. The model reads Turkish with Turkish pronunciation and English with English pronunciation, and it works out the language from the text itself, so there is nothing to set. This article gives you a small Python client for that endpoint, ready to download. Every command below was run from a clean copy of the download against a live installation on 29 October 2026, and the output quoted is the output it gave.

Before you start: you need access to a Bosphorus installation and a platform key (an API key) on it. If you would like to try it, contact Morten or write to iletisim@morten.com.tr.

Listen to a sample

This recording was made by the client in this article, through a live installation, from the text in its samples/long.txt. It is the file exactly as the platform returned it; nothing was edited.

Download long.wav (3.4 MB, 35 seconds). A Turkish version of the same text, also made by the platform: uzun.wav (3.3 MB, 34 seconds).

Download

Download bosphorus-tts-1.0.0.zip (7 KB)

The archive holds tts.py, the client; requirements.txt, its one library (requests); README.md, a short guide; and samples/, four texts to try: a short English one, a short Turkish one and a long one in each language. The client is for an installation your organisation already runs. It carries no address and no key of its own: you give it both.

Who does what

Step Who Where
Serve a speech model through the gateway Administrator Console, /providers → On-prem
Allow that model for the people who will use it Administrator Console, /keys → Model profiles
Give each developer a platform key Administrator, or each person /keys; or My variables (/vault), see your own key
Download the client, point it at the gateway, make speech Each developer A terminal

How text becomes speech

  1. The client sends the text as JSON, with your platform key as the Bearer.
  2. The gateway checks the key, your model profile, the key’s requests-per-minute limit and your team’s concurrency limit, as described in how a request is checked.
  3. A speech model inside the installation speaks the text and returns an audio file.
  4. The audit trail records the request: who sent it, the text, and the type, size and length of the audio. The audio itself is not stored by the gateway.

Speech spends no tokens, so no token budget is charged and there is no limit on tokens per minute. The text is not scanned by the policy engine.

Part A: the administrator

A1. Serve and allow the model

On the On-prem tab of /providers, a speech server added with Add & check and Type detect is filed as speech: the check asks the server for its list of voices, which only a speech model answers. A model of that type answers only /v1/audio/speech.

A model profile with an empty list allows every model. A profile that lists models allows only those: open Model profiles on /keys, add the model’s id (here OP/voxcpm2) to the profile’s Allowed models and press Save. Prefer the exact id to OP/*, which would also allow every on-premises chat model. The change applies within a minute.

A2. Tell developers the model’s id and voice

A speech model is not listed by /v1/models, because it answers no chat and a chat client must not offer it. So give developers its id and the voice to use. The client uses OP/voxcpm2 and the voice aimo unless BOSPHORUS_TTS_MODEL and BOSPHORUS_TTS_VOICE name others. A voice the server does not have is refused, and the message lists the ones it has:

HTTP 400: Invalid voice 'alloy'. Supported: aimo, default

Part B: the developer

B1. Install

unzip bosphorus-tts-1.0.0.zip
cd bosphorus-tts
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

On Windows, the activation line is .venv\Scripts\activate. The client was tested with Python 3.11 on macOS.

B2. Point it at your gateway

export BOSPHORUS_URL=https://ai.corp.example
export BOSPHORUS_KEY=gpk_...

Replace the address with your gateway’s and gpk_... with your own platform key.

B3. Check it

python tts.py --file samples/merhaba.txt -o merhaba.wav
wrote merhaba.wav (122,924 bytes, wav)

Play merhaba.wav (on macOS: afplay merhaba.wav); it says “Merhaba, bu bir deneme.” The same text and voice always give the same audio, byte for byte, so your file should be 122,924 bytes too. To check the words without listening, read the file back with the speech-to-text client, unzipped next to this one:

python ../bosphorus-speech/speech.py stt merhaba.wav
Merhaba, bu bir deneme.

B4. Choose the format, the voice and the speed

The format comes from the -o file extension, or from --format:

python tts.py --file samples/hello.txt -o hello.mp3
wrote hello.mp3 (22,560 bytes, mp3)
Option What it does
--format wav (48 kHz, 16-bit, mono), mp3, flac, opus (in an Ogg file) or pcm (raw 48 kHz, 16-bit, mono samples with no header). From the extension when omitted: .wav, .mp3, .flac, .opus or .ogg, .pcm or .raw.
--voice A voice your speech server has; the default is aimo.
--speed From 0.25 to 4.0; the default is 1.0. A sentence that took 1.60 seconds took 1.07 at --speed 1.5.
--file Read the text from a UTF-8 file instead of the command line.

All five formats were tested; speech to text read the wav, mp3, flac and opus files back as written.

B5. Long text

One request stops after about 30 seconds of audio, and it gives no warning when it does. So the client sends any text over 400 characters in parts, split at sentence ends, and joins them into one file:

python tts.py --file samples/long.txt -o long.wav
python tts.py --file samples/uzun.txt -o uzun.wav
wrote long.wav (3,363,884 bytes, wav, 3 parts)
wrote uzun.wav (3,317,804 bytes, wav, 2 parts)

The first file is the sample at the top of this page; the second is the one on its Turkish edition. Only wav and pcm can be joined this way. For mp3, flac or opus, keep the text under 400 characters:

the text is 690 characters; over 400, use wav or pcm, or send shorter text

B6. From your own code

synthesize() returns the audio bytes and writes them to a file when you give it a name. It raises SpeechError, with the HTTP status in status, when the gateway refuses:

from tts import synthesize, SpeechError

print(len(synthesize("Yarın sabah toplantı var.", "toplanti.wav")))
try:
    synthesize("Merhaba.", api_key="wrong")
except SpeechError as e:
    print(e.status, e)
138284
401 HTTP 401: invalid api key

It reads BOSPHORUS_URL, BOSPHORUS_KEY, BOSPHORUS_TTS_MODEL and BOSPHORUS_TTS_VOICE unless you pass base_url=, api_key=, model= or voice=.

B7. Without Python

The endpoint takes the same JSON from any HTTP client and answers with the audio file:

curl -sS "$BOSPHORUS_URL/v1/audio/speech" -H "Authorization: Bearer $BOSPHORUS_KEY" -H "Content-Type: application/json" -d '{"model":"OP/voxcpm2","input":"Merhaba, bu bir deneme.","voice":"aimo"}' -o merhaba.wav

That writes the same 122,924-byte merhaba.wav as B3. Add "response_format": "mp3" for another format, or "speed": 1.5. With curl, long text is not split for you: send one paragraph at a time.

Limits

When something goes wrong

You see What to do
set BOSPHORUS_URL to your gateway's address Set BOSPHORUS_URL, as in B2.
HTTP 401: invalid api key Check BOSPHORUS_KEY; the key may have been replaced or revoked.
HTTP 403: model "…" is not allowed by model profile "…" Ask your administrator to allow the model (A1). The message ends with what your profile does allow.
HTTP 400: Invalid voice '…'. Supported: … Use one of the voices the message lists, with --voice or BOSPHORUS_TTS_VOICE.
HTTP 503: no speech model "…" is registered The model id is wrong. Set one of the ids the message ends with as BOSPHORUS_TTS_MODEL.
cannot tell the format from "…" Pass --format, or use one of the extensions in B4.
HTTP 429 Wait for retry-after, then retry.