tangs b030ce89ca openbilibili | 5 anos atrás | |
---|---|---|
.. | ||
BUILD.bazel | 5 anos atrás | |
CHANGELOG.md | 5 anos atrás | |
CONTRIBUTING.md | 5 anos atrás | |
LICENSE | 5 anos atrás | |
Makefile | 5 anos atrás | |
README.md | 5 anos atrás | |
README_zh.md | 5 anos atrás | |
circle.yml | 5 anos atrás | |
doc.go | 5 anos atrás | |
phonetic_symbol.go | 5 anos atrás | |
pinyin.go | 5 anos atrás | |
pinyin_dict.go | 5 anos atrás |
汉语拼音转换工具 Go 版。
go get -u github.com/go-ego/gpy
go get -u github.com/go-ego/gpy/pinyin
$ gpy 中国人
zhōng guó rén
API documentation can be found here: godoc
package main
import (
"fmt"
"github.com/go-ego/gpy"
)
func main() {
hans := "中国人"
// 默认
a := gpy.NewArgs()
fmt.Println(gpy.Pinyin(hans, a))
// [[zhong] [guo] [ren]]
// 包含声调
a.Style = gpy.Tone
fmt.Println(gpy.Pinyin(hans, a))
// [[zhōng] [guó] [rén]]
// 声调用数字表示
a.Style = gpy.Tone2
fmt.Println(gpy.Pinyin(hans, a))
// [[zho1ng] [guo2] [re2n]]
// 开启多音字模式
a = gpy.NewArgs()
a.Heteronym = true
fmt.Println(gpy.Pinyin(hans, a))
// [[zhong zhong] [guo] [ren]]
a.Style = gpy.Tone2
fmt.Println(gpy.Pinyin(hans, a))
// [[zho1ng zho4ng] [guo2] [re2n]]
fmt.Println(gpy.LazyPinyin(hans, gpy.NewArgs()))
// [zhong guo ren]
fmt.Println(gpy.Convert(hans, nil))
// [[zhong] [guo] [ren]]
fmt.Println(gpy.LazyConvert(hans, nil))
// [zhong guo ren]
}
Under the MIT License, base on go-pinyin.