【问题标题】:getting the amplitude of the microphone in windows phone获取 windows phone 中麦克风的振幅
【发布时间】:2014-04-08 21:18:18
【问题描述】:

我想获取 windows phone 中麦克风输入的实时幅度。实现这一目标的最简单有效的方法是什么?

【问题讨论】:

标签: windows-phone-7 audio windows-phone-8


【解决方案1】:

要获得振幅,您必须处理 Microphone 类的 BufferReady 事件:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/gg442302(v=vs.105).aspx

设置代码

Microphone microphone = Microphone.Default;
microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);
microphone.BufferDuration = TimeSpan.FromMilliseconds(1000);

byte[] buffer;
buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];

microphone.Start();

事件处理块

void microphone_BufferReady(object sender, EventArgs e)
{

    microphone.GetData(buffer);


    for(int i = 0; i< buffer.Length; i+=2)
    {
        //The value of sample is the amplitude of the signal
        short sample = BitConverter.ToInt16(new byte[2] { buffer[i], buffer[i + 1] }, 0);
    }
}

【讨论】:

  • 感谢您的回复。它在“microphone.BufferReady += new EventHandler(microphone_BufferReady);”处引发“System.NullReferenceException”。你能解决这个问题吗?
  • 我可以修复它。只需在 WMAppManifest.xml 中启用 ID_CAP_MICROPHONE。
猜你喜欢
  • 2012-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-31
相关资源
最近更新 更多