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

插件申请

在小程序官方申请同声传译插件,地址:
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(`测试的语音合成播报`);
相关推荐
克里斯蒂亚诺更新6 分钟前
微信小程序体验版可以获取当前位置但是正式版不可以-办法解决
微信小程序·小程序
巴巴博一11 分钟前
uni-app / 微信小程序中 open-type=“share“ 按钮样式异常,和普通 view 无法齐平的解决方案
微信小程序·uni-app·notepad++
资深前端之路13 分钟前
微信小程序节点最大限制为5000个
微信小程序·小程序
cosinmz2 小时前
PDF 发票合并经验分享:月初高效整理发票的实用方法
经验分享·小程序·pdf·pdf转换·pdf发票合并·发票合并打印
wuxia211810 小时前
微信小程序单击元素切换元素的显示和隐藏
javascript·微信小程序·setdata
2501_9160074713 小时前
前端开发常用软件与工具全面指南
android·ios·小程序·https·uni-app·iphone·webview
2501_9159090618 小时前
iOS应用性能优化:十大策略提升用户体验与开发效率
android·ios·小程序·https·uni-app·iphone·webview
2601_9567436821 小时前
上海小程序开发公司技术选型指南:Serverless架构如何影响交付质量与长期成本
云原生·小程序·架构·serverless·开发经验·上海
silvia_Anne1 天前
微信小程序之渲染商品列表
微信小程序·小程序
海兰2 天前
【文字三国志:第六篇】天命重构,UI组件设计细节
人工智能·ui·语言模型·小程序