小程序?qū)崿F(xiàn)按下錄音松開識別語音
更新時間:2019年11月22日 16:49:48 作者:再見昨天
這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)按下錄音松開識別語音,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了小程序按下錄音松開識別語音的具體代碼,供大家參考,具體內(nèi)容如下
wxml
<view class='circle position-absol'>
<text wx:if="{{!anmationShow}}" class='fz-12 fot-col block'>按住話筒說話,松開后自動識別文字</text>
<text wx:if="{{anmationShow}}" class='fz-12 fot-col block'>松手為您匹配設(shè)計公司</text>
<image bindtouchstart='startHandel' bindtouchend='endHandle' mode="widthFix" src="https://www.baidu.com/img/baidu_jgylogo3.gif" class='imgwh'></image>
<view class='c2' wx:if="{{anmationShow}}"></view>
<view class='c3' wx:if="{{anmationShow}}"></view>
</view>
wxss
.position-absol{
width: 100%;
text-align: center;
position: absolute;
bottom: 80rpx;
}
.imgwh{
width:110rpx;
height:110rpx;
}
.block{
display:block;
}
/* 波浪動畫 */
.circle view {
position:absolute;
top:50%;
left:50%;
background:#FF5A5F;
width:100px;
height:100px;
margin-left:-50px;
margin-top:-25px;
opacity:0;
border-radius:90px;
animation: 0.8s linear infinite;
-webkit-animation: 0.8s linear infinite;
}
.circle view.c2 {
-webkit-animation-name:c2;
-webkit-animation-delay:.6s;
-ms-animation-name:c2;
-ms-animation-delay:.6s;
-moz-animation-name:c2;
-moz-animation-delay:.6s;
-o-animation-name:c2;
-o-animation-delay:.6s;
animation-name:c2;
animation-delay:.6s;
}
.circle view.c3 {
-webkit-animation-name:c2;
-webkit-animation-delay:1s;
-ms-animation-name:c2;
-ms-animation-delay:1s;
-moz-animation-name:c2;
-moz-animation-delay:1s;
-o-animation-name:c2;
-o-animation-delay:1s;
animation-name:c2;
animation-delay:1s;
}
@-webkit-keyframes c2 {
0% {
-webkit-transform:scale(.622);
-ms-transform:scale(.622);
-moz-transform:scale(.622);
-o-transform:scale(.622);
transform:scale(.622);
opacity:0
}
50% {
-webkit-transform:scale(.822);
-ms-transform:scale(.822);
-moz-transform:scale(.822);
-o-transform:scale(.822);
transform:scale(.822);
opacity:.4
}
98% {
-webkit-transform:scale(1);
-ms-transform:scale(1);
-moz-transform:scale(1);
-o-transform:scale(1);
transform:scale(1);
opacity:.2
}
100% {
opacity:0
}
}
@keyframes c2 {
0% {
-webkit-transform:scale(.622);
-ms-transform:scale(.622);
-moz-transform:scale(.622);
-o-transform:scale(.622);
transform:scale(.622);
opacity:0
}
50% {
-webkit-transform:scale(.822);
-ms-transform:scale(.822);
-moz-transform:scale(.822);
-o-transform:scale(.822);
transform:scale(.822);
opacity:.4
}
98% {
-webkit-transform:scale(1);
-ms-transform:scale(1);
-moz-transform:scale(1);
-o-transform:scale(1);
transform:scale(1);
opacity:.2
}
100% {
opacity:0
}
}
js
data:{
anmationShow: false
}
//按住按鈕
startHandel: function () {
this.setData({
sayimg: '/assets/image/demand/down.png',
anmationShow: true,
})
console.log("開始")
wx.getRecorderManager().start({
duration: 10000
})
const self = this
setTimeout(function () {
self.setData({
sayimg: '/assets/image/demand/sea.png',
anmationShow: false
})
}, 10000);
},
//松開按鈕
endHandle: function () {
// clearTimeout()
this.setData({
sayimg: '/assets/image/demand/sea.png',//圖片樣式
anmationShow: false,
})
console.log("結(jié)束")
const recorderManager = wx.getRecorderManager()
//錄音停止函數(shù)
var that = this;
wx.getRecorderManager().onStop((res) => {
if (!this.data.inpvalue) {
wx.showLoading({
title: '語音識別中'
})
}
const { tempFilePath } = res; //這里松開按鈕 會返回錄音本地路徑
//上傳錄制的音頻到服務(wù)器
wx.uploadFile({
url: '接口地址' + api.voice, //接口地址
name: 'file', //上傳文件名
filePath: tempFilePath,
success: function (res) { //后臺返回給前端識別后的文字
var model = res.data
var modeljson = JSON.parse(model)
if (modeljson.status_code == 500) {
wx.showToast({
title: '語音轉(zhuǎn)換失敗',
image: '/assets/image/icon/fail@2x.png'
})
return false;
}
if (modeljson.meta.status_code === 200 && !modeljson.data.err_msg) {
var saymessage = modeljson.data.message;
wx.setStorageSync('sayinfo', saymessage)
that.setData({
inpvalue: saymessage
})
setTimeout(() =>{
wx.navigateTo({
url: '../loding/loding'
})
},2000)
setTimeout(() => {
wx.hideLoading();
}, 100)
} else if (modeljson.data.err_msg) {
wx.showToast({
title: '請大聲說話',
image: '/assets/image/icon/fail@2x.png'
})
return false;
}
}
})
})
//觸發(fā)錄音停止
wx.getRecorderManager().stop()
},
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
如何基于filter實現(xiàn)網(wǎng)站整體變灰功能
這篇文章主要介紹了如何基于filter實現(xiàn)網(wǎng)站整體變灰功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-04-04
js下拉框二級關(guān)聯(lián)菜單效果代碼具體實現(xiàn)
這篇文章介紹了js下拉框二級關(guān)聯(lián)菜單效果代碼具體實現(xiàn),有需要的朋友可以參考一下2013-08-08
JSQL 基于客戶端的成績統(tǒng)計實現(xiàn)方法
JSQL應(yīng)用案例 基于客戶端的成績統(tǒng)計,下面我把整個example的代碼貼出來,歡迎拍磚2010-05-05
javascript中動態(tài)函數(shù)用法實例分析
這篇文章主要介紹了javascript中動態(tài)函數(shù)用法,實例分析了動態(tài)函數(shù)的定義方法與使用技巧,需要的朋友可以參考下2015-05-05
JS小功能(操作Table--動態(tài)添加刪除表格及數(shù)據(jù))實現(xiàn)代碼
這篇文章主要介紹了操作Table--動態(tài)添加刪除表格及數(shù)據(jù)實現(xiàn)代碼,有需要的朋友可以參考一下2013-11-11
JavaScript滾動條屬性scrollTop和scrollHeight
在開發(fā)中我們常常會用到判斷滾動條是否觸底的邏輯,我一般都會在網(wǎng)上搜一段代碼,這段代碼有用到scrollTop、clientHeight、 scrollHeight,這篇文章主要給大家介紹了關(guān)于JavaScript滾動條屬性scrollTop和scrollHeight的相關(guān)資料,需要的朋友可以參考下2023-11-11

