微信小程序智能语音识别

  1. <span style="font-size:14px;"> startRecode:function(){  
  2.  var s = this;  
  3.  console.log("start");  
  4.  wx.startRecord({  
  5.      success: function (res) {  
  6.          console.log(res);  
  7.          var tempFilePath = res.tempFilePath;  
  8.          s.setData({ recodePath: tempFilePath, isRecode:true});  
  9.      },  
  10.      fail: function (res) {  
  11.          console.log("fail");  
  12.          console.log(res);  
  13.          //录音失败  
  14.      }  
  15.  });  
  16.  },  
  17.  endRecode:function(){//结束录音   
  18.  var s = this;  
  19.  console.log("end");  
  20.  wx.stopRecord();  
  21.  s.setData({ isRecode: false });  
  22.   
  23.     
  24.  wx.showToast();  
  25.  setTimeout(function () {  
  26.      var urls = app.globalData.urls + "/Web/UpVoice";  
  27.      console.log(s.data.recodePath);  
  28.      wx.uploadFile({  
  29.          url: urls,  
  30.          filePath: s.data.recodePath,  
  31.          name: 'file',  
  32.          header: {  
  33.              'content-type': 'multipart/form-data'  
  34.          },  
  35.          success: function (res) {  
  36.              var str = res.data;  
  37.              var data = JSON.parse(str);  
  38.              if (data.states == 1) {  
  39.                  var cEditData = s.data.editData;  
  40.                  cEditData.recodeIdentity = data.identitys;  
  41.                  s.setData({ editData: cEditData });  
  42.              }  
  43.              else {  
  44.                  wx.showModal({  
  45.                      title: '提示',  
  46.                      content: data.message,  
  47.                      showCancel: false,  
  48.                      success: function (res) {  
  49.   
  50.                      }  
  51.                  });  
  52.              }  
  53.              wx.hideToast();  
  54.          },  
  55.          fail: function (res) {  
  56.              console.log(res);  
  57.              wx.showModal({  
  58.                  title: '提示',  
  59.                  content: "网络请求失败,请确保网络是否正常",  
  60.                  showCancel: false,  
  61.                  success: function (res) {  
  62.   
  63.                  }  
  64.              });  
  65.              wx.hideToast();  
  66.          }  
  67.      });  
  68.  },1000)  
  69.   
  70.  }</span>  
原文地址:https://www.cnblogs.com/hjjun/p/8033853.html