zoukankan      html  css  js  c++  java
  • 微信小程序智能语音识别

    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>  
  • 相关阅读:
    使用vue-cli创建项目(包含npm和cnpm的安装nodejs的安装)
    关于时区、时间戳引起的bug理解
    设置java、maven环境变量(怕麻烦以后直接来这里复制)
    回去看
    dockerfile各种命令解析
    Python+Appium环境搭建
    Python Selenium unittest+HTMLTestRunner实现 自动化测试及发送测试报告邮件
    Python Selenium 文件下载
    Python Selenium 文件上传之Autoit
    Python Selenium 文件上传之SendKeys
  • 原文地址:https://www.cnblogs.com/hjjun/p/8033853.html
Copyright © 2011-2022 走看看