使用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> 网友回复
有没有不依赖embedding向量的RAG技术?
有没有支持实时打断语音通话并后台帮你执行任何的ai模型?
开源ai大模型文件格式GGUF、MLX、Safetensors、 ONNX 有什么区别?
出海挣钱支付收款PayPal、Wise 、PingPong、Stripe如何选择?
如何实现类似google的图片隐形水印添加和识别技术?
linux上如何运行任意windows程序?
ai能写出比黑客还厉害的零日漏洞等攻击工具攻击任意软件系统工程?
js如何获取浏览器的音频上下文指纹、Canvas指纹、WebGL渲染特征?
为啥ai开始抛弃markdown文本,重新偏好html文本了?
网站有没有办法鉴别访问请求是由ai操控chrome-devtools-mcp发出的?


