如何使用字节创建wav类型文件 [英] How to create wav type file with bytes

查看:162
本文介绍了如何使用字节创建wav类型文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试用字节创建.wav类型的音频文件,实际上我有.m4a格式文件我将文件读入字节然后我创建另一个.wav格式文件,下面的代码

  var  bytes = File.ReadAllBytes(Server.MapPath(  Audios / Breakfast.m4a)); 
使用(FileStream fs = File.Create( @ C:\Docs \ myFile.wav))
{
fs.Write(bytes, 0 ,bytes.Length);
}



并且文件已创建,但无法播放。如果我尝试使用下面的代码使用Naudio dll读取创建的文件(myFile.wav)

var myReader = new WaveFileReader(@C:\Docs \ myFile .wav);



它显示如下错误信息

System.FormatException:不是WAVE文件 - 没有RIFF标题

这里如何通过使用字节创建.wav文件而没有任何问题?

TIA



我尝试过:



  var  bytes = File.ReadAllBytes(Server.MapPath( 音像/ Breakfast.m4a)); 
使用(FileStream fs = File.Create( @ C:\Docs \ myFile.wav))
{
fs.Write(bytes, 0 ,bytes.Length);
}

解决方案

这不起作用。

更改文件扩展名不会影响数据 - myFile.wav文件中的信息与Breakfast.m4a文件中的信息相同。这意味着它是一个有效的M4A文件,但是无效的WAV文件 - 所以WAV文件阅读器无法处理它。

这有点像从你的车上撬下福特徽章并装上法拉利的 - 这是不要愚弄任何人认为它是一辆跑车!



要将m4a文件改为wav,你必须改变格式,这不是一个简单的过程。我建议你找到一个预构建的转换器并将其用作命令行工具来进行转换。


你不能只是将一些字节转储到一个文件中并期望它们神奇地成为别的东西。



对源数据格式(M4A)和目标格式(WAV)进行一些研究,学习如何从中提取原始音频数据源代码,转换它,然后以目标格式写一个有效的文件。



这是一个关于WAV格式的一些信息的链接:里弗波浪 - 维基百科 [ ^ ]

Hi all , i am trying to create .wav type audio file with bytes, actually i have .m4a format file i read the file into bytes then i create a another .wav format file, with below code

var bytes = File.ReadAllBytes(Server.MapPath("Audios/Breakfast.m4a"));      
        using (FileStream fs = File.Create(@"C:\Docs\myFile.wav"))
            {
                fs.Write(bytes, 0, bytes.Length);
            }


and the file is created, but cannot play. if i try to read the created file(myFile.wav) by using Naudio dll with below code
var myReader = new WaveFileReader(@"C:\Docs\myFile.wav");

it show below Error Message
System.FormatException: Not a WAVE file - no RIFF header
here how can i Create .wav files without any issues by using Bytes ?
TIA

What I have tried:

var bytes = File.ReadAllBytes(Server.MapPath("Audios/Breakfast.m4a"));     
       using (FileStream fs = File.Create(@"C:\Docs\myFile.wav"))
           {
               fs.Write(bytes, 0, bytes.Length);
           }

解决方案

That won't work.
Changing the file extension does not affect the data - the information in the "myFile.wav" file is identical to the information in the "Breakfast.m4a" file. Which means it's a valid M4A file, but an invalid WAV file - so the WAV file reader can't process it.
It's a bit like prying the Ford badges off your car and fitting Ferrari ones - it's not going to fool anyone into thinking it's a sports car!

To change m4a files to wav you have to change the format, which is not a trivial process. I'd suggest you find a pre-built converter and use that as a command line tool to do the conversion.


You can't just dump some bytes into a file and expect that they magically become something else.

Do some research on the source data format (M4A) and the destination format (WAV), learn how to extract the raw audio data from the source, convert it and then write a valid file in the destination format.

Here is a link to some information on the WAV format: RIFF WAVE – Wikipedia[^]


这篇关于如何使用字节创建wav类型文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆