A
A
Arei2013-04-07 12:29:01
.NET
Arei, 2013-04-07 12:29:01

Get microphone input volume

Hello, please tell me how can I get the microphone input value on a scale from 0 to 100.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
E
Exvel, 2013-04-07
@Arei

I tried this option. Seems to be working as it should.

using System;
using NAudio.Wave;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var waveIn = new WaveInEvent();
            waveIn.DataAvailable += WaveOnDataAvailable;
            waveIn.WaveFormat = new WaveFormat(8000, 1);
            waveIn.StartRecording();

            Console.ReadLine();
        }

        private static void WaveOnDataAvailable(object sender, WaveInEventArgs e)
        {
            for (int index = 0; index < e.BytesRecorded; index += 2)
            {
                short sample = (short)((e.Buffer[index + 1] << 8) | e.Buffer[index + 0]);

                float amplitude = sample / 32768f;
                float level = Math.Abs(amplitude); // от 0 до 1
                
                Console.WriteLine("Уровень: {0}%.", level * 100);
            }
        }
    }
}

C
Cyrus, 2013-04-07
@Cyrus

nAudio library . There are simple examples there: you set the sampling rate, bit depth and buffer size and get an event in the arguments of which is an array of amplitudes for this filling of this buffer.

A
Arei, 2013-04-07
@Arei

I need to get how loud I speak.

M
m08pvv, 2013-04-07
@m08pvv

Something like this, for example

E
Exvel, 2013-04-07
@exvel

It?
www.geekpedia.com/tutorial176_Get-and-set-the-wave-sound-volume.html

Oops. Not that.

E
Exvel, 2013-04-07
@exvel

Here is an example from NAudio
stackoverflow.com/a/3023180/963384

A
Arei, 2013-04-07
@Arei

built-in.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question