NAudio 分割 mp3 文件
我对音频或 mp3 内容非常陌生,正在寻找一种方法来在 C#、asp.net 中分割 mp3 文件。在谷歌搜索了三天但没有得到太多帮助之后,我希望这里有人能给我指出正确的方向。
我可以使用 NAudio 来完成此任务吗?有相关的示例代码吗?提前致谢。
I am very new to audio or mp3 stuff, was looking for a way to have a feature to split an mp3 file in C#, asp.net. After googling for a good 3-day without much of a great help, I am hoping that somebody here can point me to a right direction.
Can I use NAudio to accomplish this? Is there any sample code for that? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在 C# 中分割 mp3 文件的最终解决方案是使用 NAudio。这是一个示例脚本,希望它对社区中的某个人有所帮助:
感谢 Mark Heath 对此的建议。
所需的命名空间是 NAudio.Wave。
My final solution to split mp3 file in c# is to use NAudio. Here is a sample script for that, hope it helps someone in the community:
Thanks to Mark Heath's suggestion for this.
The namespace required is NAudio.Wave.
MP3 文件由一系列 MP3 帧组成(通常在开头和结尾加上 ID3 标签)。分割 MP3 文件的最简洁方法是将一定数量的帧复制到新文件中(如果很重要,也可以选择带上 ID3 标签)。
NAudio 的
MP3FileReader
类具有一个ReadNextFrame
方法。这将返回一个MP3Frame
类,其中包含RawData
属性中字节数组形式的原始数据。它还包括一个SampleCount
属性,您可以使用它来准确测量每个 MP3 帧的持续时间。An MP3 File is made up of a sequence of MP3 frames (plus often ID3 tags on the beginning and end). The cleanest way to split an MP3 file then is to copy a certain number of frames into a new file (and optionally bring the ID3 tags along too if that is important).
NAudio's
MP3FileReader
class features aReadNextFrame
method. This returns anMP3Frame
class, which contains the raw data as a byte array in theRawData
property. It also includes aSampleCount
property which you can use to accurately measure the duration of each MP3 Frame.前面的答案帮助我开始了。 NAudio 是必经之路。
对于我的 PodcastTool,我需要以 2 分钟的间隔分割播客,以便更快地搜索特定位置。
下面是每 N 秒分割一个 mp3 的代码:
The previous answers helped me get started. NAudio is the way to go.
For my PodcastTool I needed to to split podcasts at 2 minute intervals to make seeking to a specific place faster.
Here's the code to split an mp3 every N seconds:
这些会很有帮助Alvas Audio(商业)和ffmpeg
these would be helpful Alvas Audio (commercial) and ffmpeg
如果您想分割播客,请将曲目复制到音频设备(在我的例子中为游泳标头),并包含一个由 Google 的文本转语音服务制作的小音频标头,以识别曲目。 (例如“一百个物体中的世界历史。第 15 集。第 1 条,共 4 条”)您可以检查一个小 bash 脚本 https://github.com/pulijon/cpodcast/blob/main/cutpodcast.bash
准备添加西班牙语音频头。对于其他语言,您应该更改选项 -l 和标题字符串
If you want to split podcasts, copy the tracks to an audio device (swimming headers in my case) and include a little audio header made from the Text To Speech service from Google to identify the tracks. (e.g. "History of the world in a hundred objects. Episode 15. Track 1 of 4") you could check a little bash script https://github.com/pulijon/cpodcast/blob/main/cutpodcast.bash
It is prepared to add the audio header in Spanish. For other languages you should change the option -l and the string of header