微信小程序文字转语音播报案例

插件申请

在小程序官方申请同声传译插件,地址:
mp.weixin.qq.com

引入插件

在app.json中加入

javascript 复制代码
 "plugins": {
    "WechatSI": {
      "version": "0.3.6",
      "provider": "wx069ba97219f66d99"
    }
  },

封装公共类

如page.js

javascript 复制代码
var pluginSI = requirePlugin("WechatSI");
var innerAudioSI = wx.createInnerAudioContext();
/**
     * 文字转语音
     * @author tj
     * @param string text 
     */
    textPlayer(text) {
        pluginSI.textToSpeech({
            lang: "zh_CN",
            tts: true,
            content: text,
            success: function (res) {
                console.log("succ tts", res.filename)
                innerAudioSI.src = res.filename;
                innerAudioSI.play();
            },
            fail: function (res) {
                console.log("fail tts", res)
            }
        });
        return innerAudioSI;
    }

在js文件中调用

javascript 复制代码
getApp().page.textPlayer(`测试的语音合成播报`);
相关推荐
爱学习 爱分享9 分钟前
微信小程序html 在 webview 会打开再缩放一下
微信小程序·小程序·html
梦梦代码精1 小时前
深度拆解:上门按摩系统如何成为本地生活“到家时代”的新引擎?
docker·小程序·uni-app·开源·生活·开源软件
Geek_Vison3 小时前
如何借助小程序容器技术实现跨端APP的敏捷开发
小程序·apache·敏捷流程
xshirleyl3 小时前
微信小程序开发week6-慕尚花坊项目
微信小程序·小程序
usdoc文档预览3 小时前
国产化踩坑:Vue3 / React / 小程序如何免插件实现 OFD 及复杂 Office 文档同屏预览
前端·javascript·react.js·小程序·pdf·word·office文件在线预览
倒流时光三十年3 小时前
第二章 小程序目录结构与核心文件详解
spring boot·小程序
好赞科技5 小时前
2026年八大上门服务预约小程序:解锁高效生活新体验
大数据·微信小程序
维双云5 小时前
从零到一:一份关于“做小程序的步骤”的完整实操指南
小程序
编程猪猪侠5 小时前
uni-app微信小程序车牌号输入组件实现
微信小程序·uni-app
客场消音器21 小时前
如何使用codex进行UI重构,让AI开发的前端页面不再千篇一律
前端·后端·微信小程序