C# 在Windows Phone 8.1应用程序中使用Accord音频库(非Silverlight)

C# 在Windows Phone 8.1应用程序中使用Accord音频库(非Silverlight),c#,audio,windows-phone-8.1,fft,accord.net,C#,Audio,Windows Phone 8.1,Fft,Accord.net,我目前正在使用C#为Windows Phone 8.1构建一个应用程序 该应用程序的目的是评估来自设备麦克风的音频信号,最初是频率 我本来希望使用Accord库来帮助解决这个问题,但遇到了以下错误: XamlCompiler错误WMC1006:无法解析程序集或Windows 元数据文件“System.Windows.Forms.dll” \程序文件 (x86)\MSBuild\Microsoft\WindowsXaml\v12.0\8.1\Microsoft.Windows.UI.Xaml.Co

我目前正在使用C#为Windows Phone 8.1构建一个应用程序

该应用程序的目的是评估来自设备麦克风的音频信号,最初是频率

我本来希望使用Accord库来帮助解决这个问题,但遇到了以下错误:

XamlCompiler错误WMC1006:无法解析程序集或Windows 元数据文件“System.Windows.Forms.dll”

\程序文件 (x86)\MSBuild\Microsoft\WindowsXaml\v12.0\8.1\Microsoft.Windows.UI.Xaml.Common.targets(327,9): Xaml内部错误WMC9999:无法解析类型universe 程序集:System.Windows.Forms,版本=4.0.0.0,区域性=中性, PublicKeyToken=b77a5c561934e089

我相当肯定,这是由于项目中包含的参考资料引起的,但我不确定

这是我目前的代码:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    using Accord.Audio;
    using Accord.Controls;
    using Accord.DirectSound;
    using Accord.Imaging;
    using Accord.MachineLearning;
    using Accord.Math;
    using Accord.Statistics;
    using Accord;
    using AForge;
    using AForge.Controls;
    using AForge.Imaging;
    using AForge.Math;
    using AForge.Video;
    using Windows.Media.Capture;
    using Windows.Storage;
    using Windows.Storage.Streams;
    using Windows.Storage.Pickers;
    using System.Diagnostics;
    using Windows.Media;
    using Windows.Media.MediaProperties;
    using Accord.Audio.Formats;
    using Accord.Audio.Windows;

    namespace Test2
    {
        public sealed partial class MainPage : Page
    {
        private MediaCapture _mediaCaptureManager;
        private StorageFile _recordStorageFile;
        private bool _recording;
        private bool _userRequestedRaw;
        private bool _rawAudioSupported;
        private IRandomAccessStream _audioStream;
        private FileSavePicker _fileSavePicker;
        private DispatcherTimer _timer;
        private TimeSpan _elapsedTime;


        public MainPage()
        {
            this.InitializeComponent();

            this.NavigationCacheMode = NavigationCacheMode.Required;

            InitializeAudioRecording();
        }
        private static void DecodeAudioFile()
        {

            String fileName = "record.wav";

            WaveDecoder sourceDecoder = new WaveDecoder(fileName);

            Signal sourceSignal = sourceDecoder.Decode();

            RaisedCosineWindow window = RaisedCosineWindow.Hamming(1024);

            Signal[] windows = sourceSignal.Split(window, 512);

            ComplexSignal[] complex = windows.Apply(ComplexSignal.FromSignal);

            complex.ForwardFourierTransform();

            Debug.WriteLine(complex);
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

        }

        private async void InitializeAudioRecording()
        {
            _mediaCaptureManager = new MediaCapture();
            var settings = new MediaCaptureInitializationSettings();
            settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
            settings.MediaCategory = MediaCategory.Other;
            settings.AudioProcessing = (_rawAudioSupported && _userRequestedRaw) ? AudioProcessing.Raw : AudioProcessing.Default;

            await _mediaCaptureManager.InitializeAsync(settings);

            Debug.WriteLine("Device initialised successfully");

            _mediaCaptureManager.RecordLimitationExceeded += new RecordLimitationExceededEventHandler(RecordLimitationExceeded);
            _mediaCaptureManager.Failed += new MediaCaptureFailedEventHandler(Failed);
        }

        private void Failed(MediaCapture sender, MediaCaptureFailedEventArgs errorEventArgs)
        {
            throw new NotImplementedException();
        }

        private void RecordLimitationExceeded(MediaCapture sender)
        {
            throw new NotImplementedException();
        }



        private async void CaptureAudio()
        {
            try
            {
                Debug.WriteLine("Starting record");
                String fileName = "record.wav";

                _recordStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

                Debug.WriteLine("Create record file successfully");
                Debug.WriteLine(fileName);
                MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Auto);


                await _mediaCaptureManager.StartRecordToStorageFileAsync(recordProfile, this._recordStorageFile);

                Debug.WriteLine("Start Record successful");
                _recording = true;
            }
            catch (Exception e)
            {
                Debug.WriteLine("Failed to capture audio");
            }

            DecodeAudioFile();
        }
        private async void StopCapture()
        {
            if (_recording)
            {
                Debug.WriteLine("Stopping recording");
                await _mediaCaptureManager.StopRecordAsync();
                Debug.WriteLine("Stop recording successful");

                _recording = false;
            }
        }

        private async void PlayRecordedCapture()
        {
            if (!_recording)
            {
                var stream = await _recordStorageFile.OpenAsync(FileAccessMode.Read);
                Debug.WriteLine("Recording file opened");
                playbackElement1.AutoPlay = true;
                playbackElement1.SetSource(stream, _recordStorageFile.FileType);
                playbackElement1.Play();
            }
        }

        private void Capture_Click(object sender, RoutedEventArgs e)
        {
            Capture.IsEnabled = false;
            Stop.IsEnabled = true;
            CaptureAudio();
        }

        private void Stop_Click(object sender, RoutedEventArgs e)
        {
            Capture.IsEnabled = true;
            Stop.IsEnabled = false;
            StopCapture();
        }

        private void Playback_Click(object sender, RoutedEventArgs e)
        {
            PlayRecordedCapture();
        }
        private void backBtn_Click(object sender, RoutedEventArgs e)
        {
            if (Frame.CanGoBack)
            {
                Frame.GoBack();
            }
        }
    }
}
我们将非常感谢在解决这些错误方面提供的任何帮助或指导

谢谢

除了.NET之外,其他平台无法访问原始的Accord.NET框架

通过可移植类库将Accord.NET移植到移动平台是一项努力(我负责这项工作)。其中一些软件包也在NuGet上发布(前缀为Portable Accord)

该音频包未在NuGet上发布,但您应该能够从Windows Phone 8.1的源代码构建它。你可以找到便携式雅阁的来源

请注意,仅支持播放,不支持录制