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 🙏

© 2025 – Pkg Stats / Ryan Hefner

douyin-text-extractor

v1.1.2

Published

Node.js + TypeScript library for extracting text from Douyin/TikTok videos

Downloads

12

Readme

Douyin Text Extractor

一个用于解析抖音视频链接并提取视频中音频文本的 Node.js TypeScript 库。

✨ 功能特性

  • 📱 解析抖音分享链接,获取无水印视频
  • 🎵 提取音频并转换为文本
  • 🔄 支持进度回调和错误处理
  • 🧹 自动清理临时文件
  • 📦 完整的 TypeScript 类型支持

🚀 快速开始

安装

npm install douyin-text-extractor

基本使用

const { DouyinService } = require("douyin-text-extractor");

// 最简单的方式(使用默认配置)
const service = DouyinService.create("your-speech-api-key");

// 或者使用构造函数(推荐)
const service = new DouyinService({
  speechApiKey: "your-speech-api-key"
});

async function extractText() {
  const shareLink = "复制的抖音分享链接";
  
  try {
    const result = await service.extractText(shareLink, (progress) => {
      console.log(`${progress.stage}: ${progress.progress}%`);
    });
    
    console.log("提取的文本:", result.extractedText);
  } catch (error) {
    console.error("提取失败:", error.message);
  }
}

extractText();

TypeScript 支持

import { DouyinService, DouyinServiceOptions } from "douyin-text-extractor";

// 基本用法
const service = new DouyinService({
  speechApiKey: "your-api-key"
});

// 完整配置
const options: DouyinServiceOptions = {
  speechApiKey: "your-api-key",
  speechApiBaseUrl: "https://api.custom.com/v1/audio/transcriptions",
  speechModel: "whisper-1",
  autoCleanTempFiles: false
};
const service = new DouyinService(options);

// 使用工厂方法
const service1 = DouyinService.create("your-api-key");
const service2 = DouyinService.createWithSiliconFlow("your-api-key");
const service3 = DouyinService.createWithOpenAI("your-openai-key");

📖 API 文档

DouyinService

// 构造函数
new DouyinService(options)

// 工厂方法
DouyinService.create(speechApiKey)
DouyinService.createWithSiliconFlow(speechApiKey, speechModel?)
DouyinService.createWithOpenAI(speechApiKey, speechModel?)

构造选项 (DouyinServiceOptions):

  • speechApiKey (string, 必需) - 语音识别 API 密钥
  • speechApiBaseUrl (string, 可选) - API 基础URL,默认: SiliconFlow API
  • speechModel (string, 可选) - 语音识别模型,默认: FunAudioLLM/SenseVoiceSmall
  • autoCleanTempFiles (boolean, 可选) - 是否自动清理临时文件,默认: true
  • downloadDir (string, 可选) - 下载目录,默认: ./downloads
  • tempDir (string, 可选) - 临时文件目录,默认: ./temp

主要方法:

  • parseShareUrl(shareText) - 解析分享链接
  • downloadVideo(videoInfo, progressCallback) - 下载视频
  • extractAudio(videoPath, progressCallback) - 提取音频
  • extractTextFromAudio(audioPath, progressCallback) - 音频转文本
  • extractText(shareLink, progressCallback) - 一键提取文本

⚙️ 配置

环境变量

# 语音识别 API 配置(必需)
SPEECH_API_KEY="your-api-key"
SPEECH_API_BASE_URL="https://api.siliconflow.cn/v1/audio/transcriptions"
SPEECH_MODEL="FunAudioLLM/SenseVoiceSmall"

# 文件路径配置(可选)
TEMP_DIR="./temp"
DOWNLOAD_DIR="./downloads"

# 临时文件管理(可选)
AUTO_CLEAN_TEMP_FILES="true"

# 日志配置(可选)
LOG_LEVEL="info"
LOG_FILE="./logs/app.log"

推荐配置方式

推荐直接使用构造函数,从环境变量读取配置:

// 推荐:直接构造函数配置
const service = new DouyinService({
  speechApiKey: process.env.SPEECH_API_KEY!,
  speechApiBaseUrl: process.env.SPEECH_API_BASE_URL || "https://api.siliconflow.cn/v1/audio/transcriptions",
  speechModel: process.env.SPEECH_MODEL || "FunAudioLLM/SenseVoiceSmall",
  autoCleanTempFiles: process.env.AUTO_CLEAN_TEMP_FILES !== "false",
  downloadDir: process.env.DOWNLOAD_DIR || "./downloads",
  tempDir: process.env.TEMP_DIR || "./temp"
});

// 或使用简化工厂方法
const service = DouyinService.create(process.env.SPEECH_API_KEY!);

依赖要求

  • Node.js >= 16.0.0
  • FFmpeg (音频处理)

安装 FFmpeg:

# macOS
brew install ffmpeg

# Ubuntu/Debian
sudo apt update && sudo apt install ffmpeg

🛠️ 命令行工具

项目包含完整的命令行工具,支持单个和批量处理:

# 下载视频
node scripts/douyin.js download "https://v.douyin.com/xxx"

# 提取文本
node scripts/douyin.js to-text "https://v.douyin.com/xxx"

# 批量处理
node scripts/douyin.js batch links.txt

详细说明请参考 命令行工具文档

🐳 Docker 部署

# 设置环境变量
echo "SPEECH_API_KEY=your-api-key" > .env

# 启动服务
docker-compose up -d

📚 文档

🚧 未来扩展方向

项目正在持续发展中,计划实现以下核心功能:

  • 🌐 多平台支持 - 扩展支持快手、小红书、B站等主流短视频平台
  • 📝 智能文本分析 - 集成关键词提取、内容摘要、情感分析等 AI 功能
  • ⚡ 批量处理优化 - 提升大规模视频处理的性能和稳定性
  • 🌍 多语言支持 - 支持多种语言的语音识别和文本处理

欢迎在 Issues 中讨论和建议!

🙏 致谢

感谢以下项目提供的灵感和参考:

  • douyin-mcp-server - 基于 Model Context Protocol (MCP) 的抖音视频文本提取服务器,为本项目的开发提供了宝贵的思路和参考

🤝 贡献

欢迎提交 Issue 和 Pull Request!

📄 许可证

MIT License