← Blog
A cream paper strip curls into an orange wave around a dark plum reel on a lavender background.
Published on
2026-11-30

Generate offline narration on CPU with Piper TTS

A single change to a station name should cost you one new take. With Piper TTS, you can turn a lesson into numbered WAV files on a CPU, listen to the affected paragraph, and replace just that clip. Once the software and voice files are on the machine, the narration script reads local files and writes audio locally.

Piper is a neural text-to-speech engine. The voice model determines the language and speaker you hear. For this lesson, choose one voice per language, keep its configuration beside the model, and reuse the loaded voice across all three paragraphs.

Prepare the Piper TTS voice for offline use

Use Python 3.12 for this example. On a connected machine with the same operating system, processor architecture and Python version as the destination, download the installation packages into a folder called wheels. We tested Piper 1.8.0 with ONNX Runtime 1.32.0. If the destination is a Linux VM, prepare the packages on matching Linux.

python -m pip download --only-binary=:all: --dest wheels piper-tts==1.8.0 onnxruntime==1.32.0

The voice needs two matching files. The ONNX model contains the weights, and the adjacent .onnx.json supplies settings including the sample rate and phoneme mapping. Save this as download-en.py and run python download-en.py once from your project folder. It downloads the US English LJ Speech voice, its configuration and its model card from one pinned revision into a new voice-en folder.

from pathlib import Path
from urllib.request import urlretrieve

revision = "7d1912925c997866f80a3948d2122926c87a6058"
voice = "en_US-ljspeech-medium"
folder = "en/en_US/ljspeech/medium"
base = f"https://huggingface.co/rhasspy/piper-voices/resolve/{revision}/{folder}"
out = Path("voice-en")
out.mkdir()
for name in (voice + ".onnx", voice + ".onnx.json", "MODEL_CARD"):
    urlretrieve(f"{base}/{name}", out / name)

Keep the model card with the files. The English voice card describes its training dataset as public domain. The French SIWIS card identifies a different dataset under CC BY 4.0. Check the card and attribution for the voice you choose, especially when distributing recordings or model files. Piper has its own software license.

Copy the wheel folder, the whole voice folder, and your text and Python scripts to the destination. In a fresh virtual environment there, run the following. The installation uses the packages you copied.

python -m pip install --no-index --find-links wheels piper-tts==1.8.0 onnxruntime==1.32.0

Write a script you can record one paragraph at a time

Save these three paragraphs in UTF-8 as lesson-en.txt. A blank line starts a new clip. Keep names and pronunciations you must approve in the opening paragraph so you can audition them before producing a longer lesson.

Maya opens the comma-separated file at eight fifteen. It came from Saint Ives in Cornwall. Each row names a new stop on the route.

Play the first line before you export the rest. Listen for the place name and the time.

Save each section as a separate wave file. If one stop changes, record only that section again.

Our first take used “8:15,” “CSV,” and “St. Ives.” An offline transcription rendered the initials as “CSB.” The revised take used “eight fifteen,” “comma-separated file,” and “Saint Ives in Cornwall.” The transcript recovered the time and file description but still heard “St. Ides.” Listen to that name against a trusted pronunciation before approving the recording. Transcription can flag a suspect word without telling you whether the voice or the recognizer made the mistake.

Render numbered WAV files on CPU

Save this script as narrate.py. It uses the Piper Python API to load the voice once with CUDA disabled. Each paragraph gets a separate WAV. The script requires a new output directory and moves the batch into place after the last clip finishes.

"""Turn blank-line-separated paragraphs into numbered WAVs with one CPU voice."""
from pathlib import Path
from tempfile import TemporaryDirectory
from time import perf_counter
import json
import re
import sys
import wave
from piper import PiperVoice

def narrate(model, script, output):
    paragraphs = re.split(r"\n\s*\n", script.read_text(encoding="utf-8-sig").strip())
    if not paragraphs[0]:
        raise ValueError("The script is empty")
    if output.exists():
        raise FileExistsError(output)
    output.parent.mkdir(parents=True, exist_ok=True)
    start = perf_counter()
    voice = PiperVoice.load(model, use_cuda=False)
    load_time = perf_counter() - start
    clips = []
    with TemporaryDirectory(dir=output.parent) as tmp:
        batch = Path(tmp) / "batch"
        batch.mkdir()
        for number, paragraph in enumerate(paragraphs, 1):
            path = batch / f"{number:02d}.wav"
            start = perf_counter()
            with wave.open(str(path), "wb") as audio:
                voice.synthesize_wav(paragraph, audio)
            elapsed = perf_counter() - start
            with wave.open(str(path), "rb") as audio:
                duration = audio.getnframes() / audio.getframerate()
            clips.append({"file": path.name, "audioSeconds": duration, "renderSeconds": elapsed})
        batch.rename(output)
    return {"providers": voice.session.get_providers(), "loadSeconds": load_time, "clips": clips}

if __name__ == "__main__":
    print(json.dumps(narrate(*(Path(arg) for arg in sys.argv[1:])), indent=2))
python narrate.py voice-en/en_US-ljspeech-medium.onnx lesson-en.txt takes-en

Open takes-en/01.wav and listen for the station name, the time, the pauses and the end of the last word. If the opening paragraph needs another take, save that paragraph in its own text file and render it to a new folder, for example pickup-en-p01. The numbering starts over, so the replacement is pickup-en-p01/01.wav. Keep the original until you hear “Saint Ives” clearly in the replacement and the line matches the script. Once you approve it, replace paragraph one and keep the other two clips from the original batch.

Record the approved WAV’s full path alongside the lesson revision that uses it. Play that assembled cut with its delivery captions and check the subtitle cues against the recording. Replay the changed line and the next cue. If the new take moved later speech, check the affected cues through the end before approving captions for that revision.

Estimate the CPU time for a longer lesson

We ran three batches per voice on a Windows 11 machine with an AMD Ryzen 7 7840HS (8 cores, 16 threads). Each batch started in a fresh Python process. We blocked outbound Python socket connections and confirmed that ONNX Runtime used only its CPU execution provider. Each voice produced three mono, 16-bit PCM WAV files at 22,050 Hz. Removing the matching JSON stopped the job before it created an output batch.

MeasureEnglish (LJ Speech)French (SIWIS)
Recorded lesson, first batch19.55 s17.69 s
Median model load0.89 s0.54 s
Median render time, first paragraph0.40 s0.40 s
Median warm real-time factor0.0360.047

For each run, we divided the combined render time of paragraphs two and three by their combined audio duration. At the measured English factor, a minute of similar speech would take about 2.2 seconds to render once the model is loaded. Downloads, initialization, and listening time are separate. Use a representative passage on your target CPU before committing to a delivery time.

To run a recurring narration job on a CPU instance with Hivenet, transfer the prepared files to the VM, render into a new directory and listen to a sample before exporting.

Your next workload belongs on Hivenet.

Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.