go-pinyin - 一个 Go 实现的汉语拼音转换工具

jopen 10年前

汉语拼音转换工具 Go 版。

Installation

go get -u github.com/mozillazg/go-pinyin

install CLI tool:

go get -u github.com/mozillazg/go-pinyin/pinyin  $ pinyin 中国人  zhōng guó rén

Documentation

API documentation can be found here: https://godoc.org/github.com/mozillazg/go-pinyin

Usage
package main    import (      "fmt"      "github.com/mozillazg/go-pinyin"  )    func main() {      hans := "中国人"      a := pinyin.NewArgs()      // 默认输出 [[zhong] [guo] [ren]]      fmt.Println(pinyin.Pinyin(hans, a))        // 包含声调 [[zhōng] [guó] [rén]]      a.Style = pinyin.Tone      fmt.Println(pinyin.Pinyin(hans, a))        // 声调用数字表示 [[zho1ng] [guo2] [re2n]]      a.Style = pinyin.Tone2      fmt.Println(pinyin.Pinyin(hans, a))        // 开启多音字模式 [[zhong zhong] [guo] [ren]]      a = NewArgs()      a.Heteronym = true      fmt.Println(pinyin.Pinyin(hans, a))      // [[zho1ng zho4ng] [guo2] [re2n]]      a.Style = pinyin.Tone2      fmt.Println(pinyin.Pinyin(hans, a))  }

其它相关的项目

项目主页:http://www.open-open.com/lib/view/home/1420774239484