Run eight text-to-speech workers on one GPU with Chatterbox and Civo Kubernetes

Turn a folder of text into MP3s with one Kubernetes Job. Run eight Chatterbox Turbo workers on a single L40S GPU and clear the batch in parallel.

13 minutes reading time

Written by

Mostafa Ibrahim
Mostafa Ibrahim

Software Engineer at GoCardless

A client sends you 200 scripts and wants the audio ready by morning. You run them through a text-to-speech (TTS) model one at a time. Each file has to finish before the next one starts, leaving the GPU idle between files. With 200 files to process, the workload can easily run through the night.

The usual options are to rent another GPU or use a paid TTS service. Renting another GPU adds cost, while a paid API charges by usage and puts the workflow behind someone else's pricing and limits.

You can get more out of a single GPU instead. An L40S has 48 GB of memory, and Chatterbox Turbo uses only about 4.5 GB per copy. That gives you enough memory to run several copies of the model at the same time and process multiple files in parallel.

In this tutorial, you'll run Chatterbox, an MIT-licensed open source text-to-speech model, as a Kubernetes Job on Civo. The scripts go into an Object Store bucket, the Job processes them in parallel, and the finished MP3s are written back to the same bucket.

What you'll build

You'll set up one Civo Object Store bucket and one Civo Kubernetes cluster with an L40S GPU node, then run a single Job that turns a folder of text into a folder of audio. A Job is a Kubernetes workload that runs a task to completion and then stops, which is exactly what a batch of files needs.

The setup has four parts:

  • Object Store bucket: S3-compatible storage that holds your input text files going in and the finished MP3s coming out, so the whole pipeline stays in one place.
  • Chatterbox worker image: A container that loads the Chatterbox Turbo model and generates audio from a text file.
  • Kubernetes Job: Runs the workers on the L40S GPU node, then exits once every file is done instead of staying up like a normal server.
  • Concurrent workers: Several copies of the model loaded on the same card, each taking a file at a time, so the batch processes in parallel rather than one file after another.

Once everything is running, you drop your text files into the bucket, start the Job, and collect the MP3s from the same bucket when it finishes. You'll also watch the GPU while the Job runs to confirm the workers really are sharing one card.

Prerequisites

Before you begin, make sure your Civo account is ready, and the required tools are installed.

Account

A Civo account with access to Kubernetes, GPU nodes, and Object Store. New accounts get free credit for the first month, which covers this walkthrough.

Local tools

  • Civo CLI for creating the cluster, the GPU node pool, and the Object Store bucket
  • kubectl for talking to the cluster
  • Helm for installing the NVIDIA GPU Operator
  • Docker for building the Chatterbox worker image
  • s3cmd for uploading text files to Object Store and downloading the finished MP3s

You won't need an external inference API or a separate storage service. The one account you'll need outside Civo is a free container registry to hold the worker image; this tutorial uses Docker Hub.

Versions used at the time of writing 

ToolVersion

Civo CLI

v1.5.2

kubectl

v1.34.1

Helm

v4.2.0

Docker

29.0.1

s3cmd

2.4.0

Chatterbox

Project structure

chatterbox-batch/
├── worker/
│ └── worker.py # loads Chatterbox Turbo, pulls files from a queue, writes MP3s
├── Dockerfile # builds the worker image
├── kubernetes/
│ ├── namespace.yaml # namespace for the job's resources
│ └── job.yaml # the batch Job and its settings
└── samples/ # local .txt files you upload to the bucket's input/
├── sample01.txt
├── sample02.txt
└── ...

With your Civo account set up and these tools installed, you're ready to look at how the pieces fit together.

How it fits together

Before building anything, it helps to see how a text file becomes an audio file. The pipeline has four pieces, and each has one job.

Image by author

At the start is the Object Store bucket. It contains an input/ folder for text files and an output/ folder for generated MP3s.

In the middle is the L40S GPU node in the Civo Kubernetes cluster. The NVIDIA GPU Operator installs the driver and device plugin, exposing the GPU as nvidia.com/gpu.

On top runs the Kubernetes Job. It starts one pod, where a coordinator loads multiple Chatterbox Turbo workers.

The workflow works as follows:

  • The bucket stores input text and output audio
  • The GPU Operator exposes the L40S to Kubernetes
  • The workers pull files from a shared queue
  • Each worker generates audio, uploads the MP3, and takes the next file

The workers process files in parallel. When the queue is empty, the pod exits and the Job completes.

Provisioning object store

Use one Object Store bucket for both input text and generated audio. Set it up before creating the cluster so the files are ready when the Job runs.

If you haven’t used the Civo CLI on this machine before, authenticate it first. Get your API key by following Retrieve and Reset Your Civo API Key, then save it and make it the active key.

civo apikey save my-key YOUR_CIVO_API_KEY
civo apikey use my-key

Create the bucket and its credentials in the same region as the cluster:

civo objectstore credential create chatterbox-creds --region=NYC1
civo objectstore create chatterbox-tts --size=500 --owner-name=chatterbox-creds --region=NYC1

Object Store is sold in 500 GB blocks, so 500 is the smallest size available. A batch of text files and their audio uses almost none of that, so the cost stays at a few cents.

Fetch the access key for the bucket:

civo objectstore show chatterbox-tts --region=NYC1

Copy the Access Key from the output, then get the matching secret:

civo objectstore credential secret --access-key=YOUR_ACCESS_KEY --region=NYC1

Keep the access key and secret somewhere safe. You'll use them twice: once to configure your local S3 client, and again to create the Kubernetes secret the Job reads from.

Confirm the bucket is ready:

civo objectstore ls --region=NYC1

You should see chatterbox-tts listed with a size of 500GB and a status of ready.

chatterbox-tts, 500GB, ready

Next, point your local S3 client at the bucket so you can upload files. This tutorial uses s3cmd, an S3-compatible command-line client:

s3cmd --configure

Enter the access key and secret, set the region to us-east-1, and use objectstore.nyc1.civo.com for both endpoints. Leave encryption blank, keep HTTPS enabled, and accept the s3cmd connection test.

s3cmd test output

Now set up your project folder and some text to process. Create the working directory, then write a few short sample scripts into samples/:

mkdir -p chatterbox-batch/{worker,kubernetes,samples} && cd chatterbox-batch
texts=(
"Cloud computing lets teams rent servers by the hour instead of buying hardware outright."
"A single graphics card can run several small models at once when there is memory to spare."
"Batch processing handles a whole folder of files in one run rather than one at a time."
"A worker pulls the next file from a shared queue as soon as it finishes the current one."
"Running copies of a model in parallel clears a long queue far faster than a single copy."
)
for i in "${!texts[@]}"; do
n=$(printf '%02d' $((i+1)))
printf '%s\n' "${texts[$i]}" > "samples/sample${n}.txt"
done

The list above holds five sample scripts, enough to see the pipeline work end to end. Any .txt files in samples/ are processed, so add more lines to the list, or drop in your own files, to run a larger batch. This walkthrough uses a batch of 16, so you’ll see fewer files and shorter timings if you keep the five. 

Create input/ for the text files and output/ for the generated audio. S3 uses key prefixes rather than real folders, so create each with a placeholder file:

touch .keep
s3cmd put .keep s3://chatterbox-tts/input/.keep
s3cmd put .keep s3://chatterbox-tts/output/.keep
rm .keep

Upload the text files to input/:

s3cmd put samples/*.txt s3://chatterbox-tts/input/

Verify the files landed:

s3cmd ls s3://chatterbox-tts/input/

Each .txt file should be listed with a non-zero size. If any file shows 0, it's empty; re-check it before moving on, since the worker skips empty files.

Uploaded .txt files

With your text in the bucket and the output/ folder ready, the storage side of the pipeline is done. Next, build the cluster that will process it.

Creating the GPU cluster

Create two node pools: a small CPU node for system workloads and an L40S GPU node for the batch Job. Install the GPU Operator so Kubernetes can use the GPU while system services remain on the CPU node.

Start by creating the cluster with the small CPU node:

civo kubernetes create chatterbox-batch \
--size g4s.kube.small \
--nodes 1 \
--region NYC1 \
--wait

The --wait flag holds the terminal open until the cluster is ready, which takes about 90 seconds. Once it returns, add the L40S GPU node pool:

civo kubernetes node-pool create chatterbox-batch \
--size an.g1.l40s.kube.x1 \
--nodes 1 \
--region NYC1

The GPU node takes a few minutes to join. While it does, save the kubeconfig so kubectl can talk to the cluster:

civo kubernetes config chatterbox-batch --region NYC1 --save

Check that both nodes are ready:

kubectl get nodes

You should see two nodes, the small CPU node and the L40S GPU node. Both must show Ready before moving on.

both nodes in Ready state

Install the NVIDIA GPU Operator so Kubernetes can detect and schedule the GPU. Since Civo already includes the container toolkit, disable it during installation.

Add the NVIDIA Helm repository:

helm repo add nvidia https://helm.ngc.nvidia.com/nvidia
helm repo update

Install the Operator:

helm upgrade --install gpu-operator \
-n gpu-operator --create-namespace \
nvidia/gpu-operator \
--version 25.10.1 \
--set driver.enabled=true \
--set toolkit.enabled=false \
--set devicePlugin.enabled=true \
--set gfd.enabled=true \
--set operator.defaultRuntime=containerd \
--set validator.cuda.runtimeClassName=nvidia

STATUS: deployed confirms the install succeeded. The Operator then starts its pods on the GPU node, beginning with the driver.

Give it a few minutes to settle:

kubectl get pods -n gpu-operator -w

Wait until the driver, device plugin, and validators are all Running or Completed, then press Ctrl+C.

gpu-operator pods all Running/Completed

Finally, confirm the GPU is now schedulable:

kubectl get nodes -o custom-columns="NAME:.metadata.name,GPU:.status.allocatable.nvidia\.com/gpu"

The L40S node should report GPU = 1. You don't split the card into slots here: the single batch pod claims the whole GPU and shares it across its workers internally.

gpu verified

With the GPU visible to Kubernetes, the cluster is ready to run the batch Job, which you'll deploy next.

Building the worker

The Job runs several workers in parallel. Each loads Chatterbox Turbo, pulls files from a shared queue, and uploads the MP3s.

Create worker/worker.py with the imports and environment settings:

import os
import time
import tempfile
import subprocess
import sys
import multiprocessing as mp
import boto3
import torchaudio as ta
from chatterbox.tts_turbo import ChatterboxTurboTTS
BUCKET = os.environ["BUCKET"]
INPUT_PREFIX = os.environ.get("INPUT_PREFIX", "input/")
OUTPUT_PREFIX = os.environ.get("OUTPUT_PREFIX", "output/")
WORKER_COUNT = int(os.environ.get("WORKER_COUNT", "8"))
ENDPOINT = os.environ["S3_ENDPOINT"]
ACCESS_KEY = os.environ["S3_ACCESS_KEY"]
SECRET_KEY = os.environ["S3_SECRET_KEY"]

Next, add the Object Store helper and a function to list .txt files. The Config block disables the boto3 checksum that Civo rejects:

def s3_client():
from botocore.config import Config
return boto3.client(
"s3",
endpoint_url=ENDPOINT,
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
config=Config(
request_checksum_calculation="when_required",
response_checksum_validation="when_required",
),
)
def list_input_files(s3):
keys = []
paginator = s3.get_paginator("list_objects_v2")
for page in paginator.paginate(Bucket=BUCKET, Prefix=INPUT_PREFIX):
for obj in page.get("Contents", []):
if obj["Key"].endswith(".txt"):
keys.append(obj["Key"])
return keys

Each worker loads Chatterbox Turbo once, processes queued files, converts them to MP3, and uploads the results. A None value tells the worker to stop:

def worker(worker_id, queue):
s3 = s3_client()
model = ChatterboxTurboTTS.from_pretrained(device="cuda")
print(f"[worker {worker_id}] model loaded", flush=True)
while True:
key = queue.get()
if key is None:
break
name = os.path.splitext(os.path.basename(key))[0]
text = s3.get_object(Bucket=BUCKET, Key=key)["Body"].read().decode("utf-8").strip()
if not text:
continue
wav = model.generate(text)
if wav.dim() == 1:
wav = wav.unsqueeze(0)
with tempfile.TemporaryDirectory() as d:
wav_path = os.path.join(d, f"{name}.wav")
mp3_path = os.path.join(d, f"{name}.mp3")
ta.save(wav_path, wav.cpu(), model.sr)
subprocess.run(
["ffmpeg", "-y", "-i", wav_path,
"-codec:a", "libmp3lame", "-qscale:a", "2", mp3_path],
check=True, capture_output=True,
)
s3.upload_file(mp3_path, BUCKET, f"{OUTPUT_PREFIX}{name}.mp3")
print(f"[worker {worker_id}] {name}.mp3 done", flush=True)

Finally, add the coordinator. It queues the files, adds one None per worker, starts the worker processes, and waits for them to finish:

def main():
s3 = s3_client()
files = list_input_files(s3)
print(f"found {len(files)} text files, starting {WORKER_COUNT} workers", flush=True)
if not files:
return
queue = mp.Queue()
for k in files:
queue.put(k)
for _ in range(WORKER_COUNT):
queue.put(None)
procs = []
t0 = time.time()
for i in range(WORKER_COUNT):
p = mp.Process(target=worker, args=(i, queue))
p.start()
procs.append(p)
for p in procs:
p.join()
failed = sum(1 for p in procs if p.exitcode != 0)
print(f"batch complete: {len(files)} files in {time.time() - t0:.1f}s", flush=True)
if failed:
print(f"{failed} worker(s) exited with an error", flush=True)
sys.exit(1)
if __name__ == "__main__":
mp.set_start_method("spawn", force=True)
main()

Each worker runs in its own process and shares the GPU. spawn is required for CUDA, while the shared queue keeps workers busy until the batch is done. The exit check at the end matters. If any worker dies, for example by running out of GPU memory, the coordinator exits with an error too, so the Job never reports success with files missing.

Next, package the worker into a container image for Kubernetes.

Packaging the Image

Package worker.py, its Python dependencies, and ffmpeg into a container image, then push it to a registry for the GPU Job.

Create the Dockerfile in the project root:

FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 python3-pip ffmpeg git && rm -rf /var/lib/apt/lists/*
WORKDIR /app
RUN pip3 install --upgrade pip setuptools wheel
RUN git clone https://github.com/resemble-ai/chatterbox.git /opt/chatterbox && \
cd /opt/chatterbox && git checkout 5de7a54 && pip3 install .
RUN pip3 install --force-reinstall torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu121
RUN pip3 install boto3
COPY worker/worker.py .
ENTRYPOINT ["python3", "worker.py"]

The CUDA base image provides GPU support, and apt-get installs Python and ffmpeg. Chatterbox is installed from source for Turbo support, then the tested PyTorch versions are restored. Copying worker.py last makes script-only rebuilds faster.

Building on a Civo VM

The image is several gigabytes because it includes CUDA and PyTorch. To speed up the push, build it on a small Civo VM with a faster data-center connection.

From your local terminal, create the build VM:

civo instance create chatterbox-builder --size g3.large --diskimage ubuntu-jammy --region NYC1 --wait
civo instance show chatterbox-builder --region NYC1

Copy the public IP and the initial password from the output.

In the same terminal on your machine, copy the two files the build needs up to the VM. Do this before you SSH in, since it runs from your machine, not the VM:

scp Dockerfile civo@YOUR_VM_IP:/home/civo/
scp worker/worker.py civo@YOUR_VM_IP:/home/civo/worker.py

Now SSH into the VM. Everything after this runs on the VM:

ssh civo@YOUR_VM_IP

Put the files into the layout the Dockerfile expects, then install Docker and git:

mkdir -p worker && mv worker.py worker/worker.py
sudo apt-get update
sudo apt-get install -y docker.io git
sudo systemctl start docker

Log in to your registry before building. This tutorial uses Docker Hub. You can sign in with your username and password, but a quick way is to use a personal access token. To create one, go to hub.docker.com, open Account Settings, then Personal access tokens, and click Generate new token. Give it a name and grant Read and Write access, then copy the token, which is shown only once.

Log in with your username and paste the token when it asks for a password:

sudo docker login -u YOUR_REGISTRY_USER

Look for Login Succeeded.

docker login showing "Login Succeeded"

Build and push the image:

sudo docker build -t YOUR_REGISTRY_USER/chatterbox-batch:v1 .
sudo docker push YOUR_REGISTRY_USER/chatterbox-batch:v1

If the push fails with insufficient_scope: authorization failed, log in to the registry again and retry. Docker will reuse the layers already uploaded.

docker push completing, layers pushed and final digest line

Once the push finishes, the image is in the registry and ready for the cluster to pull. Next, create the Kubernetes manifests that run it.

Configuring the Kubernetes manifests

Kubernetes needs a namespace, a Job, and a secret for the Object Store credentials.

Start with kubernetes/namespace.yaml:

apiVersion: v1
kind: Namespace
metadata:
name: chatterbox

A namespace groups the pipeline resources so they can be managed together. Apply it:

kubectl apply -f kubernetes/namespace.yaml

Next, the Job. Create kubernetes/job.yaml:

apiVersion: batch/v1
kind: Job
metadata:
name: chatterbox-batch
namespace: chatterbox
spec:
backoffLimit: 2
template:
spec:
hostPID: true
restartPolicy: OnFailure
containers:
- name: worker
image: YOUR_REGISTRY_USER/chatterbox-batch:v1
env:
- name: BUCKET
value: "chatterbox-tts"
- name: INPUT_PREFIX
value: "input/"
- name: OUTPUT_PREFIX
value: "output/"
- name: WORKER_COUNT
value: "8"
- name: S3_ENDPOINT
value: "https://objectstore.nyc1.civo.com"
- name: S3_ACCESS_KEY
valueFrom:
secretKeyRef:
name: objectstore-creds
key: access-key
- name: S3_SECRET_KEY
valueFrom:
secretKeyRef:
name: objectstore-creds
key: secret-key
resources:
limits:
nvidia.com/gpu: 1
volumeMounts:
- name: shm
mountPath: /dev/shm
volumes:
- name: shm
emptyDir:
medium: Memory
sizeLimit: 4Gi

The Job runs the batch on one L40S GPU. WORKER_COUNT sets concurrency; credentials come from a Kubernetes secret, and shm supports worker communication. hostPID: true lets the pod share the node’s process list; without it, nvidia-smi inside the container can’t see the individual worker processes, so the per-worker check later comes back empty. It’s here only for that verification and should be dropped outside a test run, since it gives the pod a view of every process on the node. 

Create the secret first:

kubectl create secret generic objectstore-creds \
-n chatterbox \
--from-literal=access-key=YOUR_ACCESS_KEY \
--from-literal=secret-key=YOUR_SECRET_KEY

The Kubernetes secret keeps credentials out of the manifest, and the Job reads them at runtime through secretKeyRef.

With the namespace, secret, and Job manifest ready, you can run the batch.

Deploying and watching the job run

Everything is in place, so it's time to run the batch. Apply the Job:

kubectl apply -f kubernetes/job.yaml

Kubernetes creates one pod on the GPU node and pulls the image. The first pull can take a few minutes because the image is large.

Watch the pod start:

kubectl get pods -n chatterbox -w

The pod stays in ContainerCreating while the image downloads, then switches to Running. Seeing one pod is expected because all workers run inside it and share the GPU.

kubectl get pods showing the pod in Running state

Once it's running, follow the logs to watch the workers do their job:

kubectl logs -n chatterbox -l job-name=chatterbox-batch -f

Each worker logs when its model loads and when it finishes a file. Files may complete out of order because workers pull from a shared queue. When the queue is empty, the run ends with a summary line:

logs showing workers loading and files completing

While the pod is still Running, open a second terminal and check the GPU directly; this is proof the workers really share one card. Run both the card summary and the per-worker breakdown in one command: 

kubectl exec -n chatterbox job/chatterbox-batch -- bash -c "echo '=== GPU ==='; nvidia-smi --query-gpu=name,memory.used,memory.total,memory.free --format=csv,noheader; echo ''; echo '=== Per-worker processes ==='; nvidia-smi --query-compute-apps=pid,used_gpu_memory --format=csv,noheader"

You’ll see several processes, one per worker, each holding its own slice of memory, all on the same GPU. In this run, eight workers shared one 48 GB L40S, each using about 4 to 4.5 GB while generating, around 33 GB of the card in total. With roughly 12 GB still free, there’s headroom to raise WORKER_COUNT and fit one or two more workers on the same card.

nvidia-smi shows eight worker processes on one L40S

When the batch finishes, the workers stop, the pod exits, and the Job is marked complete. Confirm it:

kubectl get job -n chatterbox

The Job should show 1/1 under COMPLETIONS, meaning it finished successfully.

kubectl get job showing 1/1 completions

If the Job fails or the pod restarts, check the previous logs with kubectl logs -n chatterbox <pod-name> --previous. A worker running out of GPU memory is the usual cause, so lower WORKER_COUNT, delete the Job, and apply it again.

Once the Job finishes, verify the output files and confirm the workers shared the GPU.

Verifying the output

The Job reports success, so confirm the audio actually landed in the bucket.

For a single view of the whole pipeline, list the bucket recursively:

s3cmd ls --recursive s3://chatterbox-tts/

This shows the full before-and-after: the .txt files in input/ and the matching .mp3 files in output/. You should see one non-empty MP3 for every text file.

s3cmd ls --recursive showing input .txt and output .mp3 files together

Download the results into a local folder and play one:

mkdir -p results
s3cmd get --recursive --skip-existing s3://chatterbox-tts/output/ ./results/

Open any file in results/ and confirm the speech matches its text. 

results folder of MP3s, one playing

Every text file came back as spoken audio, generated entirely on your own GPU with no external service. With the output confirmed, that's the full pipeline: text in, audio out, all on one card. 

Clean up

The L40S node, the build VM, and the Object Store bill by the hour until you delete them. Once you’ve downloaded your MP3s, tear everything down.

Delete the cluster, which removes both nodes and stops the GPU billing:

civo kubernetes delete chatterbox-batch --region NYC1 -y

Delete the build VM:

civo instance delete chatterbox-builder --region NYC1 -y

Delete the bucket, then the credential that owns it. Civo only lets you remove a credential once its bucket is gone:

civo objectstore delete chatterbox-tts --region NYC1 -y
civo objectstore credential delete chatterbox-creds --region NYC1 -y

Confirm nothing is left running:

civo kubernetes ls --region NYC1
civo instance ls --region NYC1
civo objectstore ls --region NYC1

None of the chatterbox resources should appear in the lists, and billing stops.

Mostafa Ibrahim
Mostafa Ibrahim

Software Engineer at GoCardless

Mostafa Ibrahim is a software engineer and technical writer specializing in developer-focused content for SaaS and AI platforms. He currently works as a Software Engineer at GoCardless, contributing to production systems and scalable payment infrastructure.

Alongside his engineering work, Mostafa has written more than 200 technical articles reaching over 500,000 readers. His content covers topics including Kubernetes deployments, AI infrastructure, authentication systems, and retrieval-augmented generation (RAG) architectures.

View author profile