c# - 如何使用 pythonnet 从 python 订阅 c# 流?
问题描述
我需要用 python 分析 loopbackcapture 流。
我没有找到任何用于 wasapi loopbackcapture 的 python 包装,所以我不得不使用 c#(我没有任何经验)。
现在我有 c# 程序集 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 脚本。我怎样才能做到这一点?(我的意思是事件的触发和处理方面)
解决方案
推荐阅读
- java - Java Spring JPA - 字节 [] 到字符串
- c# - 我的测试用例没有执行,它开始执行但没有任何反应,并且显示未运行状态
- boost-test - CTest 和多测试二进制文件
- c# - TSQL 数组初始化和 LINQ Where on Array
- python - 使用 aiohttp 在线程中获取页面 - 得到 Future
连接到不同的循环 - java - 如何在spring-boot应用程序中的任何类/服务中获得身份验证
- python - 使用 python 和 boto3 在 aws 中获取配置的 S3 存储桶以获取详细的计费报告
- amazon-web-services - 使用 Ubuntu OVA 无法导入带有“ClientError: Unknown OS/Missing OS files”的 VM
- c++ - 如何使用 glDebugMessageControl 仅禁用一个特定 ID?
- python - 几何线组到具有密度的光栅图像