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

插件申请

在小程序官方申请同声传译插件,地址:
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(`测试的语音合成播报`);
相关推荐
2501_915909063 小时前
原生与 H5 共存情况下的测试思路,混合开发 App 的实际测试场景
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者84 小时前
了解 Xcode 在 iOS 开发中的作用和功能有哪些
android·ios·小程序·https·uni-app·iphone·webview
漏刻有时7 小时前
微信小程序学习实录14:微信小程序手写签名功能完整开发方案
学习·微信小程序·notepad++
说私域9 小时前
全民电商时代下的链动2+1模式与S2B2C商城小程序:社交裂变与供应链协同的营销革命
开发语言·人工智能·小程序·php·流量运营
2501_915106329 小时前
iOS 抓包工具实战实践指南,围绕代理抓包、数据流抓包和拦截器等常见工具
android·ios·小程序·https·uni-app·iphone·webview
莫桐9 小时前
微信小程序tab模块滚动至顶部导航栏置顶效果实现
微信小程序·小程序
sheji34169 小时前
【开题答辩全过程】以 基于微信小程序健康跑平台的设计与实现为例,包含答辩的问题和答案
微信小程序·小程序
棒棒的唐9 小时前
适合小程序使用的将对象数组转换为参数字符串方法
前端·javascript·小程序
努力学前端Hang10 小时前
微信小程序安装tdsign组件库
微信小程序·小程序
2501_9151063210 小时前
如何在 iOS 设备上理解和分析 CPU 使用率(windows环境)
android·ios·小程序·https·uni-app·iphone·webview