Exemplo n.º 1
0
def maybe_cache(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.extsep + "txt"):
        textToSynth, langToSynth = gradint.readText(
            directory + os.sep + s), gradint.languageof(
                s, directory == gradint.promptsDirectory)
    else:
        return
    if not langToSynth in langs: return  # we're not caching that language
    if synth_fileExists(
        (textToSynth + "_" + langToSynth +
         gradint.dotwav).lower()) or synth_fileExists(
             (textToSynth + "_" + langToSynth + gradint.dotmp3).lower()):
        return  # it's already been done
    if synth_fileExists(("__rejected_" + textToSynth + "_" + langToSynth +
                         gradint.dotwav).lower()) or synth_fileExists(
                             ("__rejected_" + textToSynth + "_" + langToSynth +
                              gradint.dotmp3).lower()):
        return  # it's been rejected by the GUI
    if (textToSynth.lower(), langToSynth) in generating:
        return  # we're already generating it
    generating[(textToSynth.lower(), langToSynth)] = 1
    sys.stderr.write("Generating %s\n" % (textToSynth, ))
    toMove.append((gradint.synth_event(langToSynth, textToSynth).getSound(),
                   (textToSynth + "_" + langToSynth + gradint.dotwav).lower()))
Exemplo n.º 2
0
def transLineToTuple(l):
    x, y = l.split(None, 1)
    y = "!synth:" + y
    if gradint.extsep in x:
        x = x[:x.rindex(
            gradint.extsep
        )]  # make comparison easier (extensions don't matter to us)
    return (gradint.textof(y) + "_" + gradint.languageof(y), x)
def link(l):
    if type(l) == type([]): return link(l[-1])
    if l.lower().endswith(gradint.dottxt):
        l = "!synth:" + gradint.u8strip(
            gradint.read(gradint.samplesDirectory + os.sep +
                         checkVariant(l, 1))).strip(
                             gradint.wsp) + "_" + gradint.languageof(l)
    if "!synth:" in l:
        if gradint.languageof(l) not in [
                gradint.firstLanguage, gradint.secondLanguage
        ]:
            l = gradint.textof(l) + " (" + gradint.languageof(l) + ")"
        else:
            l = gradint.textof(l)
        return l.replace('&', '&amp;').replace('<', '&lt;')
    if samples_url:
        return '<A HREF="' + samples_url + checkVariant(l) + '"' + h5aCode(
            checkVariant(l)) + '>' + wrappable(l) + '</A>'
    return wrappable(l).replace('&', '&amp;').replace('<', '&lt;')
Exemplo n.º 4
0
def getTxtLang(s):
    if '!synth:' in s and "_" in s:
        return gradint.textof(s).decode('utf-8'), gradint.languageof(s)
    elif s.endswith(gradint.extsep + "txt"):
        langToSynth = gradint.languageof(s)
        if langToSynth == languageToCache:
            return gradint.readText(s).decode(
                'utf-8'
            ), langToSynth  # else don't bother reading the file (it might be over ftpfs)
    return None, None
Exemplo n.º 5
0
def mark_as_used(s,directory):
    if s and '!synth:' in s and "_" in s: textToSynth, langToSynth = gradint.textof(s),gradint.languageof(s)
    elif s and s.endswith(gradint.extsep+"txt"): textToSynth, langToSynth = gradint.readText(directory+os.sep+s), gradint.languageof(s,directory==gradint.promptsDirectory)
    else: return
    k=(textToSynth+"_"+langToSynth).lower()
    k=trans.get(k,k)
    for p in ["__rejected_","__rejected__"]:
        if p+k in unused: del unused[p+k]
    if not k in unused:
        if "_"+k in unused: k="_"+k
        else: return
    if also_remove_words_that_can_be_synthesized_by_partials and gradint.synth_from_partials(textToSynth,langToSynth): return
    del unused[k]
Exemplo n.º 6
0
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(
                s, directory == gradint.promptsDirectory)
    else:
        return
    if not langToSynth == lang: return  # we're not listing that language
    if textToSynth.lower() in listed: return
    d = textToSynth.decode('utf-8')
    if hanzi_only and langToSynth == "zh" and not gradint.fix_compatibility(
            d).replace(" ", "") == gradint.hanzi_and_punc(d):
        return
    global wroteChars
    if paragraph_size and wroteChars and wroteChars + len(d) > paragraph_size:
        toList.append("")
        wroteChars = 0
    wroteChars += (len(d) + 2)  # comma and \n
    toList.append(textToSynth + ",")
    listed[textToSynth.lower()] = 1
Exemplo n.º 7
0
            == gradint.secondLanguage, pLines):
        continue
    plines2 = []
    for p in pLines:
        idx = line2index[p]
        doneAlready[idx] = 1
        prompt = d.unavail[idx][1]
        equals = ""
        if type(prompt) == type([]):
            if len(prompt) == 3: equals = prompt[1]
        elif not plines2 and not prompt == p: equals = prompt  # if 1st line
        if equals:
            assert equals.startswith("!synth:") and gradint.languageof(
                equals
            ) == gradint.firstLanguage, "recovery of poems with non-L1 secondary prompts not yet supported"
            equals = "=" + gradint.textof(equals)
        plines2.append(gradint.textof(p) + equals)
    output.append((d.unavail[line2index[pLines[0]]][0], gradint.secondLanguage,
                   gradint.firstLanguage,
                   "\n".join(["begin poetry"] + plines2 + ["end poetry"])))

for count, (num, L1, L2) in zip(xrange(len(d.unavail)), d.unavail):
    if count in doneAlready: continue
    if type(L1) == type(L2) == type("") and L1.startswith(
            "!synth:") and L2.startswith("!synth:"):
        lang1, lang2 = gradint.languageof(L1), gradint.languageof(L2)
        output.append((num, lang2, lang1,
                       "%s=%s" % (gradint.textof(L2), gradint.textof(L1))))

output.sort()
output.reverse()