我需要使用python分析loopbackcapture流。
我没有为wasapi loopbackcapture找到任何python包装,所以我不得不使用c#(我没有任何经验)。
现在我有c#汇编dll,该DLL被包装到wasapiLoopbackCapture并将其记录到文件中。但是我需要实时进行分析。
using (WasapiCapture soundIn = new WasapiLoopbackCapture())
{
//initialize the soundIn instance
soundIn.Initialize();
//create a SoundSource around the the soundIn instance
SoundInSource soundInSource = new SoundInSource(soundIn) { FillWithZeros = false };
//create a source, that converts the data provided by the soundInSource to any other format
IWaveSource convertedSource = soundInSource
.ChangeSampleRate(sampleRate) // sample rate
.ToSampleSource()
.ToWaveSource(bitsPerSample); //bits per sample
//channels...
convertedSource = convertedSource.ToMono()
//create a new wavefile
WaveWriter waveWriter = new WaveWriter(output_file, convertedSource.WaveFormat)
//register an event handler for the DataAvailable event of the soundInSource
soundInSource.DataAvailable += (s, e) =>
{
//read data from the converedSource
byte[] buffer = new byte[convertedSource.WaveFormat.BytesPerSecond / 2];
int read;
//keep reading as long as we still get some data
while ((read = convertedSource.Read(buffer, 0, buffer.Length)) > 0)
{
//write the read data to a file
waveWriter.Write(buffer, 0, read);
}
};
}
1)是否可以从c#返回流并从python订阅它?
2)另一个变体是在c#端分析流并向python脚本触发一些事件。我怎样才能做到这一点? (我的意思是事件是事物的触发和处理)