<template> <div class="container"> <div class="button1" @click="startRecording"> <text>开始录音</text> </div> <div class="button1" @click="stopRecording"> <text>停止录音</text> </div> <div><text>录音数据已获取:</text></div> <div><text>音频字节长度: {{ audioBuffer ? audioBuffer.byteLength : 0 }} 字节</text></div> <div> <text>音频地址{{url}}</text> </div> </div> </template> <script> import router from '@system.router' import record from '@system.record' export default { data() { return { audioBuffer: null, // 存储音频数据 isRecording: false, url: '' }; }, onInit() { record.onframerecorded = (res) => { this.audioBuffer = res.frameBuffer; console.log(res); }; }, startRecording() { console.log('开始录音'); record.start({ duration: 600000, sampleRate: 16000, numberOfChannels: 1, encodeBitRate: 96000, format:'pcm', frameSize:'1024', success: (data) => { console.log(`录音成功,URI: ${data.uri}`); this.url = data.uri }, fail: (data, code) => { console.log(`录音失败,错误代码: ${code}, 错误信息: ${data}`); } }); }, stopRecording() { console.log('停止录音'); record.stop(); } }; </script> <style scoped> .container { padding: 20px; text-align: center; flex-direction: column; align-items: center; } .button1 { margin: 50px; padding: 10px; width: 300px; height: 80px; font-size: 16px; background-color: #4CAF50; color: white; border-radius: 5px; justify-content: center; } div { margin-top: 20px; color: #000; } </style> |