Gpy
Golang Chinese to Pinyin
Install / Use
/learn @go-ego/GpyREADME
gpy
<!-- [](https://coveralls.io/r/github.com/go-ego/gpy?branch=master) -->
汉语拼音转换工具 Go 版。
Installation
go get -u github.com/go-ego/gpy
Install CLI tool:
go get -u github.com/go-ego/gpy/tools/pinyin
$ pinyin 中国话
zhōng guó huà
$ pinyin -s zhao 中国话
zhong guo hua
Usage
package main
import (
"fmt"
"github.com/go-ego/gse"
"github.com/go-ego/gpy"
"github.com/go-ego/gpy/phrase"
)
var test = `西雅图都会区; 长夜漫漫, winter is coming!`
func main() {
args := gpy.Args{
Style: gpy.Tone,
Heteronym: true}
py := gpy.Pinyin(test, args)
fmt.Println("gpy:", py)
s := gpy.ToString(py)
fmt.Println("gpy string:", s)
phrase.LoadGseDict()
go func() {
fmt.Println("gpy phrase1:", phrase.Paragraph(test))
}()
fmt.Println("gpy phrase2:", phrase.Paragraph(test))
seg := gse.New("zh, dict.txt")
// phrase.DictAdd["都会区"] = "dū huì qū"
phrase.AddDict("都会区", "dū huì qū")
fmt.Println("gpy phrase:", phrase.Paragraph(test, seg))
fmt.Println("pinyin: ", phrase.Pinyin(test))
fmt.Println("Initial: ", phrase.Initial("都会区"))
}
package main
import (
"fmt"
"github.com/go-ego/gpy"
)
func main() {
hans := "中国话"
// 默认
a := gpy.NewArgs()
fmt.Println(gpy.Pinyin(hans, a))
// [[zhong] [guo] [hua]]
// 包含声调
a.Style = gpy.Tone
fmt.Println(gpy.Pinyin(hans, a))
// [[zhōng] [guó] [huà]]
// 声调用数字表示
a.Style = gpy.Tone2
fmt.Println(gpy.Pinyin(hans, a))
// [[zho1ng] [guo2] [hua4]]
// 开启多音字模式
a = gpy.NewArgs()
a.Heteronym = true
fmt.Println(gpy.Pinyin(hans, a))
// [[zhong zhong] [guo] [hua]]
a.Style = gpy.Tone2
fmt.Println(gpy.Pinyin(hans, a))
// [[zho1ng zho4ng] [guo2] [hua4]]
fmt.Println(gpy.LazyPinyin(hans, gpy.NewArgs()))
// [zhong guo hua]
fmt.Println(gpy.Convert(hans, nil))
// [[zhong] [guo] [hua]]
fmt.Println(gpy.LazyConvert(hans, nil))
// [zhong guo hua]
}
Related Projects
- hotoo/pinyin: 汉语拼音转换工具 Node.js/JavaScript 版。
- mozillazg/python-pinyin: 汉语拼音转换工具 Python 版。
- mozillazg/rust-pinyin: 汉语拼音转换工具 Rust 版。
License
Under the MIT License, base on go-pinyin.
Related Skills
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
344.4kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
