小程序--语音合成tts 对接多平台(讯飞,思必驰,百度)
小程序功能特点
- 文本转语音
- 多平台多发音人可选
- 可调语速
- 可提供音频下载
- 良心产品无广告?
小程序码
已对接在线语音识别服务
- 思必驰dui平台 (超过40个免费可选发音人)
- 讯飞开放平台 (5个免费可选发音人)
- 百度语音(4个免费发音人可选)
小程序截图
服务端主要代码
class TTSController extends Controller {async tts () {let params = this.ctx.querylet result = null// 根据plat参数来调用不同的接口if (params.plat === 'xf') {result = await this.ctx.service.xftts.getTts(params)} else if (params.plat === 'baidu') {result = await this.ctx.service.baidutts.getTts(params)} else {result = await this.ctx.service.aispeechtts.getTts(params)}// 设置response的类型,这样客户端接收到的就是一个文件流this.ctx.response.type = 'audio/mpeg'this.ctx.body = result}
}
复制代码
小程序客户端template代码(使用的mpvue)
<template><div class="container"><div class="preview"><textarea :class="textAreaFocus? 'focus' : ''" auto-height @focus="bindTextAreaFocus" @blur="bindTextAreaBlur" placeholder="请输入文本" v-model="text" maxlength="256"/></div><div class="setting"><picker @change="bindPlatChange" v-model="platIndex" range-key="name" :range="platArr"><div class="item"><div class="label">选择平台</div><div class="value voice">{{platArr[platIndex].name}}</div></div></picker><picker @change="bindPickerChange" v-model="index" range-key="name" :range="array"><div class="item"><div class="label">选择发音人</div><div class="value voice">{{array[index].name}}</div></div></picker><div class="item speed"><div class="label">调节语速</div><div class="value"><slider @change="onSpeedChange" :value="speedObj.default" :step='speedObj.step' activeColor="#6F8FFF" :min="speedObj.min" :max="speedObj.max" show-value /></div></div></div><div style="height: 140rpx;"><div class="btn-group"><div class="item"><button @click="audioPlay" type="main">播放合成语音</button> </div><div class="item"> <button @click="audioDownload" type="submain">复制链接下载</button> </div></div></div><div class="desc">说明:tts是英文 text to speech的缩写,即文本转语音技术<contact-button type="default-light"session-from="weapp">联系客服</contact-button></div></div>
</template>
复制代码
script 代码
<script>
import voiceIdArray from './voiceIdArray'export default {data () {return {array: voiceIdArray.aispeech,platArr: [{id: 'xf', name: '科大讯飞'}, {id: 'aispeech', name: '思必驰'}, {id: 'baidu', name: '百度'}],platIndex: 1,index: 26,text: `改革春风吹满地,吹满地,春风吹满地。\n中国人民真争气,真争气,人民真争气。\n这个世界太疯狂,耗子都给猫当伴娘。\n齐德隆,齐东强。\n齐德隆的咚得隆咚锵。`,voiceId: 'lili1f_diantai',speed: 1,textAreaFocus: false,audioCtx: null,ttsServer: 'https://tts.server.com',audioSrc: '',downloadUrl: '',xfSpeedObj: {min: 0,max: 100,default: 50,step: 1},aispeechSpeedObj: {min: 0.7,max: 2,default: 1,step: 0.1},baiduSpeedObj: {min: 0,max: 9,default: 5,step: 1},speedObj: {}}},watch: {platIndex (newVal, oldVal) {if (newVal === 2) {this.array = voiceIdArray.baiduthis.index = 0this.speedObj = this.baiduSpeedObj}if (newVal === 1) {this.array = voiceIdArray.aispeechthis.index = 26this.speedObj = this.aispeechSpeedObj}if (newVal === 0) {this.array = voiceIdArray.xfthis.index = 0this.speedObj = this.xfSpeedObj}}},onShareAppMessage () {return {title: '文本转语音服务,多发音人可选'}},methods: {onSpeedChange (e) {this.speedObj.default = e.target.value},bindPlatChange (e) {this.platIndex = e.target.value * 1},bindPickerChange (e) {this.index = e.target.value},getAudioSrc () {if (this.text === '') {return false}const speed = this.speedObj.defaultconst voiceId = this.array[this.index].idconst plat = this.platArr[this.platIndex].idreturn encodeURI(`${this.ttsServer}/tts?plat=${plat}&voiceId=${voiceId}&speed=${speed}&text=${this.text}`)},getDownloadUrl () {const plat = this.platArr[this.platIndex].idconst voiceId = this.array[this.index].idwx.showLoading({title: '加载中'})wx.request({url: 'https://tts.server.com/getdownloadurl',data: {plat: plat,voiceId: voiceId,speed: this.speedObj.default,text: this.text},header: {'content-type': 'application/json' // 默认值},success (res) {wx.hideLoading()wx.setClipboardData({data: res.data.short_url,success (res) {wx.showToast({title: '链接已复制请用浏览器下载(ios端无法下载)',icon: 'none',duration: 3000})}})}})},audioPlay () {this.audioCtx.src = this.getAudioSrc()if (!this.audioCtx.src) {wx.showToast({title: '请先输入文本',icon: 'none',duration: 2000})return false}wx.showLoading({title: '加载中'})this.audioCtx.play()},audioDownload () {this.getDownloadUrl()},bindTextAreaBlur (e) {this.textAreaFocus = falsethis.text = e.target.value},bindTextAreaFocus () {this.textAreaFocus = true}},created () {this.speedObj = this.aispeechSpeedObj},mounted () {this.audioCtx = wx.createInnerAudioContext()this.audioCtx.onEnded((res) => {wx.hideLoading()})this.audioCtx.onPlay((res) => {wx.hideLoading()})wx.showShareMenu({withShareTicket: true})}
}
</script>
复制代码
接口对接过程中,百度的是最方便的因为有sdk可以直接使用,讯飞的最麻烦需要自己做参数加密,思必驰dui的虽然没提供SDK但是文档写的比较详细对接过程也很方便快速。
目前无法解决的就是,小程序内无法直接下载的问题,只能提供链接,然后用户自己打开浏览器进行下载(iPhone似乎无解)。
转载于:https://juejin.im/post/5c413f48f265da616e4cb1d0
小程序--语音合成tts 对接多平台(讯飞,思必驰,百度)相关推荐
- 思必驰成立2亿基金,扶持DUI平台优秀开发者
AI科技大本营9月7日讯 在思必驰大音希声发布会上,思必驰CEO高始兴正式对外发布DUI平台. DUI平台是为物联网.移动互联网还有互联网的开发者提供超高度定制更自由的对话定制的一个平台,它的本质定位 ...
- 凡泰极客 FinClip 技术已实现小程序多端口、全平台运行
近日,凡泰极客旗下核心产品 FinClip 技术正式宣布支持 Linux 平台运行.此前,FinClip 技术已先后支持 Windows.Mac 等平台运行.至此,FinClip 技术已实现小程序代码 ...
- 一个小程序的首页对接后端实现用户注册
一个小程序的首页对接后端实现用户注册 //index.js //获取应用实例 const app = getApp()Page({globalData: {appid: 'wx4abc8f71681a ...
- 新版知识付费系统付费阅读小程序源码知识付费平台
介绍: 2021知识付费系统付费阅读小程序源码知识付费平台源码. 知识付费的小程序源码的作用我就不多说了,现在都是知识付费的年代,也是付费学习的时代. 知识付费阅读小程序,带有代理,分销,课程资源更新 ...
- ssm基于微信小程序的学习资料销售平台+ssm+uinapp+Mysql+计算机毕业设计
本微信小程序的学习资料销售平台以ssm作为框架,b/s模式以及MySql作为后台运行的数据库,同时使用Tomcat用为系统的服务器.本系统主要包括以下功能模块:首页.个人中心.用户管理.资料类型管理. ...
- 计算机毕业设计PHP基于微信小程序寸金校园租车平台(源码+程序+uni+lw+部署)
该项目含有源码.文档.程序.数据库.配套开发软件.软件安装教程.欢迎交流 项目运行 环境配置: phpStudy+ Vscode +Mysql5.7 + HBuilderX+Navicat11+Vue ...
- springboot+vue基本微信小程序的疫情防控平台系统 计算机毕业设计
本文讲述了基于微信小程序的疫情防控平台系统的设计与实现.结合电子管理系统的特点,分析了疫情防控平台系统的现状,给出了基于微信小程序的疫情防控平台系统实现的设计方案.本论文主要完成不同用户的权限划分,不 ...
- 计算机毕业设计(88)php小程序毕设作品之小说平台小程序系统
项目背景和意义 目的:本课题主要目标是设计并能够实现一个基于微信小程序的在线免费小说平台,前台用户使用小程序,后台管理使用基PHP+MySql的B/S架构:管理员通过后台录入作者信息,发布资讯,管理会 ...
- 【物联网】微信小程序接入阿里云物联网平台
微信小程序接入阿里云物联网平台 一 阿里云平台端 1.登录阿里云 阿里云物联网平台 点击进入公共实例,之前没有的点进去申请 2.点击产品->创建产品 3.产品名称自定义,按项目选择类型,节点类型 ...
最新文章
- Js 对小数的处理(科学计数法 , 显示精度)
- 当前不会命中断点 源代码与原始版本不一致
- 一文讲懂什么是三层交换机、网关、DNS、子网掩码、MAC地址
- 巨量引擎2021食品饮料行业白皮书
- html 分页 惰性加载,懒加载实现的分页网站footer自适应
- 【linux】一次性杀死多个同名进程
- python 最小二乘回归 高斯核_[数值计算] 数据拟合——非线性最小二乘法
- 高斯过程回归GPR-MATLAB语法解释
- 在ArchLinux/Manjaro上安装BCM4360系列网卡驱动
- Docker Compose 配置文件 docker-compose.yml 详解
- No plugin found for prefix 'mybatis-generator' in the current project ORA-28040: No matching authen
- 从企业实务角度解读 ITIL4 之14个通用管理实践
- 【数模/预测】灰色预测
- 新办的卡为什么显示无服务器,为什么插入卡后显示无服务,有时有有时又没有?...
- bootstrap-列表样式
- jy-10-SPRINGMYBATIS01——MyBatis-程祖红/刘苍松
- KDD 2022时空数据挖掘领域论文汇总
- vscode css智能补全_在 Webstorm 伤透我的心后,我决定尝试 VS Code
- 周期性行业是什么意思_聊聊周期性行业 1.什么是周期性行业 周期性行业,就是指受经济周期影响较大的行业,经济低迷,行业亦表现为低迷;经济繁荣,行业也会表现得高... - 雪球...
- MySQL下载安装教程和修改密码(亲测有用)
热门文章
- BZOJ 4084 [Sdoi2015]双旋转字符串
- Oracle 恢复dmp文件到数据库表中(超大DMP) 【数据系列 3】
- 谁能够最终实现超越普通计算机的“量子霸权”
- iOS客户端实现 XMPP协议的步骤
- liferay mysql driver_liferay与mysql的联接
- Qt基础与Qt on Android入门-安晓辉-专题视频课程
- 【定时任务】Spring Boot 定时执行任务详解,每天定时几点钟执行任务
- 英雄会第一届在线编程大赛解题思路
- Oracle自治事务处理数据库OCPU可扩展性测试
- CPT模型:一种中文兼顾NLU和NLG的非平衡预训练语言模型