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>  
  • 相关阅读:
    lombok @Builder注解使用的例子、反编译之后的代码详解
    InfluxDB时序数据库应用场景
    阿里巴巴为什么不用 ZooKeeper 做服务发现?
    使用RestTemplate调用接口上传文件
    当try-catch-finally代码块遇上return,代码执行流程是怎样
    Spring Boot 中application.yml与bootstrap.yml的区别
    Java文件上传:Restful接口接收上传文件,缓存在本地
    线程执行synchronized同步代码块时再次重入该锁过程中抛异常,是否会释放锁
    AMQP协议详解与RabbitMQ,MQ消息队列的应用场景,如何避免消息丢失等消息队列常见问题
    数据库:内联接,外联接,空值和联接
  • 原文地址:https://www.cnblogs.com/hjjun/p/8033853.html
Copyright © 2011-2022 走看看