M
M
Max2017-03-29 12:38:19
JavaScript
Max, 2017-03-29 12:38:19

How to get the sampleRate for a microphone?

Hi all. There was a need to receive sampleRate for a microphone through JS.
Tried these approaches approach:

//Example 1
var context = new window.AudioContext();
var sampleRate = context.sampleRate;

//Example 2
var audioTimer = 0;
var sampleRate = 0;
recorder.onaudioprocess = function() {
     var time = new Date().getTime();
    if (audioTimer) {
        sampleRate = (1000 * 2048) / (time - audioTimer);  //2048 - buffer size
    }
    audioTimer = time;
}

But, in this way we get the sampleRate for the SPEAKERS, and not for the microphone.
Is there a way to get the sampleRate for the microphone?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Y, 2017-03-29
@1eqinfinity

The microphone is an analog device. The signal from it to the sound interface is analog. The same is generally true for speakers - they have an analog signal coming through the wires. The inputs and outputs of the audio interface are analog-to-digital and digital-to-analogue converters, respectively (ADC and DAC). Thus, only the interface has a sampling rate.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question