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

插件申请

在小程序官方申请同声传译插件,地址:
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(`测试的语音合成播报`);
相关推荐
zhiboshequ8 小时前
Ai音视频对话在微信小程序端的技术实现方案
人工智能·微信小程序·live-pusher·live-player·音视频对话
小蒜学长8 小时前
基于过程性评价的ai助学平台(代码+数据库+LW)
java·spring boot·后端·微信小程序·过程性评价
00后程序员张11 小时前
无需 Mac 的 iOS App 上架工具,开心上架Appuploader 负责哪些环节
android·ios·小程序·https·uni-app·iphone·webview
2501_915909061 天前
Ipa Guard 防护上架,混淆、重签名和回归测试怎么做
android·ios·小程序·https·uni-app·iphone·webview
鸿蒙开发1 天前
# 代码写完才发现不能上线:微信小程序开发前必须准备的 8 件事
微信小程序·产品经理
李纲明1 天前
微信小程序 web-view 打开空白或提示未配置业务域名:校验文件、HTTPS 与跳转域名排查
前端·微信小程序·https·web-view·小程序开发·业务域名
济南壹软网络科技有限公司1 天前
盲盒源码系统小程序V6MAX底层架构解析,PHP+Uniapp高性能商用底座发布
小程序·架构·uni-app
2501_915918411 天前
iOS 上架注意事项有哪些?Appuploader 的四个阶段自查清单
android·ios·小程序·https·uni-app·iphone·webview
Autumn_ing1 天前
AI原型设计工具怎么选?可编辑原型与可运行前端适合什么场景
前端·小程序·产品经理·代码·codex·墨刀ai客户端·ai原型
fengGer的bugs1 天前
微信小程序实战:本地存储的新生儿喂养记录(原生 + 四套主题 + 疫苗日程)
微信小程序·小程序