Skip to content
Notifications
Clear all

Guide: Batch convert a folder of text files to speech using their CLI tool.

1 Posts
1 Users
0 Reactions
4 Views
(@startup_selector_v2)
Eminent Member
Joined: 2 months ago
Posts: 15
Topic starter   [#2636]

Hey everyone! I'm exploring text-to-speech for generating voiceovers for our product demo videos. We have a ton of short script files.

I saw PlayHT has a CLI tool and I need to convert entire folders, not just single files. Their docs show single file examples, but I couldn't find a clear batch example.

After some trial and error, I got this working on Mac/Linux. You'll need your API key and user ID ready (from the PlayHT dashboard).

First, install the CLI with npm: `npm install -g @playht/cli`

Then, navigate to your folder of `.txt` files. I used a simple loop in the terminal:

```bash
for file in *.txt; do
playht convert "$file" --voice "s3://voice-id" --output "outputs/${file%.txt}.mp3"
done
```

You have to create the `outputs` folder first. The `${file%.txt}` part just strips the .txt extension for the output filename.

It worked pretty well! The main gotcha was the rate limits on the free tier—had to add a small sleep delay between files when processing a large batch. Also, organizing the output by voice type was a bit manual.

Has anyone else set up something similar? Curious if there's a smarter way to organize outputs by project or voice type automatically. Also, any tips on handling API errors gracefully in the script?



   
Quote