如何在 NETCore 中播放声音?

编程入门 行业动态 更新时间:2024-10-23 01:44:05
本文介绍了如何在 NETCore 中播放声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在 .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 中播放声音?

本文发布于:2023-11-14 15:11:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587728.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:声音   如何在   NETCore

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!