transform wav into byte[]

Asked

Viewed 40 times

0

I need to join three audios. I thought and I chose to turn them into a string of bytes to then concatenate them. However it is giving error in

File.ReadAllBytes : " "ControllerBase.File(byte[],string)" é um método, que não é válido no contexto fornecido"

 public async Task<IActionResult> recebertexto([FromForm]Texto txt)
    {
        try
        {
            if (ModelState.IsValid)
            {
                string conteudo = string.Format("Texto: {0}", txt.texto);

                await GerarAudioAsync("01a2d0519c21413686eddcdfed3d3a3d", txt.texto);



                byte[] arquivo1 = File.ReadAllBytes(GetVideoAsByte(@"1.wav"));
                byte[] arquivo2 = File.ReadAllBytes(GetVideoAsByte(@"2.wav"));
                byte[] arquivo3 = File.ReadAllBytes(GetVideoAsByte(@"3.wav"));

                byte[] arquivo4 = new byte[arquivo1.Length + arquivo2.Length + arquivo3.Length];

                long i;
                long j;

                for (i = 0; i < arquivo1.Length; i++)
                    arquivo4[i] = arquivo1[i];

                for (j = 0; j < arquivo2.Length; j++, i++)
                    arquivo4[i] = arquivo2[j];

                File.WriteAllBytes("final.mp3", arquivo4);

            }
        }
        catch (Exception ex)
        { 
            ViewBag.Error = "Erro ao gerar o  arquivo!";
        }
        return RedirectToAction("Index");
    }

Method to transform into byte:

  public static byte[] GetVideoAsByte(string videoPath)
        {
            byte[] byteData = null;

            using (var client = new System.Net.WebClient())
            {
                var url = new Uri(videoPath);
                byteData = client.DownloadData(url);
            }
            return byteData;
        }
  • Why try to call File.ReadAllBytes if your own code already gives you the byte array?

  • Dude you’re trying to join . wav files into a . mp3 like that in race? I don’t think it will work out no, these files have headers, they are not . raw files.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.