如何把httpsgenshinvoicetopapispeaker=丹恒&text=$content&format=wav&length=1&noise=05&noisew=09&sdp_ratio=02的链接在本页面播放请示例完整代码body div class=rightSide div class=header div class=imgText
您可以将以下代码插入到您的HTML文件中,以在页面中播放音频:
<audio id="audioPlayer" controls></audio>
然后,在JavaScript代码中的handleSend函数中添加以下代码:
let url = `https://genshinvoice.top/api?speaker=丹恒&text=${content}&format=wav&length=1&noise=0.5&noisew=0.9&sdp_ratio=0.2`;
let audioXhr = new XMLHttpRequest();
audioXhr.open('GET', url);
audioXhr.responseType = 'blob';
audioXhr.onload = function () {
var audioPlayer = document.getElementById('audioPlayer');
audioPlayer.src = URL.createObjectURL(audioXhr.response);
};
audioXhr.send();
这段代码将使用XMLHttpRequest从给定的URL获取音频文件,并使用URL.createObjectURL将其链接到audioPlayer元素的src属性上。这将使得音频可以在页面上播放。
原文地址: https://www.cveoy.top/t/topic/i2JF 著作权归作者所有。请勿转载和采集!