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

@tdh-keyboard/recognizer

v1.0.10

Published

中文手写汉字识别器组件

Readme

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

@tdh-keyboard/recognizer 是中文虚拟键盘组件库的手写识别模块,提供可直接注册到键盘组件中的 TdhRecognizer 实现。

功能特点

  • ✏️ 实时手写汉字识别
  • 🔧 可自定义识别模型和字典
  • 🚀 支持 CPU 模式,可按需启用 WebGL 加速
  • 📚 内置支持 GB2312 一级汉字识别模型接入

安装

npm install @tdh-keyboard/recognizer

导出内容

  • TdhRecognizer:默认手写识别器实现
  • RecognizerOptions:构造参数类型

基本用法

import { TdhRecognizer } from '@tdh-keyboard/recognizer'
import '@tensorflow/tfjs-backend-webgl'

const recognizer = new TdhRecognizer({
  modelPath: '/models/handwrite/model.json',
  dictPath: '/models/dict.txt',
  backend: 'webgl',
})

await recognizer.initialize()

const strokeData = [10, 10, 0, 20, 20, 1]
const results = await recognizer.recognize(strokeData)

console.log(results)

await recognizer.close()

参数

RecognizerOptions 支持以下字段:

  • modelPath:TensorFlow.js 模型路径
  • dictPath:汉字字典路径,文本文件,每行一个汉字
  • backend:可选,'webgl' | 'cpu',默认 'cpu'

初始化

initialize(options?) 支持来自 @tdh-keyboard/core 的初始化参数:

  • onProgress(progress):模型加载进度回调,范围为 01

识别输入格式

recognize(strokeData) 需要接收如下格式的笔迹数组:

[x1, y1, c1, x2, y2, c2, ...]

其中:

  • xy 是坐标
  • c 表示该点是否是当前笔画最后一点
  • 0 表示笔画继续
  • 1 表示笔画结束

与键盘组件配合使用

import { registerHandwritingRecognizer } from '@tdh-keyboard/vue'
import { TdhRecognizer } from '@tdh-keyboard/recognizer'

registerHandwritingRecognizer(new TdhRecognizer({
  modelPath: '/models/handwrite/model.json',
  dictPath: '/models/dict.txt',
}))

性能建议

  • 在支持 WebGL 的设备上,可通过 backend: 'webgl' 提高识别速度
  • 使用 WebGL 后端时,需要手动引入 @tensorflow/tfjs-backend-webgl
  • 初始化阶段会加载模型和字典,建议在应用启动或键盘首次使用前完成