I need to analyze loopbackcapture stream with python.
I didn't found any python wrappings for wasapi loopbackcapture, so I had to use c# (in which I don't have any experience).
For now I have c# assembly dll which is wrappings to wasapiLoopbackCapture and records this to the file. But I need to perform analysis on the real time.
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) Is it possible to return stream from c# and subscribe on it from python?
2) another variant is to analyze stream on c# side and fire some events to python script. how can I do this? ( I mean event's firing and handling side of thing)