美文网首页
文字转为语音播放

文字转为语音播放

作者: zlf_j | 来源:发表于2020-08-21 11:45 被阅读0次

一、文字转语音播放(3种实现办法)

https://blog.csdn.net/WhiteEmperor/article/details/92568232

二、audio

   <script type="text/javascript">
    var audios = document.getElementsByTagName("audio");
    for (var i = 0; i < audios.length; i++) {
        // console.log("audios "+i+"  SRC:" + audios[i].currentSrc);
        audios[i].addEventListener('ended', function() {
            // nextSibling 属性返回指定节点之后紧跟的节点,在相同的树层级中。
            var nextAudio = this.nextSibling.nextSibling;
            // tagName 属性返回元素的标签名。(大写)
            if (nextAudio.tagName == "AUDIO") {
                nextAudio.play();
            }
        }, false);
    }
    </script>

https://blog.csdn.net/diebaiying3731/article/details/102237694

  • 3、如何判断audio是否在播放
var audioPlayer = document.querySelector('audio#player'); 
if (audioPlayer.paused) {
// 暂停中
} else {
// 播放中
}

https://www.zhihu.com/question/24692289

  • 4、让audio立马结束重新开始
player.currentTime=0;

https://www.oschina.net/question/273464_49768

音频上传(elementUI)

  • 1、上传音频格式限制(类型+大小+时长)
           beforeAvatarUpload(file) {
                // 文件类型进行判断
                const isAudio = file.type === "audio/mp3" || file.type === "audio/mpeg";
                // 限制上传文件大小 2M
                const isLt2M = file.size / 1024 / 1024 < 2;
                const isTime60S = this.audioDuration >= 60 ? true : '';
                // 获取时长
                this.getTimes(file);
                if (!isAudio) {
                    this.$message.error("上传文件只能是Mp3格式!");
                    this.fileList = [];
                } else {
                    if (!isLt2M) {
                        this.$message.error("上传文件大小不能超过 2MB!");
                        this.fileList = [];
                    } else {
                        if (!isTime60S) {
                            this.$message.error("上传文件时长不能超过60秒!");
                            this.fileList = [];
                        }
                    }
                }
                return isAudio && isLt2M && isTime60S
            },
             getTimes(file) {
                var content = file;
                //获取录音时长
                var url = URL.createObjectURL(content);
                //经测试,发现audio也可获取视频的时长
                var audioElement = new Audio(url);
                audioElement.addEventListener("loadedmetadata", (_event) => {
                    this.audioDuration = parseInt(audioElement.duration);
                    // console.log(this.audioDuration);
                });
            },

https://blog.csdn.net/weixin_43915587/article/details/91488764

  • 2、ajax实现文件上传, illegal invocation 错误( processData:false)
      $.ajax({
            url:'backData.php',
            data:sendData,
            type:'post',
            //ajax2.0可以不用设置请求头,但是jq帮我们自动设置了,这样的话需要我们自己取消掉
            contentType:false,
            //取消帮我们格式化数据,是什么就是什么
            processData:false, // *** 解决方案
            success:function(backData){
                console.log(backData);
            }
        })

https://blog.csdn.net/qq_42181069/article/details/80333779

  • 3、el-upload 在v-for里使用时 如何获取index

外层套一个div,加点击事件,获取循环后的index
https://blog.csdn.net/weixin_34163553/article/details/93212655

  • 4、Access to XMLHttpRequest at ‘’rom origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok st...(jquery,ajax传参,post请求报错,跨域问题)
 crossDomain: true

https://www.cnblogs.com/autoXingJY/p/11419860.htmla

相关文章

网友评论

      本文标题:文字转为语音播放

      本文链接:https://www.haomeiwen.com/subject/ymjedktx.html