<template>
  <div class="AppTest">
    <button @tap="startRecord">开始录音</button>
		<button @tap="endRecord">停止录音</button>
  </div>
</template>

<script>

import {mapState} from "vuex";

export default {
  name: 'AppTest',
  appName: '测试语音',
  data() {
    return {
      recorderManager: null
    }
  },
  computed: {
    ...mapState(['user']),
  },
  onLoad() {
    
  },
  onShow() {
    
		
  },
  methods: {
    startRecord() {
      uni.authorize({
        scope: 'scope.record',
        success() {
          console.log(123)
          this.recorderManager = uni.getRecorderManager()
          const options = {
            duration: 10000,
            sampleRate: 44100,
            numberOfChannels: 1,
            encodeBitRate: 192000,
            format: 'aac',
            frameSize: 50
          }
          this.recorderManager.start(options)
          this.recorderManager.onStart(() => {
            console.log('录音开始');
          })
          this.recorderManager.onError((err) => {
            console.log(err)
          })
        },
        fail() {
          uni.showModal({
            title: "提示",
            content: "您的录音权限未开启",
          })
        }
      })	
		},
		endRecord() {
      this.recorderManager.stop()
      this.recorderManager.onStop((res)=> {
        console.log('录音结束');
        console.log('recorder stop' + JSON.stringify(res));
        // self.voicePath = res.tempFilePath;
      });
		}
  },
  onReachBottom() {

  },
}
</script>

<style lang="scss" scoped>
.AppTest {
  
}
</style>
