コード例 #1
0
 def preprocess(syllables):
     temp = []
     for syllable in syllables:
         for p in TextToSpeech.punctuation:
             syllable = syllable.replace(p, "")
         if syllable.isdigit():
             syllable = atc.num2chinese(syllable)
             new_sounds = lazy_pinyin(syllable, style=pypinyin.TONE3)
             for e in new_sounds:
                 temp.append(e)
         else:
             temp.append(syllable)
     return temp
コード例 #2
0
def text2pinyin(syllables):
    temp = []
    for syllable in syllables:
        for p in PUNCTUATION:
            syllable = syllable.replace(p, "")
        # print(syllable)
        # if syllable.isdigit():
        try:
            syllable = atc.num2chinese(syllable)
            # print("sy:", syllable)
            new_sounds = lazy_pinyin(syllable, style=pypinyin.TONE2)
            for e in new_sounds:
                temp.append(e)
        except:
            syllable = syllable.replace(".", "")
            for p in PUNCTUATION:
                syllable = syllable.replace(p, "")
            temp.append(syllable)
    return temp
コード例 #3
0
        for alpha, pronuce in alpha_pronuce.items():
            text = text.replace(alpha, pronuce)
        text = text.replace("  ", " ")
        text = text.replace("  ", " ")

        return text
    else:
        print("input format error")


def num2han(value):
    num_han = {0: '零', 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六', 7: '七', 8: '八', 9: '九'}
    value = ''.join(x for x in value if x in "0123456789")
    value = ''.join(num_han.get(int(x)) for x in value)
    return value


def num2phone(value):
    num_han = {0: '零', 1: '妖', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六', 7: '七', 8: '八', 9: '九'}
    value = ''.join(x for x in value if x in "0123456789")
    value = ''.join(num_han.get(int(x)) for x in value)
    return value


if __name__ == "__main__":
    print(num2han(value="010194567898"))
    print(ch2p(num2phone("010194567898")))
    print(atc.num2chinese("3418.91"))
    print(atc.num2chinese("2418.91", twoalt=True))
    print(ch2p("月A 三ABW六零"))