J'utilise NAudio lib pour créer un service Windows, pour capturer l'audio de la carte son, lancer Wasapi. Mais sur l'un des ordinateurs, je reçois hresult = -2147024809, quand j'appelle audioClientInterface.Initialize Voici le code que j'utilise pour capturer.IAudioClient :: Initialize renvoie (E_InvalidArg, 0x80070057, -2147024809)
public partial class TestRecorder : ServiceBase
{
private static readonly Logger _logger = LogManager.GetLogger("ServiceLogger");
public TestRecorder()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
ThreadPool.QueueUserWorkItem(x =>
{
using (var rec = new Recorder())
{
rec.Start();
Thread.Sleep(10000);
rec.Stop();
}
});
}
protected override void OnStop()
{
}
internal void TestStartupAndStop(string[] args)
{
this.OnStart(args);
Console.ReadLine();
this.OnStop();
}
}
Here is code of Recorder.
public class Recorder : IDisposable
{
private static readonly Logger _logger = LogManager.GetLogger("ServiceLogger");
private WasapiCapture MicroCapture { get; set; }
private WaveFileWriter Writer { get; set; }
public Recorder()
{
var deviceEnum = new MMDeviceEnumerator();
MMDevice micro = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
MicroCapture = new WasapiCapture(micro);
MicroCapture.DataAvailable += OnDataAvailible;
Writer = new WaveFileWriter(@"C:\Temp\test.wav", MicroCapture.WaveFormat);
_logger.Trace("Recorder is initialized");
}
private void OnDataAvailible(object sender, WaveInEventArgs e)
{
if (e.BytesRecorded > 0)
{
Writer.Write(e.Buffer, 0, e.BytesRecorded);
}
}
public void Start()
{
try
{
MicroCapture.StartRecording();
_logger.Trace("Recorder started");
}
catch (Exception ex)
{
_logger.Fatal(ex);
}
}
public void Stop()
{
try
{
MicroCapture.StopRecording();
_logger.Trace("Recorder stopped");
}
catch (Exception ex)
{
_logger.Fatal(ex);
}
}
public void Dispose()
{
MicroCapture.Dispose();
Writer.Dispose();
_logger.Trace("Capture and writer disposed");
}
}
J'ai essayé d'installer 3 pilotes différents. J'ai essayé d'utiliser différents formats. NAudio envoie les prochains paramètres
audioClientInterface.Initialize envoie les paramètres suivants.
shareMode = Shared,
streamFlags = None,
bufferDuration = 1000000,
periodicity = 0,
waveFormat = 32 bit PCM: 48kHz 2 channels wBitsPerSample:32 dwChannelMask:3 subFormat:00000003-0000-0010-8000-00aa00389b71 extraSize:22,
audioSessionGuid = 00000000-0000-0000-0000-000000000000
Dans les paramètres Haut-parleur et Microphone, sélectionnez 48000 hz 16 bit
. S'il vous plaît donnez-moi un indice pour résoudre ce problème sur comment puis-je déboguer ou résoudre ce problème. Le modèle de carte son est VIA vt1708s
, le modèle de carte mère est Asus P8H61-M LX3 R2.0
IAudioClient :: IsFormatSupproted renvoie S_OK.