Browse Source

AI参谋跳转接口调试

zhujindu 1 year ago
parent
commit
3b7d96dcd4
2 changed files with 33 additions and 7 deletions
  1. 27 4
      src/views/intelligence/audioBox.vue
  2. 6 3
      src/views/intelligence/index.vue

+ 27 - 4
src/views/intelligence/audioBox.vue

@@ -1,5 +1,5 @@
 <template>
-  <div class="audioBoxContent">
+  <div class="audioRecord">
     <div class="audioBox">
       <div
         class="boxItem"
@@ -68,6 +68,12 @@ var recorder = new Recorder({
 
 export default {
   name: 'audioRecord',
+  props: {
+    audioUrl: {
+      type: String,
+      default: '',
+    },
+  },
   data() {
     return {
       //波浪图-录音
@@ -85,6 +91,14 @@ export default {
       ys: 0, // 播放时长 秒
     };
   },
+  watch: {
+    audioUrl: {
+      handler() {
+        debugger;
+        this.getMp3Data();
+      },
+    },
+  },
   created() {
     // 绑定事件-打印的是当前录音数据
     recorder.onprogress = function (params) {
@@ -245,8 +259,17 @@ export default {
      * 文件格式转换 wav-map3
      * */
     getMp3Data() {
-      const mp3Blob = this.convertToMp3(recorder.getWAV());
-      recorder.download(mp3Blob, 'recorder', 'mp3');
+      debugger;
+      let url = this.audioUrl;
+      var xhr = new XMLHttpRequest();
+      xhr.open('GET', url, true);
+      xhr.responseType = 'arraybuffer';
+      xhr.onload = function () {
+        var samples = new Int16Array(xhr.response);
+        const mp3Blob = this.convertToMp3(samples);
+        recorder.download(mp3Blob, 'recorder', 'mp3');
+      };
+      xhr.send();
     },
     convertToMp3(wavDataView) {
       // 获取wav头信息
@@ -354,7 +377,7 @@ export default {
 };
 </script>
 <style lang="scss" scoped>
-.audioBoxContent {
+.audioRecord {
   background: #fff;
   position: fixed;
   bottom: 120px;

+ 6 - 3
src/views/intelligence/index.vue

@@ -422,7 +422,7 @@
         </div>
       </div>
     </van-overlay>
-    <audioBox></audioBox>
+    <audioRecord :audioUrl="audioUrl"></audioRecord>
   </div>
 </template>
 
@@ -437,10 +437,10 @@ import { aiDialogue } from '@/api/inventory';
 import { getPosition, getTicketFun } from '@/utils/TXApiFun';
 import BenzAMRRecorder from 'benz-amr-recorder';
 import sample3s from '@/assets/mp3/sample-3s.mp3';
-import audioBox from './audioBox.vue';
+import audioRecord from './audioRecord.vue';
 export default {
   name: 'ai',
-  components: { tabBar, audioBox },
+  components: { tabBar, audioRecord },
   data() {
     return {
       sample3s: sample3s,
@@ -485,6 +485,7 @@ export default {
       isNoData: false, //是否加载完所有数据
       successText: '加载成功', //上拉刷新提示语
       tips: '按住 说话',
+      audioUrl: '',
     };
   },
   // watch: {
@@ -500,6 +501,8 @@ export default {
     this.onLoad();
     // 授权
     getTicketFun(['getLocation', 'startRecord', 'stopRecord', 'onVoiceRecordEnd', 'uploadVoice']);
+    this.audioUrl =
+      'https://cdn-svs-test.nipponpaint.com.cn/%E5%90%B4%E5%BA%B7-20240918152244.amr?Expires=2042176973&OSSAccessKeyId=LTAI5tG1DTJFA16BHkzHVxjz&Signature=BvwZFdxp69wRNy7oOPfqG6lxTww%3D';
   },
   methods: {
     audioPlay(chatRecordFile) {