使用plus.io.resolveLocalFileSystemURL
<template>
<view>
<button @click="startRecord">开始录音</button>
<button @click="stopRecord">停止录音</button>
</view>
</template>
<script>
export default {
data() {
return {
recorderManager: null,
tempFilePath: ''
};
},
onLoad() {
// 获取录音管理器实例
this.recorderManager = uni.getRecorderManager();
// 监听录音停止事件
this.recorderManager.onStop((res) => {
console.log('录音停止,文件路径:', res.tempFilePath);
this.tempFilePath = res.tempFilePath;
this.convertToBase64(res.tempFilePath);
});
},
methods: {
// 开始录音方法
startRecord() {
const options = {
format: 'mp3' // 录音格式,这里选择 mp3
};
this.recorderManager.start(options);
console.log('开始录音');
},
// 停止录音方法
stopRecord() {
this.recorderManager.stop();
console.log('停止录音');
},
// 将录音文件转换为 Base64 编码字符串的方法
convertToBase64(filePath) {
// 将 UniApp 路径转换为 5+ 路径
const plusPath = '_doc' + filePath.split('_doc')[1];
plus.io.resolveLocalFileSystemURL(plusPath, (entry) => {
entry.file((file) => {
const reader = new plus.io.FileReader();
reader.readAsDataURL(file);
reader.onload = (e) => {
const base64Data = e.target.result.split(',')[1];
console.log('Base64 编码字符串:', base64Data);
// 在这里可以对 Base64 编码字符串进行进一步处理
};
reader.onerror = (err) => {
console.error('读取文件失败:', err);
};
}, (err) => {
console.error('获取文件失败:', err);
});
}, (err) => {
console.error('解析文件路径失败:', err);
});
}
}
};
</script> 网友回复
阿里云ESA、cloudflare worker、腾讯云EdgeOne网站代理托管哪家更好?
剪映能打开.fcpxml格式的文件吗?
增量式编码器与绝对式编码器的区别是啥?
有没有开源的单张照片或者序列帧图片或视频就能重建4d场景动画项目?
chrome网页突然报错:错误代码:RESULT_CODE_KILLED_BAD_MESSAGE
openai的codex如何全程无需手动确认自动修改文件?
阿里云oss前端上传文件直传如何限制文件类型?
阿里云oss前端获取policy签名直传oss上传文件回调如何传?
如何将根据三维物体通过提示词变成可交互的4d场景动画?
浏览器中实时摄像头离线视觉ai模型有吗?


