在.NET Core中录制音频 [英] Record Audio in .NET Core

查看:583
本文介绍了在.NET Core中录制音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示,我希望从.NET Core中的麦克风捕获音频。对我来说,跨平台是很重要的。我已经在Windows,Linux和OSX上的OpenCV中进行了大量视频处理。音频对我来说是一个难题。

解决方案

OpenTK.NETCore是OpenTK的一个非常好的跨平台端口。 / p>

使用它的 AudioCapture 类,我已经能够捕获不同操作系统平台上的麦克风数据。

 使用(var audioCapture = new AudioCapture(_recorders.First(),_sampling_rate,ALFormat.Mono16,buffer_length_samples))
{
audioCapture.Start();

int available_samples = audioCapture.AvailableSamples;

_buffer = _pool.Rent(MathHelper.NextPowerOfTwo((int)((available_samples * _sampleToByte /(double)BlittableValueType.StrideOf(_buffer))+ 0.5))));;

if(available_samples> 0)
{
audioCapture.ReadSamples(_buffer,available_samples);
}
else
{
_pool.Return(_buffer);
}
}

编辑:基于 Parrot OpenTK示例中的项目。


As the title suggests, I'm looking to capture audio from a microphone in .NET Core. It's important for me that it's cross platform. I'm doing a lot of video processing in OpenCV on Windows, Linux and OSX already. Audio is a missing piece of the puzzle for me.

解决方案

OpenTK.NETCore is a really good cross platform port for OpenTK.

Using it's AudioCapture class I have been able to capture microphone data across different OS platforms.

using (var audioCapture = new AudioCapture(_recorders.First(), _sampling_rate, ALFormat.Mono16, buffer_length_samples))
{
    audioCapture.Start();

    int available_samples = audioCapture.AvailableSamples;

    _buffer = _pool.Rent(MathHelper.NextPowerOfTwo((int)((available_samples * _sampleToByte / (double)BlittableValueType.StrideOf(_buffer)) + 0.5)));

    if (available_samples > 0)
    {
        audioCapture.ReadSamples(_buffer, available_samples);
    }
    else
    {
        _pool.Return(_buffer);
    }
}

Edit: Based on Parrot project in OpenTK samples.

这篇关于在.NET Core中录制音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆