A.I. Audio Generation

  • Thread starter Thread starter Deleted member 2311908
  • Start date Start date
D

Deleted member 2311908

Guest
I use OBS Studio to generate audio and edit trailers, and this little Python script has become a really handy part of my workflow. It takes a Markdown transcript file, turns it into speech, and outputs a WAV file that I can plug straight into OBS Studio.

Posting it here in case it helps friends build a simple voice workflow for trailers, previews, or narrated content.

Code:
from kokoro import KPipeline
import soundfile as sf

TRANSCRIPT = "transcript.md"
OUT_WAV = "output.wav"

print("Loading Kokoro pipeline...")
pipeline = KPipeline(lang_code='a')  # 'a' = American English

text = open(TRANSCRIPT).read().strip()

print("Generating speech...")
generator = pipeline(text, voice='af_heart')

audio_chunks = []

for i, (gs, ps, audio) in enumerate(generator):
    audio_chunks.append(audio)

# Concatenate chunks
import numpy as np
full_audio = np.concatenate(audio_chunks)

sf.write(OUT_WAV, full_audio, 24000)

print("Done →", OUT_WAV)
 
Really interesting. Great work.

I'd also taken a look at Kokoro but haven't tested it yet. What kind of hardware does it require to use locally?

I don't need it to be super fast. But let's say I have a text that would generate 60 minutes of audio, and I run a script before going to sleep, I'd like it to be ready about 10 hours later, around the time I start using my computer the next day.

So, for comparison, could you share what kind of hardware you use, the duration of the audio files you create, and how long it takes to output?

Thanks in advance.
 
Thank you for the kind words. My setup is nothing too exotic, I am running a single NVIDIA GeForce RTX 4070 over a transcript file with ~1200 ASCII characters. It produces about a minute and a half of audio in roughly five to ten seconds.

All voice used is ethically sourced, and no dark magic involved.
 
I love good things in life and I've never even heard of Eleven Labs.
 
Thank you for the kind words. My setup is nothing too exotic, I am running a single NVIDIA GeForce RTX 4070 over a transcript file with ~1200 ASCII characters. It produces about a minute and a half of audio in roughly five to ten seconds.

All voice used is ethically sourced, and no dark magic involved.
Thanks for sharing your experience. I finally gave Kokoro a try, and honestly, I'm blown away by how effective and lightweight it is!

Basically, the only challenge is that voices that sound truly human are rare—like "heart" and "bella" for American English. But the results with these voices are really good, comparable to what you get with Google AI Studio.

There’s one really impressive feature, though: you can use custom voices on the fly.

For instance, when selecting a voice in your script, instead of just picking one, you can mix two together and choose the proportions. Like `VOICE="af_heart:70,af_bella:30"`.

As for speed, I tested it on a laptop with these specs:

Intel© Core™ i5-6300U CPU @ 2.40GHz × 2 and 8 GB of RAM.

Honestly, it feels like it generates audio in real-time—matching the speed of actual speech.
For example, a 10-minute WAV file takes about 10 minutes to generate.

It’s really cool!

Your post is what really got me interested in trying it out, so thanks a lot.
 
Oh, one more thing: for most of the non-English languages I tested (using only female voices), I encountered the following issues and found a "hack" to work around them:

1: The only French voice had "flat" intonation, making it sound a bit robotic. However, it was less strange (to my ears) than the auto-generated voices you sometimes hear on TikTok.

2: The Spanish and Portuguese voices sounded too deep for female voices.

3: The other voices I tested had timbre issues, sounding somewhat metallic. This included some of the English voices.

The technique I discovered involves mixing a voice that speaks and sounds good in English—such as "Heart" or "Bella"—with the voice for the target language. Crucially, you also need to specify the language within the script itself.

After some experimentation, I managed to get a pretty good result by mixing "Heart" with the French voice. The resulting file speaks French, though with a noticeable accent.

At times, the accent is so strong that it really sounds like an English speaker speaking French; a French people would need to get used to the voice to fully understand everything.

On the plus side, the intonation is remarkably human-like.

For now, the result isn't quite up to par, but I think it's an avenue worth exploring.
 
@Starblazer to answer your question... nah, it is not quite ElevenLabs level yet if you need deep emotional range or perfect inflections. But if you are doing bulk video creation or running multiple niche channels, ElevenLabs API costs will eat all your margins anyway.

i tried Kokoro last week for a batch of short-form test channels and the speed is what blew me away. @HotMilfNearYou that voice mixing trick is gold, didn't realize you could blend them like that on the fly. I've been using XTTS v2 locally but it is a resource hog compared to this. Definitely going to try adapting this script for my next automated run.
 
he speed is what blew me away
Me too, as I was saying. That’s really the thing that shocked me. Now, regarding that:
that voice mixing trick is gold, didn't realize you could blend them like that on the fly
Yeah, that shocked me too. I’ve talked about this before as a way to get around low-quality voices, but the really interesting part is this:

Most videos using AI voices feature voices that all sound alike. I’m trying to create content that keeps my fans engaged:

Normally, when you’re a fan of a creator—even if they make faceless videos or just audio content—you recognize their voice. Right now, goods AI voices all sound almost the same, so I’m trying to create a mix that ensures my fans recognize it’s me.

There’s also something else that applies to any TTS audio, regardless of the tool:

I run the TTS audio file through Audacity to improve it, but—more importantly—I add a bit of reverb. It creates the impression of someone speaking in a real room. It makes the result feel more "human"—like a real person addressing the viewer, rather than just a voiceover like you’d hear in a TV commercial.
 
Back
Top