Utils
ChunkCache
¶
Disk cache of per-chunk audio enabling resume after a crash or quit.
Chunks are stored as .npy files keyed by (namespace, index, text
hash) so that cached audio is only reused for the identical chunk of
the identical text, voice, and generation settings. Writes are atomic
(temp file + os.replace) so a killed process never leaves a
half-written chunk that looks complete. The cache is best-effort: any
I/O failure is silently ignored, and :meth:clear removes it once the
final output has been assembled.
Source code in tts_studio/utils.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
clear()
¶
Remove the cache directory (call after the output is complete).
Source code in tts_studio/utils.py
196 197 198 | |
get(index, text)
¶
Return cached audio for a chunk, or None if not cached.
Source code in tts_studio/utils.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
put(index, text, audio)
¶
Atomically cache audio for a chunk (best-effort).
Source code in tts_studio/utils.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
chunk_text(text, initial_chunk_size=1000)
¶
Split text into chunks at sentence boundaries.
Source code in tts_studio/utils.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
dynamic_print(text, audio_length_sec)
¶
Prints text character-by-character synced to audio duration.
Source code in tts_studio/utils.py
106 107 108 109 110 111 112 113 114 115 116 117 | |
normalize_text(text, strip_markdown=False)
¶
Normalize text for TTS: rejoin hyphen-broken words and clean spacing.
Fixes the two classic causes of weird mid-word breaks: - EPUB words split across inline tags ("well- known" -> "well-known") - PDF line-wrap hyphenation ("inter-\nesting" -> "interesting")
Source code in tts_studio/utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
split_paragraphs(text)
¶
Split text into paragraphs on blank lines, normalized for TTS.
Source code in tts_studio/utils.py
64 65 66 67 68 69 70 71 72 | |
split_sentences(paragraph)
¶
Sentence-split a paragraph, merging punkt mistakes on abbreviations and quotes so the TTS doesn't pause mid-thought.
Source code in tts_studio/utils.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |