jpemartins/speex.js

speex.decode returning -2 always

Opened this issue · 0 comments

When ever i try to decode of .spx file or speex encoded data(buffer/arraybuffer) it always showing -2(corrupted stream) in Netbeans 8.1. I tried to find the solution but i didn't find any solution. Please help me.

<script src="speex.js-master/src/libspeex.js"></script> <script src="speex.js-master/src/types.js"></script> <script src="speex.js-master/public/js/lib/bitstring.js"></script> <script src="speex.js-master/src/ogg.js"></script> <script src="speex.js-master/src/util.js"></script> <script src="speex.js-master/src/speex.js"></script> <script src="speex.js-master/public/js/audio.js"></script> <script src="speex.js-master/public/js/lib/pcmdata.min.js"></script> <script src="speex.js-master/src/codec.js"></script> <script src="speex.js-master/src/libspeex.js"></script> <script src="speex.js-master/src/encoder.js"></script> <script src="speex.js-master/src/decoder.js"></script> <script>
        function playAudio(url)
        {
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function ()
            {
                if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 206))
                {
                    var spx = new Speex({
                        rate: 16000,
                        quality: 6,
                        mode: 1
                    });
                    var data = xhr.response;
                    var dataview = new Int16Array(data);
                    var encdata = spx.encode(dataview,false);
                    var decdata = spx.decode(encdata, null);
                    var len = decdata.length;
                    alert(len+" ::"+decdata);
        var waveData = PCMData.encode({
            sampleRate: 16000,
            channelCount:   2,
            bytesPerSample: 1,
            data: decdata
        });      
                    alert(typeof(waveData));
                    var blb = new Blob([waveData]);
                    var ublb = URL.createObjectURL(blb);
                    var aud = document.getElementById('audio');
                    aud.src = "data:audio/wav;base64,"+ btoa(ublb);
                    aud.load();
                    aud.play();
                }
            };
            xhr.open('GET', url, true);
            xhr.responseType = 'arraybuffer';
            //xhr.setRequestHeader("RANGE","bytes:0-4608");
            xhr.send();
        }
    </script>
</head>
<body>
    <button onclick="playAudio('test.wav')">Click Me</button>
    <audio id="audio" controls></audio>
</body>