C# Silverlight 获取声音频率

发布于 2024-12-02 12:20:14 字数 1405 浏览 0 评论 0原文

我一直在尝试使用如下代码从麦克风读取当前声音

_Capture 是一个 CaptureSource , _Encoder 是一个 SimpleAudioEncoder (自定义类)

_Capture = new CaptureSource();
_Encoder = new SimpleAudioEncoder(this);
_Encoder.CaptureSource = _Capture;

if (_Capture != null)
{
    _Capture.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
    CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
    if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
    {
        MessageBox.Show("_Capture.Start()");
        _Capture.Start();
    }
}

SimpleAudioEncoder

public class SimpleAudioEncoder : AudioSink
{
    public SimpleAudioEncoder() {

    }
    protected override void OnCaptureStarted()
    {

    }

    protected override void OnCaptureStopped()
    {

    }

    protected override void OnFormatChange(
    AudioFormat audioFormat) {

    }

    protected override void OnSamples(
    long sampleTimeInHundredNanoseconds,
    long sampleDurationInHundredNanoseconds,
    byte[] sampleData)
    {

    }
}

我猜测 sampleData byte[] 数组包含我正在查找的数据,但是我如何使用它来查找声音的频率?

那就太好了

如果我能找到像public double GetFreq(byte[] data)

这样的函数来使用

double Hertz = GetFreq(sampleData)

I've been trying to use some code like the following to read current sound from the mic

_Capture is a CaptureSource and _Encoder is a SimpleAudioEncoder (Custom class)

_Capture = new CaptureSource();
_Encoder = new SimpleAudioEncoder(this);
_Encoder.CaptureSource = _Capture;

if (_Capture != null)
{
    _Capture.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
    CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
    if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
    {
        MessageBox.Show("_Capture.Start()");
        _Capture.Start();
    }
}

Definition of SimpleAudioEncoder

public class SimpleAudioEncoder : AudioSink
{
    public SimpleAudioEncoder() {

    }
    protected override void OnCaptureStarted()
    {

    }

    protected override void OnCaptureStopped()
    {

    }

    protected override void OnFormatChange(
    AudioFormat audioFormat) {

    }

    protected override void OnSamples(
    long sampleTimeInHundredNanoseconds,
    long sampleDurationInHundredNanoseconds,
    byte[] sampleData)
    {

    }
}

Im guessing that the sampleData byte[] array has the data I'm looking for but how can I use it to find the frequency of the sound?

It would be great if I could find a function like

public double GetFreq(byte[] data)

To use like

double hertz = GetFreq(sampleData)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪淡了忧伤 2024-12-09 12:20:14

建立声音的频率需要将信号从时域转换到频域。它将涉及傅里叶变换以及对输出的后续分析。对于没有对 DSP 技术有相当透彻了解的人来说,这确实不是一份工作。如果您必须问,那么您距离自己实现这一点还有很长的路要走。我推荐一个第三方库。

此页面提供了相当不错的视图频率检测新手。

Establishing the frequency of the sound requires converting the signal from the time domain to the frequency domain. It will involve Fourier transforms and subsequent analysis of the output. It's really not a job for anyone without a pretty thorough understanding of DSP techniques. If you have to ask, then you're a long way from being able to implement this yourself. I'd recommend a third party library.

This page gives a fairly good view from somebody new to frequency detection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文