c# UWP 听力图

Posted

技术标签:

【中文标题】c# UWP 听力图【英文标题】:audiograph c# UWP 【发布时间】:2016-03-24 14:10:14 【问题描述】:

我正在尝试在 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();
                        

                    
                
            
        

【问题讨论】:

【参考方案1】:

您是否检查了清单\功能以进行麦克风访问和文件访问。您是否收到拒绝访问异常?

【讨论】:

以上是关于c# UWP 听力图的主要内容,如果未能解决你的问题,请参考以下文章

听力检查ac38,bc28是啥意思

耳朵听力检测dB是分贝吗

4.18上午 听力补充词汇复习 听力国家词汇

英语广播原声听力100篇MP3及听力原文

TOEIC托业听力阅读考试

好学多智能英语听力机--听力熊,搭载星宸科技SSD222D芯片