Automate Voice Generation with a Local API
Musa TTS Team · · 6 min read
Pasting scripts into an app works well for a handful of files. But what about 500 product descriptions? Or a daily news summary? Or a batch of lessons that must be regenerated each time the text changes?
At that point, you need automation. An API lets your own programs ask for audio, with no clicking at all. And a local API does this on your own computer, so you get automation without paying per request or sending your text to anyone else.
This guide explains what a local API is, what you can do with one, and how to get started with the Musa TTS API. You do not need to be an expert. If you can run a simple script, you can follow along.
What is an API, in plain terms?
An API is a way for one program to talk to another. Think of a restaurant. You do not go into the kitchen. You give your order to a waiter, who brings back your food. An API is that waiter.
Your program sends a request, such as "say this text in this voice". The API brings back an audio file.
What makes a local API different?
Most voice APIs live on the internet. You send your text to a company's server and pay per character.
A local API runs on your own computer. Your program sends the request to the same machine it is running on. This gives you some big benefits:
- No per-request cost. Generate as much as you need on a paid plan.
- Privacy. Your text does not leave your computer.
- No rate limits from someone else. The only limit is the speed of your own hardware.
- No dependence on an outside service. It works the same every day.
There are a few trade-offs. The Musa TTS Local API only works while the app is open, and your program must run on the same computer. It listens on 127.0.0.1 only, which keeps it private by default. It is not meant for serving audio to the public from a web server, for example.
What can you automate?
Here are some useful ideas.
- Bulk product audio. Turn a spreadsheet of descriptions into audio files.
- Daily briefings. Generate a news or sales summary each morning.
- Video pipelines. A script writes a video, makes the voiceover, then hands it to your editor.
- Course updates. Regenerate only the lessons that changed.
- Language learning. Make audio for thousands of vocabulary words.
- Apps and games. Generate voice lines for characters during development.
- Automation tools. Connect a voice step to n8n or a similar tool.
Step 1: Turn on the API
The API needs an active license, so this is a paid feature. Then:
- Open Musa TTS and go to Settings.
- Open API Server, and start the server.
- Copy your API key. Each installation has its own.
The server runs on port 7860.
Step 2: Send your first request
If you have curl, a simple command-line tool, you can test your cloned voice like this:
curl -X POST http://127.0.0.1:7860/api/v1/voice-clone \
-H "X-API-Key: YOUR_MUSA_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Hello!", "voice": "My Voice"}' \
--output hello.wav
This sends some text and a saved voice name, and saves the result as hello.wav. Change "My Voice" to the name of a voice in My Voices.
Step 3: Use the OpenAI SDK
Here is the best part. The Musa API is compatible with OpenAI's text to speech API. If you have an app built for OpenAI, you often need to change only one URL.
In Python, it looks like this:
from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:7860/v1",
api_key="YOUR_MUSA_KEY",
)
audio = client.audio.speech.create(
model="tts-1",
voice="Isabella",
input="Generated locally with Musa TTS.",
response_format="wav",
)
Everything else in your app stays the same. It is a quick way to move an existing project to local voices, and stop paying per character.
Step 4: Make a batch
Now let's do something useful. This small Python script reads lines from a text file and creates one audio file for each.
from openai import OpenAI
client = OpenAI(
base_url="http://127.0.0.1:7860/v1",
api_key="YOUR_MUSA_KEY",
)
with open("lines.txt", encoding="utf-8") as f:
lines = [line.strip() for line in f if line.strip()]
for number, line in enumerate(lines, start=1):
audio = client.audio.speech.create(
model="tts-1",
voice="Isabella",
input=line,
response_format="wav",
)
with open(f"line-{number:03}.wav", "wb") as out:
out.write(audio.content)
print("Saved", number, "of", len(lines))
Put your text in lines.txt, with one item per line, and run the script. You will get line-001.wav, line-002.wav and so on. That is hundreds of files, with no clicking.
What else the API can do
The API goes well beyond basic speech.
- Every engine. List your models, load them and generate with any engine you have installed.
- Your voices. Use cloned voices and saved blends.
- Formats. Get WAV, raw PCM or base64 JSON.
- Streaming. Receive audio as it is being made, which helps in interactive apps.
The developer docs cover all of this in full, and there is an OpenAPI spec too.
Connecting to no-code tools
You do not have to write code. Any tool that can send an HTTP request can use the API. In n8n, for example, you can use an HTTP Request node to call the API. A flow might look like this:
- A new row appears in a spreadsheet.
- The text is sent to the Musa API.
- The audio file is saved to a folder.
Remember that the tool must run on the same computer as Musa TTS, and the app must be open.
Tips for reliable automation
- Send one job at a time. Your hardware does the work, so a long queue is safer than many jobs at once.
- Save as you go. Do not keep all your files in memory.
- Check for errors. If a line fails, log it and move on, so you can retry later.
- Use sensible file names. Number them, or use a product ID.
- Keep your key private. Do not put it in public code.
- Match the engine to the job. Lighter engines are quicker for very large batches.
- Listen to a sample. Check a random handful before you trust a whole batch.
The Pronunciation Lexicon is handy for batches, too, since you cannot hand-check each name in thousands of lines.
How fast will it be?
That depends on your hardware and engine. On a mid-range NVIDIA card, Musa Sona 600 made 60 seconds of speech in 9 seconds in our tests. Lighter models run well on a CPU. The free GPU pack helps a lot on Windows with a supported NVIDIA card.
Because it runs on your computer, you can also leave a large batch running overnight, with no bill waiting for you in the morning.
Why developers choose a local API
Cloud APIs are a good fit for many apps. But for repeat tasks and large batches, per-character pricing grows along with your success. With Musa TTS, you pay for the license, and your own computer does the rest. Your text stays private, and your costs stay flat.
Get started
First, download Musa TTS and try the voices with the free version, so that you know how they sound on your computer. When you are ready to automate, the Local API is included in the paid plans. The developer docs have everything you need to write your first script.
Try it on your own computer
Musa TTS has a free plan, so you can test it with your own scripts first.