C# 使用AudioVideoCaptureDevice在Windows Phone 8上录制PCM

C# 使用AudioVideoCaptureDevice在Windows Phone 8上录制PCM,c#,windows-phone-8,windows-phone,C#,Windows Phone 8,Windows Phone,以下代码使用AMR和AAC格式将从我的Windows Phone 8设备录制的音频正确记录到独立存储中。但是,当我尝试录制PCM格式时,应用程序崩溃并出现错误: Value does not fall within the expected range. Windows.Phone.Media.Capture.AudioVideoCaptureDevice.StartRecordingToStreamAsync(IRandomAccessStream stream) at

以下代码使用AMR和AAC格式将从我的Windows Phone 8设备录制的音频正确记录到独立存储中。但是,当我尝试录制PCM格式时,应用程序崩溃并出现错误:

    Value does not fall within the expected range.
Windows.Phone.Media.Capture.AudioVideoCaptureDevice.StartRecordingToStreamAsync(IRandomAccessStream stream)
       at WP8.Classes.AudioCaptureController.<StartRecordingAsync>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at WP8.ViewModels.CameraPageViewModel.<capture>d__13.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at WP8.ViewModels.CameraPageViewModel.<TakePictureAsync>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)
将格式更改为pcm以外的任何格式都有效

更新:出于某种原因,它现在似乎可以避免崩溃,但输出中显示了这一点:

A first chance exception of type 'System.ArgumentException' occurred in WP8.DLL
An exception of type 'System.ArgumentException' occurred in WP8.DLL and wasn't handled before a managed/native boundary
(WP8是我的dll的名称)代码在此之后正常运行,只有当我停止录制时才会崩溃,因为它说录制从未开始,并且AudioVideoCaptureDevice处于错误状态


我也尝试过使用var
AudioVideoCaptureDevice.SupportedAudioEncodingFormats
要检查Pcm是否可用,您可以使用XNA framework从麦克风录制Pcm(似乎microsoft在将数据写入文件时在该框架中有错误!)


请阅读这段代码和这篇文章,了解如何从诺基亚开发者门户网站以wav格式保存数据

谢谢Frederik,我已经开始使用XNA框架话筒,但是,由于比特率和质量都不太好!是的,但是您不能在代码中设置更高的sampleRate和每个示例的字节数吗?(请参阅诺基亚开发门户网站的WriteWavHeader)您可以在那里更改采样器,但如果您不将其作为记录在(160000Hz)下的相同采样率,它将运行得非常快,我怀疑会失真。您是否尝试捕捉该异常以查看异常对象是否提供更多详细信息?我有,不幸的是,它没有提供比上述内容更多的细节!
A first chance exception of type 'System.ArgumentException' occurred in WP8.DLL
An exception of type 'System.ArgumentException' occurred in WP8.DLL and wasn't handled before a managed/native boundary