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);
}
}
}
}
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
xmlns:log="clr-namespace:MainProgram.App.Log;assembly=MainProgram"