File size: 378 Bytes
b3c3938
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
"""Full-sentence pinyin with g2pS + pypinyin fallback for monophonic chars."""
from g2ps import G2pS
import pypinyin

g = G2pS('models/nano')

def full_pinyin(text):
    used, pairs = g.convert(text)
    return [p or pypinyin.pinyin(c, style=pypinyin.Style.TONE3, heteronym=False)[0][0]
            for c, p in pairs]

print(full_pinyin('他在银行工作,行踪不定。'))