0

I need to send sound input to server. Can I send it as variable? What should I do in the function start_microphone(), and what methods of AudioContext() should I use?

var input = null;
var webaudio_tooling_obj = function() {
    var audioContext = new AudioContext();
    console.log("audio is starting up ...");
    var BUFF_SIZE = 16384;
    var audioInput = null,

    if (!navigator.getUserMedia)
        navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
            navigator.mozGetUserMedia || navigator.msGetUserMedia;

    if (navigator.getUserMedia) {
        navigator.getUserMedia({
            audio: true
        }, function(stream) {
            start_microphone(stream);
        }, function(e) {
            alert('Error capturing audio.');
        });
    } else {
        alert('getUserMedia not supported in this browser.');
    }

    function start_microphone(stream) {
        ///////////////////
    }
}();

function sendInput() {
    $(document).ready(function() {
        $("button").click(function() {
            $.post("/tuner/getfreq/", {
                "sound": input
            }, function(data, status) {
                document.getElementById("post").innerHTML = data;
            });
        });
    });
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Thanawat.ch
  • 25
  • 1
  • 2
  • 7
  • To send a file to the server you need to upload it. I would suggest using AJAX for this. If you Google 'AJAX file upload' there are already a lot of questions covering this topic – Rory McCrossan Nov 10 '16 at 16:33
  • @RoryMcCrossan If you look at the code, you see that the upload part isn't the problem here. – Brad Nov 10 '16 at 16:39
  • @ThanawatKahothong Rather than using a server-side tuner, why not just do it client-side? This is a well covered example use case of the Web Audio API. – Brad Nov 10 '16 at 16:39
  • @Brad I know - that's why I only left that comment, to help with the uploading part – Rory McCrossan Nov 10 '16 at 16:41
  • @RoryMcCrossan Before that,i don't know what to do in function. thank you for your advice.It would be useful to me. – Thanawat.ch Nov 10 '16 at 16:41
  • https://subvisual.co/blog/posts/39-tutorial-html-audio-capture-streaming-to-node-js-no-browser-extensions - might be a helpful start. – axel.michel Nov 10 '16 at 16:41
  • @ThanawatKahothong You can either use MediaRecorder to create a full media file with headers and all that, or just send raw PCM samples (use a ScriptProcessorNode). – Brad Nov 10 '16 at 16:43
  • @axel.michel thank you :) – Thanawat.ch Nov 10 '16 at 17:00
  • @Brad ScriptProcessNode can send sound as a variable? i don' t know how use it, thank you for your advice. – Thanawat.ch Nov 11 '16 at 03:05

0 Answers0