First, demand
Mall platform after receiving customer payment is successful automatic voice broadcast "system credited into 1000 yuan."
Second, Solutions
1, customers pay successfully, backstage generate orders;
2, a push message back to the client;
3, third-party client calls the interface after receiving the message into the text-to-speech playback.
Third, the practice (in this case the use of Baidu voice technology)
1, intelligent cloud applications Baidu account
2, voice technology into the module to create an application ( document address )
3, in exchange for token
// appKey = Va5yQRHl********LT0vuXV4 // appSecret = 0rDSjzQ20XUj5i********PQSzr5pVw2 https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=Va5yQRHl********LT0vuXV4&client_secret=0rDSjzQ20XUj5i********PQSzr5pVw2
{ "access_token": "1.a6b7dbd428f731035f771b8d********.86400.1292922000-2346678-124328", "expires_in": 2592000, "refresh_token": "2.385d55f8615fdfd9edb7c4b********.604800.1293440400-2346678-124328", "scope": "public audio_tts_post ...", "session_key": "ANXxSNjwQDugf8615Onqeik********CdlLxn", "session_secret": "248APxvxjCZ0VEC********aK4oZExMB", }
3, synthetic access interfaces
HTTP: // tsn.baidu.com/text2audio?lan=zh&ctp=1&cuid=abcdxxx&tok=1.a6b7dbd428f731035f771b8d****.86400.1292922000-2346678-124328&tex=%e7%99%be%e5%ba%a6%e4%bd E5% A0% a5%% Vol & bd = 9 = 0 & & per SPD = 5 & PIT = 5 & Aue = 3 // this is a normal MP3 download url of // TEX please urlencode2 times in the actual development process
4, test client shots
5, the test client code (in this case using uniapp)
1 <template> 2 <view> 3 <view class="uni-padding-wrap uni-common-mt"> 4 <view class="button-sp-area"> 5 <button type="default" @click="changeAudio()">切换</button> 6 <button type="primary" @click="play()">播放</button> 7 <button type="primary" @click="pause()">暂停</button> 8 <button type="warn" @click="stop()">停止</button> 9 </view> 12 is <View class = "UNI-title"> test text </ View> . 11 <View> 10 <view> 13 <input v-model="readText" class="uni-input" maxlength="10" placeholder="最大输入长度为10" /> 14 </view> 15 <view class="uni-title">语速</view> 16 <view> 17 <slider v-model="spd" min="0" max="15" show-value @change="spdSliderChange" /> 18 </view> 19 <view class="uni-title">音调</view> 20 <view> 21 <slider v-model="pit" min="0" max="15" show-value @change="pitSliderChange" /> 22 </view> 23 <view class="uni-title">音量</view> 24 <view> 25 <slider v-model="vol" min="0" max="15" show-value @change="volSliderChange" /> 26 </view> 27 28 <view class="uni-title">发音人</view> 29 <view class="uni-list"> 30 <view class="uni-list-cell"> 31 <view class="uni-list-cell-left"> <View class = "UNI-List-Cell-DB"> 34 is </ View> 33 is current selection 32 35 <picker @change="bindPickerChange" :value="index" range-key="lable" :range="array"> 36 <view class="uni-input">{{array[index].lable}}</view> 37 </picker> 38 </view> 39 </view> 40 </view> 41 <button type="primary" @click="loadBaiduAudio2()">测试百度语音合成</button> 42 </view> 43 </view> 44 </view> 45 </template> 46 47 <script> 48 Export default { 49 Data () { 50 return { 51 is innerAudioContext: null , 52 is readText: 'Alipay arrival one thousand yuan' , 53 is the access_token: .ae748a58ea3160facbdf707c923b5309.2592000.1574926792.282335-16656017 '00 ' , 54 is SPD:. 5 , 55 PIT:. 5 , 56 is Vol:. 5 , 57 is per: 0 , 58 Array: [{ 59 value: 0 , 60 Lable: 'Normal Female' 61 is }, 62 is { 63 is value:. 1 , 64 Lable: 'Normal boys' 65 }, 66 { 67 value:. 3 , 68 Lable: 'Emotional Synthesis - degree Happy' 69 } , 70 { 71 is value:. 4 , 72 lable: '情感合成-度丫丫' 73 } 74 ], 75 index: 0 76 } 77 }, 78 onLoad() { 79 const innerAudioContext = uni.createInnerAudioContext(); 80 innerAudioContext.autoplay = true; 81 innerAudioContext.src = 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/audio/music.mp3'; 82 innerAudioContext.pause(); 83 innerAudioContext.onPlay(() => { 84 console.log('开始播放'); 85 }); 86 innerAudioContext.onError((res) => { 87 console.log(res.errMsg); 88 console.log(res.errCode); 89 }); 90 this.innerAudioContext = innerAudioContext; 91 }, 92 methods: { 93 changeAudio: function() { 94 this.innerAudioContext.src = 'http://m10.music.126.net/20191029152112/53749fba54e8903c0daa20d7c723f3d6/ymusic/374b/8502/4d09/798b85bbef3192e6de5675159073e941.mp3'; 95 }, 96 play: function() { 97 this.innerAudioContext.play(); 98 }, 99 pause: function() { 100 this.innerAudioContext.pause(); 101 }, 102 stop: function() { 103 this.innerAudioContext.stop(); 104 }, 105 // GET方式 106 loadBaiduAudio2: function() { 107 this.innerAudioContext.src = 'http://tsn.baidu.com/text2audio?tex=' + encodeURIComponent(encodeURIComponent(this.readText)) + 108 '&tok=' + this.access_token + '&cuid=test_001&ctp=1&lan=zh&spd=' + 109 this.spd + '&pit=' + this.pit + '&vol=' + this.vol + '&per=' + this.per 110 }, 111 // POST方式 112 loadBaiduAudio: function() { 113 uni.request ({ 114 URL: 'http://tsn.baidu.com/text2audio' , 115 Method: 'the POST' , 1 16 Data: { 117 // . Required synthetic text, using UTF-8 encoding is less than . 2048 alphanumeric characters or (after conversion to text within GBK Baidu server, must be less than 4096 bytes) 1 18 TEX: the encodeURIComponent (the encodeURIComponent ( the this .readText)), 119 // required to open development platform obtains by the access_token 120 Tok: the this .access_token, 121 // required to uniquely identify a user, to calculate the value of UV proposed fill machine user can distinguish the MAC address or IMEI code, a length of 60 characters or less. 122 CUID: 'test_001' , 123 // Required client type selection, web end to fill a fixed value. 1 124 CTP:. 1 , 125 // optional fixed value zh. Language selection, only English mixed mode, the fixed value fill ZH 126 LAN: 'ZH' , 127 // optional speech rate, the value 0-15, default 5 Speed 128 SPD: 5 , 129 // selected from filling tone values 0-15, default tone 5 130. PIT: 5 , 131 is // optional volume value of 0-15, default 5 volume 132 Vol: 5 , 133 //Pronunciation optional chose, for the general female 0, 1 ordinary boys and 3 for the synthesis of emotion - of Happy, 4 for the synthesis of emotion - of the Ya-Ya, the default for the general female 134 per: 0 , 135 // optional 3 mp3 format (default); 4 pcm-16k; 5 to pcm-8k; 6 as WAV (the same content pcm-16k); Note aue = 4 or 6 is a format of voice recognition requirements, but the audio content is not speech recognition requirements natural pronunciation, so the recognition effect will be affected. 136 Aue:. 3 137 }, 138 header: {}, 139 Success: (RES) => { 140 // this.innerAudioContext.src = res.data; 141 is } 142 }); 143 }, 144 bindPickerChange:function (E) { 145 the console.log ( 'Picker change transmission selected, carrying a value' , e.target.value) 146 the this .index = e.target.value 147 the this .per = the this .Array [e.target. value] .Value || 0 ; 148 }, 149 spdSliderChange: function (E) { 150 the console.log ( 'value change:' + e.detail.value); 151 the this .spd = e.detail.value; 152 }, 153 pitSliderChange: function (E) { 154 console.log('value 发生变化:' + e.detail.value); 155 this.pit = e.detail.value; 156 }, 157 volSliderChange: function(e) { 158 console.log('value 发生变化:' + e.detail.value); 159 this.vol = e.detail.value; 160 } 161 } 162 } 163 </script> 164 165 <style> 166 button { 167 margin-top: 30upx; 168 margin-bottom: 30upx; 169 } 170 171 .button-sp-area { 172 margin: 0 auto; 173 width: 60%; 174 } 175 176 .mini-btn { 177 margin-right: 10upx; 178 } 179 </style>