gpt4 book ai didi

c# - 录音机 c# UWP

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

我正在尝试在 UWP 上为 winphone 创建一个通话记录器。我正在尝试用音频图来做到这一点。我需要为输入设备(麦克风)创建一个节点,为输出设备(扬声器)创建一个节点并将它们提交到文件(wave/mp3)。

我收到异常。

        AudioGraph graph;
AudioDeviceInputNode deviceInputNode;
AudioDeviceOutputNode deviceOutputNode;
AudioFileOutputNode fileOutputNode;

private async Task InitAudiographAsync()
{

AudioGraphSettings settings = new AudioGraphSettings(AudioRenderCategory.Speech);
CreateAudioGraphResult result = await AudioGraph.CreateAsync(settings);
if (result.Status == AudioGraphCreationStatus.Success)
{
graph = result.Graph;

CreateAudioDeviceOutputNodeResult deviceOutputNodeResult = await graph.CreateDeviceOutputNodeAsync();

if (deviceOutputNodeResult.Status == AudioDeviceNodeCreationStatus.Success)
{
deviceOutputNode = deviceOutputNodeResult.DeviceOutputNode;

var microphone = await DeviceInformation.CreateFromIdAsync(
MediaDevice.GetDefaultAudioCaptureId(AudioDeviceRole.Default));

var inProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High);

var deviceInputNodeResult = await graph.CreateDeviceInputNodeAsync(MediaCategory.Speech, inProfile.Audio, microphone);

if (deviceInputNodeResult.Status == AudioDeviceNodeCreationStatus.Success)
{
deviceInputNode = deviceInputNodeResult.DeviceInputNode;

FileSavePicker saveFilePicker = new FileSavePicker();
saveFilePicker.FileTypeChoices.Add("Windows Media Audio", new List<string>() { ".wma" });
saveFilePicker.FileTypeChoices.Add("MPEG Audio Layer-3", new List<string>() { ".mp3" });
saveFilePicker.SuggestedFileName = "New Audio Track";
StorageFile file = await saveFilePicker.PickSaveFileAsync();

// File can be null if cancel is hit in the file picker
if (file == null)
{
return;
}

MediaEncodingProfile mediaEncodingProfile;
switch (file.FileType.ToString().ToLowerInvariant())
{
case ".mp3":
mediaEncodingProfile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High);
break;
case ".wav":
mediaEncodingProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High);
break;
default:
throw new ArgumentException();
}

CreateAudioFileOutputNodeResult fileOutputNodeResult = await graph.CreateFileOutputNodeAsync(file, mediaEncodingProfile);

if (fileOutputNodeResult.Status == AudioFileNodeCreationStatus.Success)
{
fileOutputNode = fileOutputNodeResult.FileOutputNode;
deviceInputNode.AddOutgoingConnection(deviceOutputNode);
deviceInputNode.AddOutgoingConnection(fileOutputNode);
graph.Start();
}

}
}
}
}

最佳答案

您是否检查了麦克风访问和文件访问的 list \功能。您是否收到拒绝访问异常?

关于c# - 录音机 c# UWP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36202209/

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