我目前正在使用C#为Windows Phone 8.1构建应用程序,
该应用程序的目的是评估来自设备麦克风的音频信号,最初是频率,
我希望使用Accord库来解决此问题,但是遇到了以下错误:
我相当确定这是由于项目中包含的引用引起的,但我不确定,
这是我当前的代码:
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();
}
}
}
}
解决这些错误的任何帮助或指导,将不胜感激,
谢谢
最佳答案
原始的Accord.NET Framework在.NET以外的其他平台上无法访问。
(通过我负责)需要通过便携式类库将Accord.NET移植到移动平台上。其中的一些软件包也已在NuGet上发布(前缀可移植Accord)。
音频程序包未在NuGet上发布,但是您应该能够从Windows Phone 8.1的源代码中构建它。您可以找到Portable Accord here的源。
请注意,仅支持播放,不支持录制。
关于c# - 在Windows Phone 8.1应用程序中使用Accord音频库(不是Silverlight),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35625813/