uppercut-tts-worker
A text-to-speech model is slow to load and takes the whole GPU, so narration tools start it once as a worker process and send it one sentence at a time. This package is the shared part: the line protocol between the tool and the worker, a lock file that lets only one GPU job run on a machine and queues the others, a job runner that resumes where it stopped, and the worker-side loop for writing a worker. No voice, voice sample, model name or weights are in it: those belong to whoever runs the worker. Standard library only.
pip install uppercut-tts-worker
The protocol
One JSON object per line in each direction, over the worker's standard input and output.
worker -> {"ready": true, "device": "cuda:0", "dtype": "float32"} once, when the model is loaded
tool -> {"text": "...", "output_path": "a.wav", "seed": 12, "settings": {...}, "voice_id": "v1"}
worker -> {"ok": true, "sample_rate": 24000, "samples": 48000, "wall_s": 1.2}
worker -> {"ok": false, "error": "RuntimeError: ..."} for a sentence it could not say
voice_id is sent only when there is one. Lines that are not JSON objects, such as a library's log output, are skipped by the reader.
Write a worker
from uppercut_tts_worker import serve
def synthesize(request):
audio = my_model.say(request["text"], seed=request["seed"], **request["settings"])
audio.write_wav(request["output_path"])
return {"sample_rate": audio.rate, "samples": len(audio)}
serve(synthesize, ready={"device": "cuda:0", "dtype": "float32"})
An exception becomes an ok: false response and the loop goes on with the next sentence.
Use a worker
from uppercut_tts_worker import GpuLock, WorkerProcess, make_request, wav_seconds
with GpuLock("runs/.gpu.lock", wait_s=2700, on_wait=print): # queue behind another GPU job
with WorkerProcess("python", "worker.py", ["--ckpt-dir", "weights"], log_path="worker.log",
env={"HF_HUB_OFFLINE": "1"}) as worker: # starts it and waits for the ready line
reply = worker.request(make_request("Hello there.", "hello.wav", seed=7, settings={"language": "English"}))
if reply["ok"]:
print(wav_seconds("hello.wav"), "seconds")
Run a job file
uppercut-tts-worker job.json (or python -m uppercut_tts_worker job.json, or run_job(job)) generates a list of sentences in one go, on the machine that has the GPU:
{"worker": {"python": "python", "script": "worker.py", "args": ["--ckpt-dir", "weights"], "env": {"HF_HUB_OFFLINE": "1"}},
"lock": "runs/.gpu.lock", "lock_wait_s": 2700,
"out_dir": "tts/job1",
"items": [{"id": "s001", "text": "First sentence.", "seed": 123, "settings": {"language": "English"}, "voice_id": "v1"}]}
Each item is written to out_dir/<id>.wav and recorded in out_dir/results.json with the SHA-256 of its text and its seed. An item whose WAV exists and whose text and seed still match is skipped, so an interrupted job resumes and an edited sentence is generated again. The lock is taken only when something is left to do. The exit code is 1 if any item failed or the job could not run.
API
| Name | What it does |
|---|---|
make_request(text, output_path, *, seed=None, settings=None, voice_id=None) |
A request object |
read_message(stream), write_message(stream, message) |
One protocol line in or out. read_message skips lines that are not JSON objects and returns None at the end |
serve(synthesize, *, ready=None, stdin=None, stdout=None) |
The worker loop |
WorkerProcess(python, script, args=(), *, env=None, log_path=None, cwd=None, raise_priority=False) |
Start a worker (start(), wait_ready(), request(r), close(), or use it as a context manager). Raises WorkerError when it does not become ready or exits mid-request. A reply is waited for without a time limit |
GpuLock(path, *, wait_s=0, poll_s=5, on_wait=None) |
The lock file. Context manager, or acquire() and release(). Raises LockBusy |
process_alive(pid) |
Whether a process is running, on Windows and elsewhere |
wav_seconds(path) |
Length of a WAV of any sample format, float files included |
raise_tree_priority(pid) |
Windows only: raise a process and its children to above normal priority, which stops ssh-started processes from running at low clocks. Returns the ids it changed |
run_job(job, *, log, lock_log), main(argv) |
The job runner and its command |
Notes
- The lock holds the owner's process id. A lock whose owner has exited is removed and taken; a lock held by a live process is waited for and never deleted. Two machines sharing a network folder do not share a lock: process ids mean nothing across machines.
release()removes the file only while it still names this process, so a lock that was taken over is left alone.- The fake worker in the tests (
tests/fake_worker.py) is a complete example of a worker built onserve. - The Windows pieces (
process_aliveandraise_tree_priorityuse the Win32 API) were written from the working scripts they replace but have not been run on Windows by this package's tests.
License
MIT
Metadata
Release files for uppercut-tts-worker 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| uppercut_tts_worker-0.1.0.tar.gz | 14.1 kB | Without provenance | Details for uppercut_tts_worker-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| uppercut_tts_worker-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for uppercut_tts_worker-0.1.0-py3-none-any.whl |
Total release size: 28.6 kB
Release files / uppercut_tts_worker-0.1.0.tar.gz
| Download URL | uppercut_tts_worker-0.1.0.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05b84dc0b74ad78abca9676092810b6654b81870a1405948a46cde4a455aff5e
|
|
BLAKE2b-256 checksum How to use checksums |
68513274d8b2066a4a848e30e6346633c8f702161ce413774001c4b38ca8477f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / uppercut_tts_worker-0.1.0-py3-none-any.whl
| Download URL | uppercut_tts_worker-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81869ec6e85b568cdbf49f536543d14940b2243b9e049e1e3ae01d7c40fb3de2
|
|
BLAKE2b-256 checksum How to use checksums |
55e6e910c2a23d081534de82b6946f2b320b221b572bba212c454b99fc6b0434
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for uppercut-tts-worker 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.