gpt4 book ai didi

c# - NAudio 拆分 mp3 文件

转载 作者:可可西里 更新时间:2023-11-01 08:33:42 24 4
gpt4 key购买 nike

我对音频或 mp3 的东西很陌生,一直在寻找一种方法来具有在 C#、asp.net 中拆分 mp3 文件的功能。在没有太多帮助的情况下用谷歌搜索了 3 天,我希望这里有人能给我指明正确的方向。

我可以使用 NAudio 来完成这个吗?有没有示例代码?提前致谢。

最佳答案

我在 C# 中拆分 mp3 文件的最终解决方案是使用 NAudio。这是一个示例脚本,希望它对社区中的某个人有所帮助:

string strMP3Folder = "<YOUR FOLDER PATH>";
string strMP3SourceFilename = "<YOUR SOURCE MP3 FILENAMe>";
string strMP3OutputFilename = "<YOUR OUTPUT MP3 FILENAME>";

using (Mp3FileReader reader = new Mp3FileReader(strMP3Folder + strMP3SourceFilename))
{
int count = 1;
Mp3Frame mp3Frame = reader.ReadNextFrame();
System.IO.FileStream _fs = new System.IO.FileStream(strMP3Folder + strMP3OutputFilename, System.IO.FileMode.Create, System.IO.FileAccess.Write);

while (mp3Frame != null)
{
if (count > 500) //retrieve a sample of 500 frames
return;

_fs.Write(mp3Frame.RawData, 0, mp3Frame.RawData.Length);
count = count + 1;
mp3Frame = reader.ReadNextFrame();
}

_fs.Close();
}

感谢 Mark Heath 对此的建议。

所需的命名空间是 NAudio.Wave。

关于c# - NAudio 拆分 mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6094287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com