def maybe_cache(s): textToSynth, langToSynth = getTxtLang(s) if not textToSynth: return if not langToSynth == languageToCache: return if hanziOnly and not gradint.fix_compatibility(textToSynth).replace( " ", "") == gradint.hanzi_and_punc(textToSynth).replace(" ", ""): return for txt in [textToSynth, sporadic + textToSynth]: if synth_fileExists( (txt.encode('utf-8') + "_" + langToSynth + dotwav).lower()) or synth_fileExists( (txt.encode('utf-8') + "_" + langToSynth + dotmp3).lower()): return # it's already been done if synth_fileExists( ("__rejected_" + txt.encode('utf-8') + "_" + langToSynth + dotwav).lower()) or synth_fileExists( ("__rejected_" + txt.encode('utf-8') + "_" + langToSynth + dotmp3).lower()): return # it's been rejected textToSynth = sporadic + textToSynth k = (textToSynth.lower(), langToSynth) if generating.has_key(k): if not generating[k] == 1: # a file already exists fname = textToSynth.lower().encode( 'utf-8') + '_' + langToSynth + generating[k][ generating[k].rindex(gradint.extsep):] rename(generating[k], gradint.synthCache + os.sep + fname) scld[fname] = 1 #rename(generating[k][:generating[k].rindex(gradint.extsep)]+dottxt,gradint.synthCache+os.sep+textToSynth.lower().encode('utf-8')+'_'+langToSynth+dottxt) os.remove(generating[k][:generating[k].rindex(gradint.extsep)] + dottxt) generating[k] = 1 return if actually_generate: tm = [ gradint.synth_event( langToSynth, textToSynth[len(sporadic):].encode('utf-8')).getSound(), (textToSynth.encode('utf-8') + "_" + langToSynth + dotwav).lower() ] if gradint.got_program("lame"): # we can MP3-encode it (TODO make this optional) n = tm[0][:-len(dotwav)] + dotmp3 if not os.system("lame --cbr -h -b 48 -m m \"%s\" \"%s\"" % (tm[0], n)): os.remove(tm[0]) tm[0] = n tm[1] = tm[1][:-len(dotwav)] + dotmp3 toMove.append(tm) scld[textToSynth.lower().encode('utf-8') + '_' + langToSynth + dotwav] = 1 return generating[k] = 1 global count while gradint.fileExists(newStuff + os.sep + str(count) + "_" + langToSynth + dottxt): count += 1 open(newStuff + os.sep + str(count) + "_" + langToSynth + dottxt, "w").write(textToSynth[len(sporadic):].encode('utf-16')) count += 1
for f in gradint.AvailablePrompts().lsDic.values(): for f2 in f: if f2.endswith("txt"): maybe_cache(f2, gradint.promptsDirectory) for l in langs: gradint.get_synth_if_possible(l).finish_makefile() count = 0 gradint.soundCollector = 0 if toMove: sys.stderr.write("Renaming\n") else: sys.stderr.write("No additional words need to be synthesized\n") for tmpfile, dest in toMove: oldDest = dest try: os.rename(tmpfile, gradint.synthCache + os.sep + dest) except OSError: # not a valid filename while gradint.fileExists(gradint.synthCache + os.sep + ("__file%d" % count) + gradint.dotwav) or gradint.fileExists( gradint.synthCache + os.sep + ("__file%d" % count) + gradint.dotmp3): count += 1 os.rename( tmpfile, gradint.synthCache + os.sep + ("__file%d" % count) + gradint.dotwav) open(gradint.synthCache + os.sep + gradint.transTbl, "ab").write("__file%d%s %s\n" % (count, gradint.dotwav, dest)) dest = "__file%d%s" % (count, gradint.dotwav) if testMode: sys.stderr.write(oldDest + "\n") e = gradint.SampleEvent(gradint.synthCache + os.sep + dest) t = time.time() e.play()
if not lang: sys.stderr.write( "Please put a language abbreviation on the command line. See comments at the start of this script for details.\n" ) sys.exit() lang = lang[0] sys.argv = [] import gradint if not gradint.synthCache: sys.stderr.write("Error - synthCache is not set in advanced.txt\n") sys.exit() gradint.cache_maintenance_mode = 1 toList = [] wroteChars = 0 listed = {} if gradint.fileExists("cachelist-done" + gradint.dottxt): listed = gradint.list2set( filter( lambda x: x, gradint.u8strip( open("cachelist-done" + gradint.dottxt).read().replace( "\r", "\n")).split("\n"))) def maybe_list(s, directory): if not s: return # in case poetry has some 2nd-language only if '!synth:' in s and "_" in s: textToSynth, langToSynth = gradint.textof(s), gradint.languageof(s) elif s.endswith(gradint.dottxt): textToSynth, langToSynth = gradint.readText( directory + os.sep + s), gradint.languageof(