Commit 339f8f40edc818959c71af6290806b20f5f1fc5b

Authored by xwenliang
0 parents

init

README.md 0 → 100644
  1 +++ a/README.md
  1 +# 微信小程序 - 语音助手
  2 +
  3 +## todo
  4 +
  5 +1. 历史记录
0 6 \ No newline at end of file
... ...
app.js 0 → 100644
  1 +++ a/app.js
  1 +//app.js
  2 +App({
  3 + onLaunch: function() {
  4 +
  5 + },
  6 + getUserInfo: function(cb) {
  7 + var that = this
  8 + if (this.globalData.userInfo) {
  9 + typeof cb == "function" && cb(this.globalData.userInfo)
  10 + } else {
  11 + //调用登录接口
  12 + wx.login({
  13 + success: function() {
  14 + wx.getUserInfo({
  15 + success: function(res) {
  16 + that.globalData.userInfo = res.userInfo
  17 + typeof cb == "function" && cb(that.globalData.userInfo)
  18 + }
  19 + })
  20 + }
  21 + })
  22 + }
  23 + },
  24 + globalData: {
  25 + userInfo: null
  26 + }
  27 +});
... ...
app.json 0 → 100644
  1 +++ a/app.json
  1 +{
  2 + "pages": [
  3 + "pages/index/index",
  4 + "pages/result/result"
  5 + ],
  6 + "window": {
  7 + "backgroundTextStyle": "light",
  8 + "navigationBarBackgroundColor": "#fff",
  9 + "navigationBarTitleText": "文字转语音",
  10 + "navigationBarTextStyle": "black"
  11 + },
  12 + "sitemapLocation": "sitemap.json"
  13 +}
0 14 \ No newline at end of file
... ...
app.wxss 0 → 100644
  1 +++ a/app.wxss
  1 +/**app.wxss**/
  2 +.container {
  3 + width: 100%;
  4 + height: 100%;
  5 + display: flex;
  6 + flex-direction: column;
  7 + align-items: center;
  8 + justify-content: space-between;
  9 + box-sizing: border-box;
  10 +}
... ...
images/logo.png 0 → 100644

21.3 KB

images/logo1.png 0 → 100644

13.2 KB

images/logo2.png 0 → 100644

1.7 KB

pages/index/index.js 0 → 100644
  1 +++ a/pages/index/index.js
  1 +//index.js
  2 +//获取应用实例
  3 +const app = getApp();
  4 +const storageKey = 'audioTypeselectedIndex';
  5 +const selectedIndex = wx.getStorageSync(storageKey);
  6 +const type = [
  7 + {
  8 + desc: '男声一',
  9 + createUrl(text){
  10 + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=1`
  11 + }
  12 + },
  13 + {
  14 + desc: '男声二',
  15 + createUrl(text){
  16 + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=4`
  17 + }
  18 + },
  19 + {
  20 + desc: '女声一',
  21 + createUrl(text){
  22 + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=2`
  23 + }
  24 + },
  25 + {
  26 + desc: '女声二',
  27 + createUrl(text){
  28 + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=3`
  29 + }
  30 + },
  31 + {
  32 + desc: '女声三',
  33 + createUrl(text){
  34 + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=5`
  35 + }
  36 + },
  37 + {
  38 + desc: '女声四',
  39 + createUrl(text){
  40 + return `https://fanyi.sogou.com/reventondc/synthesis?text=${text}&speed=1&lang=zh-CHS&from=translateweb&speaker=6`
  41 + }
  42 + },
  43 + {
  44 + desc: '女声五',
  45 + createUrl(text){
  46 + return `https://tts.youdao.com/fanyivoice?word=${text}&le=zh&keyfrom=speaker-target`
  47 + }
  48 + }
  49 +];
  50 +
  51 +let audio = null;
  52 +
  53 +Page({
  54 + data: {
  55 + placeholder: '点击此处输入文字',
  56 + text: '',
  57 + type,
  58 + selectedIndex: String(selectedIndex) ? selectedIndex : 5
  59 + },
  60 + onLoad(){
  61 + wx.showShareMenu();
  62 + },
  63 + inputText(e){
  64 + this.data.text = e.detail.value;
  65 + },
  66 + play(){
  67 + const text = this.data.text || this.data.placeholder;
  68 + this.resetAudio();
  69 + audio = wx.createInnerAudioContext({useWebAudioImplement: true});
  70 + audio.autoplay = true;
  71 + audio.src = this.data.type[this.data.selectedIndex].createUrl(text);
  72 + },
  73 + clear(){
  74 + this.resetAudio();
  75 + this.setData({
  76 + text: ''
  77 + });
  78 + },
  79 + resetAudio(){
  80 + if(audio){
  81 + audio.destroy();
  82 + audio = null;
  83 + }
  84 + },
  85 + selectIndex(e){
  86 + const { index } = e.target.dataset;
  87 + this.setData({
  88 + selectedIndex: index
  89 + }, () => {
  90 + this.play();
  91 + });
  92 + wx.setStorageSync(storageKey, index);
  93 + }
  94 +});
... ...
pages/index/index.json 0 → 100644
  1 +++ a/pages/index/index.json
  1 +{}
0 2 \ No newline at end of file
... ...
pages/index/index.wxml 0 → 100644
  1 +++ a/pages/index/index.wxml
  1 +<!--index.wxml-->
  2 +<view class="container">
  3 + <view class="text-view">
  4 + <textarea
  5 + auto-focus
  6 + class="text-area"
  7 + placeholder="{{placeholder}}"
  8 + confirm-type="done"
  9 + bindconfirm="play"
  10 + bindinput="inputText"
  11 + value="{{text}}"
  12 + />
  13 + </view>
  14 + <view class="button-view">
  15 + <button bindtap="play" class="button" type="primary" size="mini"> 播放 </button>
  16 + <button bindtap="clear" class="button" type="default" size="mini"> 清空 </button>
  17 + </view>
  18 + <view class="type-view">
  19 + <button
  20 + wx:for="{{type}}"
  21 + wx:key="desc"
  22 + bindtap="selectIndex"
  23 + class="button"
  24 + data-index="{{index}}"
  25 + type="{{index === selectedIndex ? 'primary' : 'default'}}"
  26 + size="mini"
  27 + > {{item.desc}} </button>
  28 + </view>
  29 +</view>
... ...
pages/index/index.wxss 0 → 100644
  1 +++ a/pages/index/index.wxss
  1 +/**index.wxss**/
  2 +
  3 +.text-view{
  4 + width: 100%;
  5 + text-align: center;
  6 +}
  7 +.text-area{
  8 + width: 95%;
  9 + padding: 5rpx 10rpx;
  10 + text-align: left;
  11 + box-sizing: border-box;
  12 + display: inline-block;
  13 + border: 1rpx dashed #afafaf;
  14 +}
  15 +
  16 +.button-view{
  17 + width: 100%;
  18 + margin-top: 20rpx;
  19 + text-align: center;
  20 +}
  21 +.button-view button{
  22 + width: 95%;
  23 + display: inline-block;
  24 + height: 92rpx;
  25 + line-height: 92rpx;
  26 + font-size: 36rpx;
  27 + text-align: center;
  28 +}
  29 +
  30 +.type-view{
  31 + width: 95%;
  32 + margin-top: 40rpx;
  33 + display: flex;
  34 + justify-content: space-between;
  35 +}
  36 +.type-view button{
  37 + padding: 20rpx 10rpx;
  38 + writing-mode: vertical-lr;
  39 + text-align: center;
  40 + letter-spacing: 15rpx;
  41 +}
0 42 \ No newline at end of file
... ...
pages/result/result.js 0 → 100644
  1 +++ a/pages/result/result.js
  1 +Page({
  2 + data: {
  3 + total: '',
  4 + benefit: '',
  5 + diff: ''
  6 + },
  7 + onLoad: function(options){
  8 + var total = new Number((options.price*2*options.days).toFixed(2));
  9 + var benefit = isNaN(total) ? 0 : this.calc(total).toFixed(2);
  10 + this.setData({
  11 + total: isNaN(total) ? 0 : total.toFixed(2),
  12 + benefit: benefit,
  13 + diff: (total - benefit).toFixed(2)
  14 + });
  15 + wx.showShareMenu();
  16 + },
  17 + calc: function(fee){
  18 + //662.5 = 100 + 50/0.8 + 250/0.5
  19 + if(fee > 662.5){
  20 + return fee - 262.5;
  21 + }
  22 + //162.5 = 100 + 50/0.8
  23 + else if(fee > 162.5){
  24 + //(fee - 162.5)/2 + 150;
  25 + return fee/2 + 68.75;
  26 + }
  27 + else if(fee > 100){
  28 + //(fee - 100)*0.8 + 100;
  29 + return fee*0.8 + 20;
  30 + }
  31 + else{
  32 + return fee;
  33 + }
  34 + }
  35 +});
0 36 \ No newline at end of file
... ...
pages/result/result.json 0 → 100644
  1 +++ a/pages/result/result.json
  1 +{}
0 2 \ No newline at end of file
... ...
pages/result/result.wxml 0 → 100644
  1 +++ a/pages/result/result.wxml
  1 +<view class="text-view border">
  2 + <text class="label">每月总消费: </text>
  3 + <text class="val red">{{total}} 元</text>
  4 +</view>
  5 +<view class="text-view border">
  6 + <text class="label">优惠后: </text>
  7 + <text class="val green">{{benefit}} 元</text>
  8 +</view>
  9 +<view class="text-view">
  10 + <text class="label">共节省了: </text>
  11 + <text class="val blue">{{diff}} 元</text>
  12 +</view>
  13 +<ad unit-id="adunit-0a991618c53a4445"></ad>
0 14 \ No newline at end of file
... ...
pages/result/result.wxss 0 → 100644
  1 +++ a/pages/result/result.wxss
  1 +.text-view{
  2 + display: flex;
  3 + flex-direction: row;
  4 + width: 100%;
  5 + padding: 15rpx;
  6 + background: #efefef;
  7 +}
  8 +.text-view .label{
  9 + flex: 1;
  10 + height: 72rpx;
  11 + padding-right: 20rpx;
  12 + vertical-align: top;
  13 + line-height: 72rpx;
  14 + font-size: 36rpx;
  15 + color: #666;
  16 + text-align: right;
  17 +}
  18 +.text-view .val{
  19 + flex: 2;
  20 + height: 72rpx;
  21 + line-height: 72rpx;
  22 + font-size: 36rpx;
  23 +}
  24 +.border{
  25 + border-bottom: 1rpx solid #dfdfdf;
  26 +}
  27 +.red{
  28 + color: red;
  29 +}
  30 +.green{
  31 + color: green;
  32 +}
  33 +.blue{
  34 + color: blue;
  35 +}
0 36 \ No newline at end of file
... ...
project.config.json 0 → 100644
  1 +++ a/project.config.json
  1 +{
  2 + "description": "项目配置文件。",
  3 + "setting": {
  4 + "urlCheck": false,
  5 + "es6": true,
  6 + "enhance": true,
  7 + "postcss": true,
  8 + "preloadBackgroundData": false,
  9 + "minified": true,
  10 + "newFeature": true,
  11 + "coverView": true,
  12 + "nodeModules": false,
  13 + "autoAudits": false,
  14 + "showShadowRootInWxmlPanel": true,
  15 + "scopeDataCheck": false,
  16 + "uglifyFileName": false,
  17 + "checkInvalidKey": true,
  18 + "checkSiteMap": true,
  19 + "uploadWithSourceMap": true,
  20 + "compileHotReLoad": false,
  21 + "lazyloadPlaceholderEnable": false,
  22 + "useMultiFrameRuntime": true,
  23 + "useApiHook": true,
  24 + "useApiHostProcess": true,
  25 + "babelSetting": {
  26 + "ignore": [],
  27 + "disablePlugins": [],
  28 + "outputPath": ""
  29 + },
  30 + "enableEngineNative": false,
  31 + "useIsolateContext": false,
  32 + "userConfirmedBundleSwitch": false,
  33 + "packNpmManually": false,
  34 + "packNpmRelationList": [],
  35 + "minifyWXSS": true,
  36 + "disableUseStrict": false,
  37 + "minifyWXML": true,
  38 + "showES6CompileOption": false,
  39 + "useCompilerPlugins": false
  40 + },
  41 + "compileType": "miniprogram",
  42 + "libVersion": "1.9.93",
  43 + "appid": "wx330e54aa6000516d",
  44 + "projectname": "%E8%AF%AD%E9%9F%B3%E5%8A%A9%E6%89%8B",
  45 + "isGameTourist": false,
  46 + "condition": {
  47 + "search": {
  48 + "list": []
  49 + },
  50 + "conversation": {
  51 + "list": []
  52 + },
  53 + "game": {
  54 + "currentL": -1,
  55 + "list": []
  56 + },
  57 + "miniprogram": {
  58 + "list": []
  59 + }
  60 + }
  61 +}
0 62 \ No newline at end of file
... ...
sitemap.json 0 → 100644
  1 +++ a/sitemap.json
  1 +{
  2 + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
  3 + "rules": [{
  4 + "action": "allow",
  5 + "page": "*"
  6 + }]
  7 +}
0 8 \ No newline at end of file
... ...
utils/util.js 0 → 100644
  1 +++ a/utils/util.js
  1 +function formatTime(date) {
  2 + var year = date.getFullYear()
  3 + var month = date.getMonth() + 1
  4 + var day = date.getDate()
  5 +
  6 + var hour = date.getHours()
  7 + var minute = date.getMinutes()
  8 + var second = date.getSeconds()
  9 +
  10 +
  11 + return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  12 +}
  13 +
  14 +function formatNumber(n) {
  15 + n = n.toString()
  16 + return n[1] ? n : '0' + n
  17 +}
  18 +
  19 +module.exports = {
  20 + formatTime: formatTime
  21 +}
... ...