Newer
Older
r.append(",")
elif not e.__class__==Event: r.append(fname(str(e)))
return " ".join(r)
def abspath_from_start(p): # for just_synthesize to check for paths relative to the original starting directory if this is different from the gradint directory (see system.py)
d=os.getcwd()
os.chdir(starting_directory)
try: r=os.path.abspath(p)
except: r="" # library problems on Windows?
os.chdir(d)
return r
def just_synthesize(callSanityCheck=0,lastLang_override=None):
# Handle the justSynthesize setting (see advanced.txt)
global startAnnouncement,endAnnouncement,logFile,synth_partials_cache
synth_partials_cache = {} # to stop 'memory leak' when running from the GUI
oldStart,oldEnd,oldLogfile = startAnnouncement,endAnnouncement,logFile
startAnnouncement=endAnnouncement=logFile=None
if app: app.setLabel("") # not "wait a moment"
called_synth = 0
# we re-generate the lesson on each repeat, so sporadic-synthcache stuff works
global repeatMode ; repeatMode = 1
while repeatMode:
repeatMode = 0
less = Lesson()
lastStartTime = lastEndTime = lastWasDelay = 0
if lastLang_override: lastLanguage = lastLang_override
else: lastLanguage = secondLanguage
def checkCanSynth(fname):
ret=can_be_synthesized(fname)
if ret: return fileToEvent(fname)
else: show_warning("Can't say "+repr(fname)) # previous warnings should have said why (e.g. partials-only language)
for line in justSynthesize.split("#"):
line = line.strip(wsp) ; l = line.split(None,1)
if extsep in line and fileExists(line): event = fileToEvent(line,"")
elif extsep in line and fileExists(abspath_from_start(line)): event = fileToEvent(abspath_from_start(line),"")
elif line=='R':
repeatMode=1 ; continue
elif len(l)==1:
try: delayVal = float(l[0])
except ValueError: delayVal = None
if delayVal==None:
# no float value; assume it's a single word to synth in secondLanguage or whatever was the last language used
show_warning("Assuming that %s is a word to synthesize in language '%s'" % (repr(l[0]),lastLanguage))
if callSanityCheck and sanityCheck(l[0],lastLanguage,1): return
event = checkCanSynth("!synth:"+l[0]+"_"+lastLanguage)
if not event: continue # couldn't synth
called_synth = 1
else:
lastWasDelay = 1
if delayVal<0: lastEndTime = lastStartTime-delayVal
else: lastEndTime += delayVal
continue
elif len(l)==2:
lang, text = l
if lang=="sh:": event = ShellEvent(text)
else:
fname = "!synth:"+text+"_"+lang
if not can_be_synthesized(fname):
if lang in [firstLanguage,secondLanguage]+otherLanguages:
show_warning("Can't say %s in %s" % (repr(text),repr(lang)))
lastLanguage=lang ; continue
# otherwise, user might have omitted lang by mistake
show_warning("Assuming %s was meant to be synthesized in language '%s'" % (cond("#" in justSynthesize or len(repr(line))<10,"that '"+repr(line)+"'","this line"),lastLanguage))
if callSanityCheck and sanityCheck(line,lastLanguage,1): return
else:
if callSanityCheck and sanityCheck(text,lang,1): return
called_synth = 1
else: continue # len(l)==0: ignore empty strings between #s
event.addToEvents(less.events,lastEndTime)
lastWasDelay = 0
lastStartTime = lastEndTime
lastEndTime += event.length
if lastWasDelay: Event(0).addToEvents(less.events,lastEndTime)
global dbase ; dbase = None # for handleInterrupt
less.play()
startAnnouncement,endAnnouncement,logFile = oldStart,oldEnd,oldLogfile
if not called_synth: return None
return lastLanguage