我正在尝试在 .Net Core 控制台应用程序中播放声音,但我无法弄清楚.
I'm trying to play a sound inside a .Net Core console application and I can't figure this out.
我正在寻找在 .Net Core 环境中管理的东西,可能像常规的 .Net :
I am looking for something managed inside the .Net Core environment, maybe like regular .Net :
// Not working on .Net Core System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:mywavfile.wav"); player.Play();在他们讨论的 dotnet core Github 上发现了一个问题.
Found an issue on dotnet core Github where they talk about it.
github/dotnet/core/issues/74
他们说没有用于音频播放的高级 API,但问题已经 9 个月了,所以我希望有新的东西吗?
They say there is no high-level API for audio playback but the issue is 9 months old, so I hope there is something new ?
推荐答案现在有一种方法可以使用 NAudio 库来实现(因为 1.9.0-preview1) 但它只适用于 Windows.
There is now a way to do it with NAudio library (since 1.9.0-preview1) but it will only works on Windows.
因此使用 NAudio,这里是在 .NET Core 中播放声音的代码,假设您是在 Windows 环境中执行此操作.
So using NAudio, here the code to play a sound in .NET Core assuming you are doing it from a Windows environment.
using (var waveOut = new WaveOutEvent()) using (var wavReader = new WaveFileReader(@"c:mywavfile.wav")) { waveOut.Init(wavReader); waveOut.Play(); }要获得更全球化的解决方案,您应该选择@Fiodar 的利用 Node.js 的解决方案.
For a more global solution, you should go for @Fiodar's one taking advantage of Node.js.
更多推荐
如何在 NETCore 中播放声音?
发布评论