2

I'm currently building an application for Windows Phone 8.1 using C#,

The aim of the app is to assess audio signals from the device's microphone, initially for frequency,

I was hoping to use the Accord library to help with this but have run into these errors:

XamlCompiler error WMC1006: Cannot resolve Assembly or Windows Metadata file 'System.Windows.Forms.dll'

\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v12.0\8.1\Microsoft.Windows.UI.Xaml.Common.targets(327,9): Xaml Internal Error error WMC9999: Type universe cannot resolve assembly: System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

I'm fairly certain that this is arising due to the references included in the project but I'm not to sure,

Here is my current code:

    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();
            }
        }
    }
}

Any help or guidance in resolving these errors would be greatly appreciated,

Thanks

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

1 Answers1

1

The original Accord.NET Framework is not accessible on other platforms than .NET.

There is an effort (of which I am responsible) for porting Accord.NET to mobile platforms via Portable Class Libraries. Several of these packages have been published on NuGet as well (prefix Portable Accord).

The Audio package is not published on NuGet, but you should be able to build it from source for Windows Phone 8.1. You can find the source for Portable Accord here.

Please note that only playback is supported, recording is not.

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114