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

插件申请

在小程序官方申请同声传译插件,地址:
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(`测试的语音合成播报`);
相关推荐
2601_949950631 小时前
考研英语资料太散?用小程序把真题、词汇和错题放到一起
人工智能·学习·考研·小程序·刷题·小程序推荐
lhldsg4 小时前
树洞倾诉的核心需求与产品定位误区
java·前端·小程序
lhldsg4 小时前
宠物同城领养平台开发实战:从需求分析到上线部署指南
java·前端·小程序·需求分析·宠物
171320330计算机毕设编程5 小时前
基于SpringBoot的在线拍卖系统
android·java·spring boot·小程序·课程设计
2501_916007475 小时前
Flutter与游戏App加固避坑指南:如何为混合开发与高交互应用选对安全方案?
安全·flutter·游戏·ios·小程序·uni-app·iphone
andrsted8 小时前
老师可以用小程序在线整理题库、课堂检测和错题集
学习·微信小程序·小程序·学习方法
show4339 小时前
2026小程序视频转文字多语种识别引擎选型:22方言25外语
小程序·音视频
学习星球1 天前
AI Agent 成本工程实战:从 OpenAI Codex 的 8 个“烧 Token“Bug 学起
人工智能·设计模式·微信小程序
律宏阔1 天前
微信小程序使用 Orval + OpenAPI 自动生成接口:Axios 兼容踩坑记录
前端·微信小程序
律宏阔1 天前
微信小程序集成 TDesign 完整记录:解决 NPM packages not found
前端·微信小程序