gpt4 book ai didi

c# - 将 Accord 音频库与 Windows Phone 8.1 应用程序(非 Silverlight)一起使用

转载 作者:太空宇宙 更新时间:2023-11-03 12:50:47 24 4
gpt4 key购买 nike

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

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

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

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.

我相当确定这是由于项目中包含的引用而引起的,但我不确定,

这是我当前的代码:

    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 上发布(前缀 Portable Accord)。

Audio 包未在 NuGet 上发布,但您应该能够从 Windows Phone 8.1 的源代码构建它。您可以找到 Portable Accord 的来源 here .

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

关于c# - 将 Accord 音频库与 Windows Phone 8.1 应用程序(非 Silverlight)一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35625813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com