Friday 21 April 2017

Not able to use cordova spectogram plugin?

I am not able to use this plugin as their are no instruction given on their git link. However I somehow installed the plugin and tried. I want to create a button to start audio record and then plot spectogram in real time.

Here is the link of the plugin Plugin link

   var audioRecorder = exports;

    var fns = ['initialiseAudioRecorder', 'startAudioRecorder', 'stopAudioRecorder', 
               'startWhiteNoise', 'stopWhiteNoise', 
               'startHeterodyne', 'stopHeterodyne', 
               'getAmplitude', 'getScaledAmplitude', 'getFrequencies', 'getScaledFrequencies', 'getFrequencyColours', 
               'captureRecording', 'clearBuffers'];

    // Add functions for each of the plugin callbacks we want to expose

    for (var i = 0; i < fns.length; i++) {

        // Wrap in a closure so that we lock in the value of fnName

        (function () {

            var fnName = fns[i];

            audioRecorder[fnName] = function (win, fail) {

                win = win || function () {};
                fail = fail || function () {};

                cordova.exec(win, fail, "AudioRecorder", fnName, [null]);

            };

        })();
    }

    audioRecorder.setHeterodyneFrequency = function (frequency, win, fail) {

        win = win || function () {};
        fail = fail || function () {};

        frequency = frequency || 15000;

        cordova.exec(win, fail, "AudioRecorder", "setHeterodyneFrequency", [frequency]);

    }

    audioRecorder.writeSonogram = function (width, height, duration, win, fail) {

        win = win || function () {};
        fail = fail || function () {};

        width = width || 320;
        height = height || 120;
        duration = duration || 30;

        cordova.exec(win, fail, "AudioRecorder", "writeSonogram", [width, height, duration]);

    }

    audioRecorder.writeRecording = function (duration, win, fail) {

        win = win || function () {};
        fail = fail || function () {};

        duration = duration || 30;

        cordova.exec(win, fail, "AudioRecorder", "writeRecording", [duration]);

    }
<!DOCTYPE html>
<html>
    <head>
      <title>pectogram</title>
    </head>
    <body>
        <div class="app">
            <h1>Hello World</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
                                <button onclick="mycode()">Start recording</button>
                                <button onclick="plot()">Show spectogram</button>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
                <script>
                  function mycode() {
                 audioRecorder-plugin.audioRecorder(win, fail, "audiorecorder")
                                                          }
                
                </script>
    </body>
</html>


via Dr._Duck

No comments:

Post a Comment