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

@mingto/microsoft-tts

v1.0.10

Published

借助“微软认知服务语音合成API”实现浏览器端“文本转语音

Readme

@mingto/microsoft-tts

微软 Azure 文本转语音(TTS)服务工具库,流式处理,支持多种音色和语言。

特性

  • 🎙️ 流式处理:支持流式文本合成与播放
  • 🌍 多语言支持:支持多种语言和音色
  • 🔧 灵活配置:支持自定义语音参数
  • 📱 浏览器端支持:专为浏览器环境优化
  • 🔇 静音控制:支持静音/取消静音操作

安装

pnpm add @mingto/microsoft-tts

快速开始

import microsoftTts from '@mingto/microsoft-tts'

// 配置全局参数
microsoftTts.config({
  // Azure语音服务订阅密钥
  subscriptionKey: 'your-subscriptionKey',
  // Azure语音服务区域(如"southeastasia")
  region: 'your-region',
})

// 创建应用实例
const ttsInstance = microsoftTts.create({
  voice_type: 'zh-CN-XiaoxiaoNeural',
})

// 订阅事件
ttsInstance.on('audioFirstStart', () => {
  console.log('音频首次播放')
})

ttsInstance.on('appError', (error) => {
  console.error('应用错误', error)
})

ttsInstance.on('appFinish', () => {
  console.log('应用已销毁')
})

// 开始转换
ttsInstance.start()

// 发送文本
ttsInstance.send('你好呀。')

// 结束转换(通知发送文本已经结束,但是不会销毁应用,剩余的文本将会继续播放)
ttsInstance.end()

// 销毁应用(停止播放)
// ttsInstance.finish()

// 调整音量
// ttsInstance.mute()     // 静音
// ttsInstance.unmute()   // 恢复音量

API

全局配置

microsoftTts.config(options)

配置全局参数,支持以下参数:

| 参数 | 类型 | 必填 | 说明 | |------|------|------|------| | subscriptionKey | string | 否 | Azure 语音服务订阅密钥 | | region | string | 否 | Azure 语音服务区域(如"southeastasia") |

创建应用实例

microsoftTts.create(options?)

创建 TTS 应用实例。

| 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| | voice_type | string | ❌ | 'zh-CN-XiaoxiaoNeural' | 语音名称/音色 | | region | string | ❌ | 'eastasia' | Azure 语音服务区域 | | volume | number | ❌ | 100 | 音量,范围 0.0-100.0 | | outputFormat | SpeechSynthesisOutputFormat | ❌ | - | 音频输出格式 | | language | string | ❌ | 'zh-CN' | 语言区域 |

实例方法

ttsInstance.start()

激活应用,准备接收文本进行语音播放。

ttsInstance.start()

ttsInstance.send(text)

发送文本进行语音合成。

ttsInstance.send('你好呀。')

ttsInstance.end()

通知应用发送文本已经结束,但是不会销毁应用,剩余的文本将会继续播放。

ttsInstance.end()

ttsInstance.finish()

应用播放结束,应用将会被销毁,剩余的文本将会停止播放。

ttsInstance.finish()

ttsInstance.mute()

静音当前音频输出。

ttsInstance.mute()

ttsInstance.unmute()

取消静音,恢复音频输出。

ttsInstance.unmute()

ttsInstance.on(eventName, callback)

订阅应用事件,获取播放开始、错误、结束等通知。

ttsInstance.on('audioFirstStart', () => {
  console.log('音频首次播放')
})

应用事件

| 事件名 | 触发时机 | 说明 | |--------|----------|------| | audioFirstStart | 音频首次播放时触发 | 首次播放提示 | | appError | 应用发生错误时触发 | 携带错误信息 | | appFinish | 调用 finish() 或流程结束时触发 | 应用结束事件 |

事件示例

ttsInstance.on('audioFirstStart', () => {
  console.log('音频首次播放')
})

ttsInstance.on('appError', (error) => {
  console.error('应用错误', error)
})

ttsInstance.on('appFinish', () => {
  console.log('应用已销毁')
})

流式文本处理示例

import microsoftTts from '@mingto/microsoft-tts'

microsoftTts.config()

const ttsInstance = microsoftTts.create({
  voice_type: 'zh-CN-XiaoxiaoNeural'
})

ttsInstance
  .on('appFinish', () => console.log('appFinish'))
  .on('audioFirstStart', () => console.log('audioFirstStart'))

const arrText = ['你要抱', '抱我吗?', '我好', '喜欢你呀!']
let index = 0
ttsInstance.start()

const timer = setInterval(() => {
  ttsInstance.send(arrText[index])
  index += 1
  if (index === arrText.length) {
    ttsInstance.end()
    clearInterval(timer)
  }
}, 100)

推荐音色

中文常用音色

  • zh-CN-XiaoxiaoNeural - 晓晓(女声)
  • zh-CN-YunxiNeural - 云希(男声)
  • zh-CN-YunyangNeural - 云扬(男声)
  • zh-HK-HiuMaanNeural - 香港粤语女声
  • zh-TW-HsiaoChenNeural - 台湾女声

许可证

MIT