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

taro-voice-player

v1.0.17

Published

Taro voice player for WeChat Mini Program

Readme

Taro-Voice-Player 微信小程序语音播报库

简介

taro-voice-player 是一个专为 Taro + Vue3 项目开发的微信小程序语音播报库,提供简单易用的 API 实现文本到语音的转换功能。

功能特性

  • ✅ 支持文本语音播报
  • ✅ 可调节音量、语速
  • ✅ 支持多种语言
  • ✅ 播放控制(播放/暂停/继续/停止)
  • ✅ 自动处理微信小程序 API 调用
  • ✅ 提供 Vue3 组合式 API 和组件两种使用方式
  • ✅ 完善的 TypeScript 类型支持

安装

使用 npm 或 yarn 安装:

npm install taro-voice-player
# 或
yarn add taro-voice-player

快速开始

基本使用

import { createVoicePlayer } from 'taro-voice-player'

const player = createVoicePlayer({
  volume: 0.8,  // 音量 0-1
  lang: 'zh_CN' // 语言
})

// 播放语音
player.play('你好,欢迎使用语音播报功能')
  .then(() => console.log('播放开始'))
  .catch(err => console.error('播放失败', err))

// 暂停播放
player.pause()

// 继续播放
player.resume()

// 停止播放
player.stop()

Vue3 组合式 API 使用

import { useVoicePlayer } from 'taro-voice-player'

export default {
  setup() {
    const { player, isPlaying, isPaused } = useVoicePlayer({
      volume: 0.7,
      onEnd: () => console.log('播放结束')
    })

    const handlePlay = () => {
      player?.play('这是要播放的文本内容')
    }

    return {
      handlePlay,
      isPlaying,
      isPaused
    }
  }
}

组件方式使用

<template>
  <VoicePlayer 
    text="这是要播放的文本" 
    :options="{ volume: 0.7 }" 
  />
</template>

<script>
import { VoicePlayer } from 'taro-voice-player'

export default {
  components: {
    VoicePlayer
  }
}
</script>

API 文档

createVoicePlayer(options)

创建语音播放器实例。

参数:

  • options (Object) - 配置选项
    • volume (Number) - 音量,范围 0-1,默认 0.8
    • playbackRate (Number) - 语速,范围 0.5-2,默认 1
    • lang (String) - 语言代码,默认 'zh_CN'
    • onEnd (Function) - 播放结束回调
    • onError (Function) - 错误回调

返回值:

  • 返回 VoicePlayer 实例,包含以下方法:
    • play(text, options) - 播放文本
    • pause() - 暂停播放
    • resume() - 继续播放
    • stop() - 停止播放
    • setOptions(options) - 更新配置

useVoicePlayer(options)

Vue3 组合式 API。

参数:

  • createVoicePlayer

返回值:

  • 包含以下属性的对象:
    • player - VoicePlayer 实例
    • isPlaying (Ref) - 是否正在播放
    • isPaused (Ref) - 是否暂停
    • init() - 初始化方法

VoicePlayer 组件

Props:

  • text (String) - 必填,要播放的文本
  • options (Object) - 同 createVoicePlayer 的 options

注意事项

  1. 微信小程序需要配置合法域名:https://api.weixin.qq.com
  2. 需要在小程序后台开通语音合成相关权限
  3. 真机测试效果可能与开发者工具不同
  4. API 可能有调用频率限制

示例项目

查看完整示例:示例项目链接

贡献

欢迎提交 Issue 和 PR。

许可证

MIT