我正在使用惊人的NAudio框架来获取音频设备列表.
但正如我所看到的那样,音频设备是PC的集成音频和耳机是不可能的.我的意思是他们有相同的名字,只有当我们插入耳机它才会进入Active状态.
想象一下,如果我使用插入式耳机启动应用程序,我如何知道当前设备是耳机而不是PC的集成音频?
我的意思是我们可以通过NAduio检测到插入的音频设备是外部音频设备并且是耳机本身吗?
var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();
// Allows you to enumerate rendering devices in certain states
var endpoints = enumerator.EnumerateAudioEndPoints(
DataFlow.Render,
DeviceState.Unplugged | DeviceState.Active);
foreach (var endpoint in endpoints)
{
Console.WriteLine("{0} - {1}", endpoint.DeviceFriendlyName, endpoint.State);
}
// Aswell as hook to the actual event
enumerator.RegisterEndpointNotificationCallback(new NotificationClient());
Run Code Online (Sandbox Code Playgroud)
NotificationClient的实现方式如下:
class NotificationClient : NAudio.CoreAudioApi.Interfaces.IMMNotificationClient
{
void IMMNotificationClient.OnDeviceStateChanged(string deviceId, DeviceState newState)
{
Console.WriteLine("OnDeviceStateChanged\n Device Id -->{0} : Device State {1}", deviceId, newState);
}
void IMMNotificationClient.OnDeviceAdded(string pwstrDeviceId) …Run Code Online (Sandbox Code Playgroud) 我正在开发适用于音频数据的UWP应用程序(适用于Windows 10).它以浮点数样本的形式在开始时接收样本缓冲区,这些项目从-1f变为1f.之前我使用过NAudio.dll 1.8.0,它提供了所有必要的功能.使用WaveFileReader,waveBuffer.FloatBuffer,WaveFileWriter类.但是,当我完成此应用程序并尝试构建Relese版本时,出现此错误:ILT0042:当前不支持指针类型的数组:'System.Int32*[]'.
我试图解决它:
1)https://forums.xamarin.com/discussion/73169/uwp-10-build-fail-arrays-of-pointer-types-error
有建议删除.dll的链接,但我需要它.
2)我尝试使用Manage NuGet Packages安装相同版本的NAudio,但WaveFileReader,WaveFileWriter不可用.
3)在NAudio开发人员的回答中(如何使用NAudio在Windows 10中存储.wav文件)我已经阅读了有关使用AudioGraph的内容,但我只能在实时播放中构建浮点数组样本,但我需要获取完整的示例包音频文件上传后立即.在录制过程或播放过程中获取样本的示例:https: //docs.microsoft.com/ru-ru/windows/uwp/audio-video-camera/audio-graphs
这就是我需要帮助的原因:如何在音频文件上传后让FloatBuffer处理样本?例如,用于构建音频波或计算音频效果应用.
先感谢您.
我曾尝试使用FileStream和BitConverter.ToSingle(),但是与NAudio相比,我有不同的结果.换句话说,我仍在寻找解决方案.
private float[] GetBufferArray()
{
string _path = ApplicationData.Current.LocalFolder.Path.ToString() + "/track_1.mp3";
FileStream _stream = new FileStream(_path, FileMode.Open);
BinaryReader _binaryReader = new BinaryReader(_stream);
int _dataSize = _binaryReader.ReadInt32();
byte[] _byteBuffer = _binaryReader.ReadBytes(_dataSize);
int _sizeFloat = sizeof(float);
float[] _floatBuffer = new float[_byteBuffer.Length / _sizeFloat];
for (int i = 0, j = 0; i < _byteBuffer.Length - _sizeFloat; i += _sizeFloat, j++)
{
_floatBuffer[j] = …Run Code Online (Sandbox Code Playgroud)Microsoft语音系统有一个很好的示例代码,但是添加回送以记录正在播放的内容而不是通过麦克风记录的内容时,我遇到了问题。提供视频的文字说明,例如不在扬声器上播放时。似乎是要执行此操作的库,但是我在将其推到识别器的音频流时遇到类型错误:
using System;
using System.Speech.Recognition;
using NAudio.Wave;
using NAudio.CoreAudioApi.Interfaces;
using NAudio.CoreAudioApi;
using System.IO;
using System.Speech.AudioFormat;
namespace SpeechRecognitionApp
{
class Program
{
static void Main(string[] args)
{
// Create an in-process speech recognizer for the en-US locale.
using (
SpeechRecognitionEngine recognizer =
new SpeechRecognitionEngine(
new System.Globalization.CultureInfo("en-US")))
{
// Create and load a dictation grammar.
recognizer.LoadGrammar(new DictationGrammar());
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Configure input to the speech recognizer.
//recognizer.SetInputToDefaultAudioDevice();
WasapiLoopbackCapture capture …Run Code Online (Sandbox Code Playgroud) c# speech-recognition naudio sound-recognition naudio-framework
我终于构建了一个程序来使用 NAudio 收听内部音频环回,并输出识别的文本。问题是它会倾听,并且总是说,例如:
Recognized text: had
Recognized text: had
Recognized text: had
Recognized text: had
Recognized text: had had phone Le K add phone Laton
Recognized text: had phone looked had phone looked had phone looked had phone lo
oked zone
Recognized text: had phone lines to had, had phone looked had phone looked had p
hone line had phone
Recognized text: had phone line had phone looked had phone
Recognized text: had phone looked had phone looked had phone …Run Code Online (Sandbox Code Playgroud)