Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 53 additions & 47 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,61 @@
import conf

rep = {
'\n': ' ',
'%¶%': '\n',
'fi': 'fi',
'ff': 'ff',
'fl': 'fl',
'ffi': 'ffi',
"\n": " ",
"%¶%": "\n",
"fi": "fi",
"ff": "ff",
"fl": "fl",
"ffi": "ffi",
}


async def synth(pg, text) -> None:
AUDIO = f"page-{pg}.mp3"
SUBS = f"page-{pg}"

if isfile(f"page-{pg}.mp3"): # Skip if exists
with open(SUBS, "r") as file:
file.seek(0, 0)
if file.readline() != "*": return

if not text: # Skip if empty
Path(SUBS).touch(); return

prompt = p.SubMaker()
communicate = edge_tts.Communicate(text, conf.VOICE, rate=conf.RATE)
text = text.replace("\n\n", "%¶% ")
prompt.puncted = deque(text.split())

with open(AUDIO, "wb") as file:
async for chunk in communicate.stream():
if chunk["type"] == "audio":
file.write(chunk["data"])
elif chunk["type"] == "WordBoundary":
prompt.times.append(chunk["offset"])
prompt.plain.append(chunk["text"])

with open(SUBS, "w", encoding="utf-8") as file:
file.write(prompt.generate_subs())
file.seek(0, 0)
file.write("*")
return
AUDIO = f"{conf.VOICE}-{conf.RATE.replace('.', '_')}page-{pg}.mp3"
SUBS = f"page-{pg}"

if isfile(AUDIO): # Skip if exists
with open(SUBS, "r") as file:
file.seek(0, 0)
if file.readline() != "*":
return

if not text: # Skip if empty
Path(SUBS).touch()
return

prompt = p.SubMaker()
communicate = edge_tts.Communicate(text, conf.VOICE, rate=conf.RATE)
text = text.replace("\n\n", "%¶% ")
prompt.puncted = deque(text.split())

with open(AUDIO, "wb") as file:
async for chunk in communicate.stream():
if chunk["type"] == "audio":
file.write(chunk["data"])
elif chunk["type"] == "WordBoundary":
prompt.times.append(chunk["offset"])
prompt.plain.append(chunk["text"])

with open(SUBS, "w", encoding="utf-8") as file:
file.write(prompt.generate_subs())
file.seek(0, 0)
file.write("*")
return


def clean(raw, pg):
text = raw[pg-1].replace('\n\n', '%¶%') # preserve paragraphs
for key, val in rep.items(): # Format + ligature fix
text = text.replace(key, val)

page = ""
# Catch most headers, subtitles, & text fragments
for line in text.splitlines():
words = line.count(' ') + 1
if words < 6: continue
if words and words < 12 and line[-1] != '.': continue
page += line.strip() + '\n\n'
return page
text = raw[pg - 1].replace("\n\n", "%¶%") # preserve paragraphs
for key, val in rep.items(): # Format + ligature fix
text = text.replace(key, val)

page = ""
# Catch most headers, subtitles, & text fragments
for line in text.splitlines():
words = line.count(" ") + 1
if words < 6:
continue
if words and words < 12 and line[-1] != ".":
continue
page += line.strip() + "\n\n"
return page
4 changes: 2 additions & 2 deletions lec.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#————————————————— Lectern: config —————————————————

# Preferred name of voice (default: en-US-AriaNeural)
voice = en-US-EricNeural
voice = en-US-GuyNeural

# Preferred rate of speech for voice (default: 1)
rate = 1.8
rate = 1.2

# Enable/disable bionic reading
bionic = true
Expand Down
Loading