在网页上扒音乐资源+m4a音频文件的解码(用c#解码为wav格式)

  1. 需要在音乐播放时在右边的文件里找m4a格式的文件
  2. 找格式的时候需要把鼠标放到文件名称上看后缀
  3. 然后点在网页中跳转即可自动下载

注意一下路径就可以

using System;
using System.Diagnostics;
using System.IO;
using System;
using NAudio.Wave;
using MediaFoundation;
namespace DecodeM4aToWav
{
    using System;
    using NAudio.Wave;

    class Program
    {
        static void Main(string[] args)
        {
            string inputFile = @"D:\code\cs\ProjectBasedOnRaylib\Assets\bgmFruit.m4a";
            string outputFile = @"D:\code\cs\ProjectBasedOnRaylib\Assets\bgmFruit.wav";

            try
            {
                // 使用MediaFoundationReader来解码M4A
                using (var reader = new MediaFoundationReader(inputFile))
                {
                    // 创建一个WaveFileWriter来写入WAV文件
                    using (var writer = new WaveFileWriter(outputFile, reader.WaveFormat))
                    {
                        // 读取并写入数据
                        byte[] buffer = new byte[reader.WaveFormat.AverageBytesPerSecond];
                        int read;
                        while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            writer.Write(buffer, 0, read);
                        }
                    }
                }

                Console.WriteLine("文件已成功转换为WAV格式.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("转换过程中出现错误: " + ex.Message);
            }
        }
    }



}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值