diff --git b/README.md a/README.md new file mode 100644 index 0000000..527d6d5 --- /dev/null +++ a/README.md @@ -0,0 +1,5 @@ +# 微信小程序 - 语音助手 + +## todo + +1. 历史记录 \ No newline at end of file diff --git b/app.js a/app.js new file mode 100644 index 0000000..99d5e94 --- /dev/null +++ a/app.js @@ -0,0 +1,27 @@ +//app.js +App({ + onLaunch: function() { + + }, + getUserInfo: function(cb) { + var that = this + if (this.globalData.userInfo) { + typeof cb == "function" && cb(this.globalData.userInfo) + } else { + //调用登录接口 + wx.login({ + success: function() { + wx.getUserInfo({ + success: function(res) { + that.globalData.userInfo = res.userInfo + typeof cb == "function" && cb(that.globalData.userInfo) + } + }) + } + }) + } + }, + globalData: { + userInfo: null + } +}); diff --git b/app.json a/app.json new file mode 100644 index 0000000..5dacca9 --- /dev/null +++ a/app.json @@ -0,0 +1,13 @@ +{ + "pages": [ + "pages/index/index", + "pages/result/result" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "文字转语音", + "navigationBarTextStyle": "black" + }, + "sitemapLocation": "sitemap.json" +} \ No newline at end of file diff --git b/app.wxss a/app.wxss new file mode 100644 index 0000000..2ca0051 --- /dev/null +++ a/app.wxss @@ -0,0 +1,10 @@ +/**app.wxss**/ +.container { + width: 100%; + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + box-sizing: border-box; +} diff --git b/images/logo.png a/images/logo.png new file mode 100644 index 0000000..99f8dc4 --- /dev/null +++ a/images/logo.png diff --git b/images/logo1.png a/images/logo1.png new file mode 100644 index 0000000..af28ea0 --- /dev/null +++ a/images/logo1.png diff --git b/images/logo2.png a/images/logo2.png new file mode 100644 index 0000000..7564cfe --- /dev/null +++ a/images/logo2.png diff --git b/pages/index/index.js a/pages/index/index.js new file mode 100644 index 0000000..fb439ae --- /dev/null +++ a/pages/index/index.js @@ -0,0 +1,94 @@ +//index.js +//获取应用实例 +const app = getApp(); +const storageKey = 'audioTypeselectedIndex'; +const selectedIndex = wx.getStorageSync(storageKey); +const type = [ + { + desc: '男声一', + createUrl(text){ + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=1` + } + }, + { + desc: '男声二', + createUrl(text){ + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=4` + } + }, + { + desc: '女声一', + createUrl(text){ + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=2` + } + }, + { + desc: '女声二', + createUrl(text){ + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=3` + } + }, + { + desc: '女声三', + createUrl(text){ + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=5` + } + }, + { + desc: '女声四', + createUrl(text){ + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=6` + } + }, + { + desc: '女声五', + createUrl(text){ + return `https://tts.youdao.com/fanyivoice?word=${text}&le=zh&keyfrom=speaker-target` + } + } +]; + +let audio = null; + +Page({ + data: { + placeholder: '点击此处输入文字', + text: '', + type, + selectedIndex: String(selectedIndex) ? selectedIndex : 5 + }, + onLoad(){ + wx.showShareMenu(); + }, + inputText(e){ + this.data.text = e.detail.value; + }, + play(){ + const text = this.data.text || this.data.placeholder; + this.resetAudio(); + audio = wx.createInnerAudioContext({useWebAudioImplement: true}); + audio.autoplay = true; + audio.src = this.data.type[this.data.selectedIndex].createUrl(text); + }, + clear(){ + this.resetAudio(); + this.setData({ + text: '' + }); + }, + resetAudio(){ + if(audio){ + audio.destroy(); + audio = null; + } + }, + selectIndex(e){ + const { index } = e.target.dataset; + this.setData({ + selectedIndex: index + }, () => { + this.play(); + }); + wx.setStorageSync(storageKey, index); + } +}); diff --git b/pages/index/index.json a/pages/index/index.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ a/pages/index/index.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git b/pages/index/index.wxml a/pages/index/index.wxml new file mode 100644 index 0000000..cf348b2 --- /dev/null +++ a/pages/index/index.wxml @@ -0,0 +1,29 @@ + + + +