代码拉取完成,页面将自动刷新
同步操作将从 theajack/cnchar 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<!--
* @Author: chenzhongsheng
* @Date: 2023-03-18 16:52:44
* @Description: Coding something
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext;
try {
var context = new window.AudioContext();;
var source = null;
var audioBuffer = null;
function stopSound() {
if (source) {
source.stop(0); //立即停止
}
}
function playSound() {
source = context.createBufferSource();
source.playbackRate.value = 1;
source.buffer = audioBuffer;
// source.loop = true; //循环播放
const gain = context.createGain();
gain.gain.value = 1;
source.connect(gain);
gain.connect(context.destination);
// source.connect(context.destination);
source.start(0); //立即播放
}
function initSound(arrayBuffer) {
context.decodeAudioData(arrayBuffer, function(buffer) { //解码成功时的回调函数
audioBuffer = buffer;
playSound();
}, function(e) { //解码出错时的回调函数
console.log('Error decoding file', e);
});
}
function loadAudioFile(url) {
var xhr = new XMLHttpRequest(); //通过XHR下载音频文件
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.onreadystatechange = () => {
if (xhr.status === 200) {
if (xhr.readyState === 4) {
console.log('response decodeArrayBuffer', xhr.response);
// decodeArrayBuffer(xhr.response, resolve);
initSound(xhr.response);
}
} else {
resolve(null);
}
};
// xhr.onload = function(e) { //下载完成
// initSound(this.response);
// };
xhr.send();
}
loadAudioFile('https://unpkg.com/cnchar-data@1.1.0/voice/hao3.mp3');
} catch (e) {
console.log('!Your browser does not support AudioContext');
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。