You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
HTML
51 lines
1.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Opus to PCM</title>
|
|
</head>
|
|
<body>
|
|
<div id="container" style="width: 400px; margin: 0 auto; font-size: 30px;">
|
|
It should play audio if everying went well!
|
|
</div>
|
|
<script>
|
|
window.onload = function() {
|
|
var orgSampleRate = 8000,
|
|
channels = 1,
|
|
configFlag = false,
|
|
socketURL = 'ws://localhost:8080';
|
|
|
|
var decoder = new Decoder.OpusToPCM({
|
|
channels: channels
|
|
});
|
|
|
|
var player = new PCMPlayer();
|
|
|
|
var ws = new WebSocket(socketURL);
|
|
ws.binaryType = 'arraybuffer';
|
|
ws.addEventListener('message',function(event) {
|
|
var data = new Uint8Array(event.data);
|
|
decoder.decode(data).then(function(pcmData) {
|
|
|
|
/*
|
|
Sample rate in opus is not fixed.
|
|
It can vary depending on hardware rate. But
|
|
we need sample rate for playing PCM data using audio context,
|
|
so lets set sampelRate here returned by decoder.
|
|
*/
|
|
if (!configFlag) {
|
|
var samppleRate = decoder.getSampleRate();
|
|
player.setConfig(samppleRate, channels);
|
|
configFlag = true;
|
|
}
|
|
|
|
player.feed(pcmData);
|
|
});
|
|
});
|
|
}
|
|
</script>
|
|
<script type="text/javascript" src="../dist/opus_to_pcm.js"></script>
|
|
<script type="text/javascript" src="player/pcm_player.js"></script>
|
|
</body>
|
|
</html>
|