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

插件申请

在小程序官方申请同声传译插件,地址:
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(`测试的语音合成播报`);
相关推荐
项目題供诗28 分钟前
微信小程序黑马优购(项目)(八)
微信小程序·小程序
2501_9159184142 分钟前
iOS 项目中证书管理常见的协作问题
android·ios·小程序·https·uni-app·iphone·webview
2501_915918411 小时前
提升 iOS 应用安全审核通过率的一种思路,把容易被拒的点先处理
android·安全·ios·小程序·uni-app·iphone·webview
00后程序员张1 小时前
APP如何快速上架Apple Store:完整上架流程与常见问题解析
android·小程序·https·uni-app·iphone·webview
Chloe.Zz1 小时前
微信小程序接入大模型实战 4:塔罗咨询室(含代码)
语言模型·微信小程序·小程序
2501_916008892 小时前
iOS 应用发布流程中常被忽视的关键环节
android·ios·小程序·https·uni-app·iphone·webview
Q_Q5110082852 小时前
小程序基于Java Web的健身房管理系统设计和开发
java·前端·小程序
艾上编程2 小时前
第四章——桌面小程序场景之使用Tkinter制作文件格式转换器:满足日常格式转换需求
开发语言·小程序
风月歌2 小时前
小程序项目之“健康早知道”微信小程序源码(java+小程序+mysql)
java·微信小程序·小程序·毕业设计·源码
speedoooo11 小时前
在现有App里嵌入一个AI协作者
前端·ui·小程序·前端框架·web app