npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zh-keyboard/recognizer

v1.1.1

Published

中文手写汉字识别器组件

Readme

@zh-keyboard/recognizer | 中文手写识别模块

License

中文虚拟键盘组件库的手写识别模块

功能特点

  • ✏️ 实时手写汉字识别
  • 🔧 可自定义识别模型和字典
  • 🚀 识别速度快,纯cpu模式200ms内,可选webgl加速
  • 📚 内置支持GB2312标准中的3755个一级汉字的识别支持
  • 🔄 更多文字识别支持(包括二级汉字、生僻字等)暂不开放

🤝 手写识别模型说明

手写识别模型由我的一个朋友提供

如果您需要包括二级汉字、生僻字等的更完整的手写识别模型,以及更多的定制服务,请扫描下方二维码添加我朋友的QQ进行咨询:

安装

# 使用npm
npm install @zh-keyboard/recognizer

# 或使用pnpm
pnpm add @zh-keyboard/recognizer

基本用法

import { ZhkRecognizer } from '@zh-keyboard/recognizer'
// 如果需要使用WebGL后端,需要手动引入
import '@tensorflow/tfjs-backend-webgl'

// 创建识别器实例
const recognizer = new ZhkRecognizer({
  modelPath: '/models/handwrite/model.json', // TensorFlow.js模型路径
  dictPath: '/models/dict.txt', // 汉字字典路径
  backend: 'webgl' // 可选:'webgl'或'cpu',默认为'cpu'
})

// 初始化识别器(加载模型和字典)
await recognizer.initialize()

// 使用识别器识别手写汉字
// strokeData格式:[x1, y1, isEnd1, x2, y2, isEnd2, ...]
// isEnd为0表示笔画继续,为1表示笔画结束
const strokeData = [10, 10, 0, 20, 20, 1,]
const results = await recognizer.recognize(strokeData)

// 识别结果是按置信度排序的汉字数组
console.log('识别结果:', results) // 例如 ['中', '申', '由', ...]

// 使用完毕后释放资源
await recognizer.close()

参数

  • options: 配置对象
    • modelPath: 模型文件路径,指向TensorFlow.js模型的json文件
    • dictPath: 字典文件路径,文本文件,每行一个汉字
    • backend: 可选,TensorFlow.js后端类型,可选值为'webgl'或'cpu',默认为'cpu'

性能优化

  • 在支持WebGL的设备上使用'webgl'后端可以显著提高识别速度
  • 注意:使用WebGL后端时,需要手动引入 import '@tensorflow/tfjs-backend-webgl'
  • 初始化时会自动进行模型预热,减少首次识别的延迟
  • 如果在移动设备上使用,建议使用较小的模型以提高响应速度