9***@qq.com
9***@qq.com
  • 发布:2019-11-14 16:34
  • 更新:2019-11-14 16:46
  • 阅读:1386

uni-app 语音上传安卓可以 苹果无法上传

分类:uni-app
<script>  
    import void_token from '@/static/js/void_token.js'  

    import baseUrl from '@/static/js/Ajax.js'  
    const recorderManager = uni.getRecorderManager();  
    const innerAudioContext = uni.createInnerAudioContext();  

    innerAudioContext.autoplay = true;  
    var myDate = new Date();  
    export default {  
        data() {  
            return {  
                text: 'uni-app',  
                voicePath: '',  
                lypd: 1,  
                date: myDate.getFullYear() + '.' + (myDate.getMonth() + 1) + '.' + myDate.getDate(),  
                wenzi: []  
            };  
        },  
        // onLoad: function(option) { //option为object类型,会序列化上个页面传递的参数  
        //  console.log(option.id); //打印出上个页面传递的参数。  
        //  this.cId = option.id  
        // },  
        onLoad(option) {  
            console.log(option.id); //打印出上个页面传递的参数。  
            this.cId = option.id  
            let self = this;  
            recorderManager.onStop(function(res) {  
                self.lypd = 1  
                self.voicePath = ''  
                console.log(res.tempFilePath);  
                // console.log('recorder stop' + JSON.stringify(res));  
                self.voicePath = res.tempFilePath;  
                uni.showLoading({  
                    title: '转译中'  
                });  
                uni.uploadFile({  
                    url: baseUrl + '/analysis/voiceAnalysis',  
                    header: {  
                        'Authorization': uni.getStorageSync('TOKEN'),  
                        // 'content-type': 'application/json'  
                    },  
                    formData: {  
                        avatarfile: res.tempFilePath  
                    },  
                    fileType: 'video',  
                    filePath: res.tempFilePath,  
                    name: 'avatarfile',  
                    success: (res) => {  
                        void_token(res.data)  

                        uni.hideLoading();  
                        console.log(res.data);  
                        const data = JSON.parse(res.data)  
                        console.log(data);  
                        var that = self  
                        if (data.code == 0) {  
                            uni.request({  
                                method: 'POST',  
                                url: baseUrl + '/meeting/userNotes',  
                                header: {  
                                    'Authorization': uni.getStorageSync('TOKEN'),  
                                    'content-type': 'application/x-www-form-urlencoded'  
                                },  
                                data: {  
                                    conferenceId: that.cId,  
                                    content: data.data  
                                },  
                                success: (res) => {  
                                    void_token(res.data);  
                                    console.log(res);  
                                }  
                            });  
                        }  
                        self.wenzi.push(data.data)  
                        console.log(self.wenzi)  
                    }  
                })  
            });  
        },  
        methods: {  
            PlayOrStop() {  
                if (this.lypd == 1) {  
                    this.lypd = 2  
                    this.startRecord()  
                } else {  
                    this.lypd = 1  
                    this.endRecord()  
                }  
            },  
            startRecord() {  
                uni.showToast({  
                    title: "开始录音"  
                })  
                recorderManager.start({  
                    format: 'mp3'  
                });  
            },  
            endRecord() {  
                uni.showToast({  
                    title: "录音结束"  
                })  
                recorderManager.stop();  
                console.log(this.voicePath);  
            },  
            // playVoice() {  
            //  console.log('播放录音');  

            //  if (this.voicePath) {  
            //      innerAudioContext.src = this.voicePath;  
            //      innerAudioContext.play();  
            //  }  
            // }  
        }  
    }  
</script>
2019-11-14 16:34 负责人:无 分享
已邀请:
9***@qq.com

9***@qq.com (作者) - 今天也是充满希望的一天 ——A little whale on the wing

在线等

9***@qq.com

9***@qq.com (作者) - 今天也是充满希望的一天 ——A little whale on the wing

语音路径可以打印

该问题目前已经被锁定, 无法添加新回复