C# Silverlight 获取声音频率
我一直在尝试使用如下代码从麦克风读取当前声音
_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
建立声音的频率需要将信号从时域转换到频域。它将涉及傅里叶变换以及对输出的后续分析。对于没有对 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.