Repository navigation
|
Hello, Is there any way, either through a command or through text editing, to add different lengths of pause between the paragraphs (and possibly after "," or ".")? I've tried adding multiple ellipsis and other punctuation and symbols, but it either ignores multiple instances or reads them out loud in some cases. Personally, I'm using en-US-BrianNeural (because it sounds the most natural to me), but it doesn't really care much about punctuation apparently, and will fire out all the words quicker than I can absorb them, since I mainly use this to turn various webnovels into audio while I do other things. |
Replies: 1 comment 1 reply
|
Not with markup, unfortunately. edge-tts escapes the text you give it ( Punctuation helps a little but isn't controllable. With BrianNeural I measured about 0.45 s after a plain What works reliably is what rany2 suggested in #83: synthesize one paragraph at a time and put real silence in between. A small script for that (needs import asyncio, pathlib, re, subprocess, sys, tempfile
import edge_tts
VOICE = "en-US-BrianNeural"
RATE = "-10%" # a bit slower overall
PAUSE = 1.2 # seconds of silence between paragraphs
async def main(src, out):
text = pathlib.Path(src).read_text(encoding="utf-8")
# blank-line separated paragraphs if there are any, otherwise one paragraph per line
blocks = re.split(r"\n\s*\n", text) if re.search(r"\n\s*\n", text) else text.splitlines()
paras = [p.strip() for p in blocks if p.strip()]
tmp = pathlib.Path(tempfile.mkdtemp())
silence = tmp / "silence.mp3"
subprocess.run(["ffmpeg", "-loglevel", "error", "-f", "lavfi", "-i", "anullsrc=r=24000:cl=mono",
"-t", str(PAUSE), "-c:a", "libmp3lame", "-b:a", "48k", str(silence)], check=True)
parts = []
for i, p in enumerate(paras):
f = tmp / f"p{i:04d}.mp3"
await edge_tts.Communicate(p, VOICE, rate=RATE).save(str(f))
parts += [f, silence]
listfile = tmp / "list.txt"
listfile.write_text("".join(f"file '{x}'\n" for x in parts[:-1]))
subprocess.run(["ffmpeg", "-loglevel", "error", "-y", "-f", "concat", "-safe", "0",
"-i", str(listfile), "-c:a", "libmp3lame", "-b:a", "48k", out], check=True)
asyncio.run(main(sys.argv[1], sys.argv[2]))
|
Not with markup, unfortunately. edge-tts escapes the text you give it (
escape(...)incommunicate.py) and wraps it in a single<prosody>tag, so a<break time="1s"/>would just be read out. The README explains why: Microsoft only accepts the SSML Edge itself generates, so custom SSML support was removed.Punctuation helps a little but isn't controllable. With BrianNeural I measured about 0.45 s after a plain
.(blank lines change nothing), 0.65 s with. ...and 1.3 s with. ... ... ..., but adding even more dots made the pause shorter again.What works reliably is what rany2 suggested in #83: synthesize one paragraph at a time and put real silence in between. A small script for that (n…