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

插件申请

在小程序官方申请同声传译插件,地址:
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(`测试的语音合成播报`);
相关推荐
万岳科技系统开发12 小时前
付费知识系统源码的整体架构设计与模块划分
java·数据库·小程序
2501_9159214312 小时前
iOS App 中 SSL Pinning 场景下代理抓包失效的原因
android·网络协议·ios·小程序·uni-app·iphone·ssl
一品威客爱开发12 小时前
情绪识别技术优化客服 App 体验:让服务更贴心高效!
小程序
Brduino脑机接口技术答疑15 小时前
SSVEP 脑电小程序说明
人工智能·机器学习·小程序·脑机接口
hello kitty w16 小时前
1.标签定义
小程序
说私域16 小时前
点状打法在电商与社群空间中的创新实践:基于开源链动2+1模式AI智能名片S2B2C商城小程序的探索
人工智能·小程序·开源
OctShop大型商城源码16 小时前
免费开源大型多用户多商家小程序电商系统源码_OctShop
微信小程序·小程序·开源·小程序电商系统·多用户商城系统
2501_9160088916 小时前
在 Windows 上使用开心上架(Appuploader)在 Windows 环境下创建与管理 iOS 证书
android·ios·小程序·https·uni-app·iphone·webview
小白变怪兽16 小时前
微信小程序页面中监听globalData数据变化
微信小程序·小程序
计算机毕设指导616 小时前
基于微信小程序的烧烤店点餐和结账系统【源码文末联系】
java·spring·微信小程序·小程序·tomcat·maven·intellij-idea