overtrue/pinyin
Chinese to pinyin translator.
6.0.1
7.2M downloads/mo
#2054 most downloaded on Packagist
overtrue/pinyin
What this package is like to depend on
Last release 5 months ago
06 Mar 2026
Ships fairly regularly
a new release about every 5 months
Rarely documented
notes for 12 of 56 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
56 releases · first in 2014
2 releases in the last 12 months
see the full history below
Release timeline
56 releases · Jul 2014 to Mar 2026Releases
latest 56-
6.0.106 Mar 2026 -
6.0.008 Sep 2025Release notes
Open source →🚀 Major Features
- 性能优化策略系统: 全新的转换策略架构,针对不同使用场景提供最优性能
- 内存优化策略 (Memory Optimized): 占用 ~400KB 内存,适合 Web 请求和内存受限环境
- 缓存策略 (Cached): 占用 ~4MB 内存,重复转换性能提升 2-3 倍,适合批处理任务
- 智能策略 (Smart): 占用 600KB-1.5MB 内存,根据文本复杂度自适应加载
- ConverterFactory: 新的工厂模式管理转换器实例和策略选择
- 自动策略选择: 根据运行环境(Web/CLI/内存限制)自动推荐最佳策略
- 性能基准测试工具: 内置的策略性能对比和监控工具
- 内存监控: 支持实时监控内存使用情况和性能指标
🔧 API Changes
- 新增
Pinyin::useMemoryOptimized()- 切换到内存优化策略 - 新增
Pinyin::useCached()- 切换到缓存策略 - 新增
Pinyin::useSmart()- 切换到智能策略 - 新增
Pinyin::useAutoStrategy()- 自动选择最佳策略 - 新增
Pinyin::clearCache()- 清理所有转换器缓存 - 新增
ConverterFactory::make($strategy)- 创建指定策略的转换器 - 新增
ConverterFactory::recommend()- 获取推荐策略 - 新增
ConverterFactory::getStrategiesInfo()- 获取所有策略信息
⚡ Performance Improvements
- 内存使用优化: 默认内存占用从 ~4MB 降低到 ~400KB
- 转换速度提升: 缓存策略下重复转换速度提升 2-3 倍
- 智能加载: 根据文本复杂度动态调整数据加载策略
- 按需加载: 内存优化策略仅在需要时加载转换数据
📊 Benchmark & Monitoring
- 新增
php benchmark/run.php- 运行性能基准测试 - 新增
php benchmark/compare-strategies.php- 策略对比测试 - 新增基准测试文档
docs/benchmark-guide.md - 支持内存使用情况实时监控
运行基准测试
# 运行标准基准测试,显示所有方法的性能表现 php benchmark/run.php # 详细的策略对比测试,对比三种策略的性能差异 php benchmark/compare-strategies.php
基准测试会显示:
- 每种策略的执行时间和内存使用情况
- 不同文本长度下的性能表现
- 策略之间的性能对比和推荐场景
🔄 Breaking Changes
- 默认策略变更: 从全缓存改为内存优化策略,降低默认内存占用
- 转换器架构重构: 引入策略模式,旧的直接实例化转换器方式仍兼容
- 性能特征变化: 首次转换可能略慢,但内存占用显著降低
🔧 Backward Compatibility
- 完全兼容 5.x API,现有代码无需修改即可使用
heteronym()方法(5.3.3+ 引入)继续保持兼容- 所有原有的转换方法 (
sentence,phrase,chars等) 保持不变
📚 Documentation
- 更新 README.md 增加性能优化策略说明
- 新增性能对比表格和使用建议
- 新增基准测试指南
- 新增性能优化最佳实践
🔧 Development Tools
- 新增性能基准测试脚本
- 新增策略对比工具
- 增强命令行工具支持策略选择
https://github.com/overtrue/pinyin/blob/master/CHANGELOG.md
New Contributors
- @Copilot made their first contribution in #216
Full Changelog: 5.3.4...6.0.0
Release notes
Open source →🚀 Major Features
- 性能优化策略系统: 全新的转换策略架构,针对不同使用场景提供最优性能
- 内存优化策略 (Memory Optimized): 占用 ~400KB 内存,适合 Web 请求和内存受限环境
- 缓存策略 (Cached): 占用 ~4MB 内存,重复转换性能提升 2-3 倍,适合批处理任务
- 智能策略 (Smart): 占用 600KB-1.5MB 内存,根据文本复杂度自适应加载
- ConverterFactory: 新的工厂模式管理转换器实例和策略选择
- 自动策略选择: 根据运行环境(Web/CLI/内存限制)自动推荐最佳策略
- 性能基准测试工具: 内置的策略性能对比和监控工具
- 内存监控: 支持实时监控内存使用情况和性能指标
🔧 API Changes
- 新增
Pinyin::useMemoryOptimized()- 切换到内存优化策略 - 新增
Pinyin::useCached()- 切换到缓存策略 - 新增
Pinyin::useSmart()- 切换到智能策略 - 新增
Pinyin::useAutoStrategy()- 自动选择最佳策略 - 新增
Pinyin::clearCache()- 清理所有转换器缓存 - 新增
ConverterFactory::make($strategy)- 创建指定策略的转换器 - 新增
ConverterFactory::recommend()- 获取推荐策略 - 新增
ConverterFactory::getStrategiesInfo()- 获取所有策略信息
⚡ Performance Improvements
- 内存使用优化: 默认内存占用从 ~4MB 降低到 ~400KB
- 转换速度提升: 缓存策略下重复转换速度提升 2-3 倍
- 智能加载: 根据文本复杂度动态调整数据加载策略
- 按需加载: 内存优化策略仅在需要时加载转换数据
📊 Benchmark & Monitoring
- 新增
php benchmark/run.php- 运行性能基准测试 - 新增
php benchmark/compare-strategies.php- 策略对比测试 - 新增基准测试文档
docs/benchmark-guide.md - 支持内存使用情况实时监控
运行基准测试
# 运行标准基准测试,显示所有方法的性能表现 php benchmark/run.php # 详细的策略对比测试,对比三种策略的性能差异 php benchmark/compare-strategies.php基准测试会显示:
- 每种策略的执行时间和内存使用情况
- 不同文本长度下的性能表现
- 策略之间的性能对比和推荐场景
🔄 Breaking Changes
- 默认策略变更: 从全缓存改为内存优化策略,降低默认内存占用
- 转换器架构重构: 引入策略模式,旧的直接实例化转换器方式仍兼容
- 性能特征变化: 首次转换可能略慢,但内存占用显著降低
🔧 Backward Compatibility
- 完全兼容 5.x API,现有代码无需修改即可使用
heteronym()方法(5.3.3+ 引入)继续保持兼容- 所有原有的转换方法 (
sentence,phrase,chars等) 保持不变
📚 Documentation
- 更新 README.md 增加性能优化策略说明
- 新增性能对比表格和使用建议
- 新增基准测试指南
- 新增性能优化最佳实践
🔧 Development Tools
- 新增性能基准测试脚本
- 新增策略对比工具
- 增强命令行工具支持策略选择
🛠️ Migration Guide
从 5.x 升级到 6.0 非常简单,所有现有代码都能正常工作:
无需任何修改(推荐)
// 5.x 和 6.x 都能正常工作 Pinyin::sentence('你好世界'); // 6.x 默认使用内存优化策略,内存占用更低保持 5.x 完全相同的性能特征
// 如果你需要与 5.x 完全相同的高性能(高内存占用) Pinyin::useCached(); // 一次设置,全局生效 Pinyin::sentence('你好世界');使用新的性能优化特性
// 自动选择最佳策略(推荐用于新项目) Pinyin::useAutoStrategy(); // 或者根据场景手动选择: // Web 应用(内存受限) Pinyin::useMemoryOptimized(); // 批处理任务(性能优先) Pinyin::useCached(); // 通用场景(平衡) Pinyin::useSmart();性能监控和优化
// 监控内存使用 $initialMemory = memory_get_usage(); $result = Pinyin::sentence('测试文本'); $memoryUsed = memory_get_usage() - $initialMemory; echo "内存使用: " . round($memoryUsed / 1024, 2) . " KB"; // 批处理完成后清理缓存 Pinyin::useCached(); // ... 批量处理 ... Pinyin::clearCache(); // 释放内存💡 Performance Comparison
策略 内存占用 首次转换 重复转换 推荐场景 Memory Optimized ~400KB 中等 中等 Web 请求、内存受限环境 Cached ~4MB 慢 最快 (2-3x) 批处理、长时运行进程 Smart 600KB-1.5MB 快 快 通用场景、自动优化 基于 1000 次转换的基准测试结果:
文本长度 Memory Optimized Cached Smart 短文本 (<10字) 1.2ms 0.5ms 0.8ms 中等文本 (10-50字) 3.5ms 1.2ms 2.1ms 长文本 (>100字) 8.7ms 3.1ms 5.2ms - 性能优化策略系统: 全新的转换策略架构,针对不同使用场景提供最优性能
-
5.3.416 Mar 2025Release notes
Open source →What's Changed
- 修改炔的读音gui为que by @ljyljy0211 in #209
New Contributors
- @ljyljy0211 made their first contribution in #209
Full Changelog: 5.3.3...5.3.4
-
5.3.301 Aug 2024Release notes
Open source →What's Changed
- Fixed #207
- Update brainmaestro/composer-git-hooks requirement from ^2.7 to ^3.0 by @dependabot in #204
- Update nunomaduro/termwind requirement from ^1.13 to ^2.0 by @dependabot in #206
- Update phpunit/phpunit requirement from ^10.1 to ^11.2 by @dependabot in #205
Full Changelog: 5.3.2...5.3.3
Release notes
Open source →🚀 Features
- 使用 heteronym 代替 polyphonic 多音字 #184
- 取首字母时,能否保留完整的英文 #199
🐛 Bug Fixes
- 修复 琢 的音频顺序 #207
- 补充案例 #207
- Tests
- Tests
-
5.3.219 Mar 2024Release notes
Open source →Pinyin::abbr新增第三个参数bool $preserveEnglishWords = false, 以保留输入内容的英文单词 #199Full Changelog: 5.3.1...5.3.2
-
5.3.119 Mar 2024 -
5.3.027 Oct 2023 -
5.2.227 Sep 2023 -
5.2.117 Jun 2023 -
5.2.012 Jun 2023Release notes
Open source →What's Changed
- 新增
Pinyin::polyphonesAsArray方法,支持多音字逐字返回,#195 - Update phpunit/phpunit requirement from ^9.5 to ^10.1 by @dependabot in #192
Full Changelog: 5.1.1...5.2.0
Release notes
Open source →🚀 Features
- 增加 Pinyin::polyphonesAsArray. fixed #195
📚 Documentation
- 更新文档提示
- 更新文档提示
- 更新文档提示
- 新增
-
5.1.127 Apr 2023Nothing published for this version
-
5.1.027 Apr 2023 -
5.0.024 Jul 2022 -
4.1.027 Apr 2023Nothing published for this version
-
4.0.819 Jul 2021Nothing published for this version
-
4.0.716 Apr 2021Nothing published for this version
-
4.0.613 Apr 2020Nothing published for this version
-
4.0.520 Sep 2019Nothing published for this version
-
4.0.417 Sep 2019Nothing published for this version
-
4.0.321 Apr 2019Nothing published for this version
-
4.0.221 Apr 2019Nothing published for this version
-
4.0.111 Jan 2019Nothing published for this version
-
4.0.020 Sep 2018Nothing published for this version
-
3.0.610 Jul 2017Nothing published for this version
-
3.0.527 Feb 2017Nothing published for this version
-
3.0.417 Aug 2016Nothing published for this version
-
3.0.313 Jun 2016Nothing published for this version
-
3.0.222 May 2016Nothing published for this version
-
3.0.118 May 2016Nothing published for this version
-
3.0.025 Apr 2016Nothing published for this version
-
2.6.805 Apr 2016Nothing published for this version
-
2.6.719 Jan 2016Nothing published for this version
-
2.6.518 Jan 2016Nothing published for this version
-
2.6.422 Dec 2015Nothing published for this version
-
2.6.328 Oct 2015Nothing published for this version
-
2.6.221 Oct 2015Nothing published for this version
-
2.6.104 Sep 2015Nothing published for this version
-
2.6.001 Aug 2015Nothing published for this version
-
2.5.425 Jul 2015Nothing published for this version
-
2.5.302 Jul 2015Nothing published for this version
-
2.5.201 Jun 2015Nothing published for this version
-
2.5.128 Apr 2015Nothing published for this version
-
2.5.016 Mar 2015Nothing published for this version
-
2.4.114 Jan 2015Nothing published for this version
-
2.4.025 Dec 2014Nothing published for this version
-
2.3.127 Nov 2014Nothing published for this version
-
2.3.026 Nov 2014Nothing published for this version
-
2.2.122 Nov 2014Nothing published for this version
-
v2.008 Oct 2014Nothing published for this version
-
2.222 Nov 2014Nothing published for this version
-
2.102 Nov 2014Nothing published for this version
-
1.406 Oct 2014Nothing published for this version
-
1.306 Oct 2014Nothing published for this version
-
1.116 Jul 2014Nothing published for this version
-
1.0-beta16 Jul 2014Nothing published for this version
-
1.016 Jul 2014Nothing published for this version