Israel
Asked

Hello,I'M Trying To Play An

Hello, I'm trying to play an audio (I'm coding in C# SDK)

I converted .mp3 to raw by audio conversion software, and when i play the .raw on audacity is sounds pretty fine

I tried to use _ezb.SoundV4.PlayData function like this:

byte[] bytes = File.ReadAllBytes("../path");

_ezb.SoundV4.PlayData(bytes,100);

but the audio sounds really bad

when i try to play the .mp3 in ARC it sounds better.

any ideas? thank you!


ARC Pro

Upgrade to ARC Pro

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.

PRO
Synthiam
#1   — Edited

Must save PCM as MONO 8 BIT and 14700 hz

I recommend loading and playing the file in real-time like this... Here's how the soundboard loads and plays the file. I compress the file so it can be stored in a much smaller memory footprint


if (openFileDialog1.FileName.ToLower().Contains(".mp3")) {

  using (NAudio.Wave.Mp3FileReader mp3 = new NAudio.Wave.Mp3FileReader(openFileDialog1.FileName)) {

    using (NAudio.Wave.WaveFormatConversionStream pcm = new NAudio.Wave.WaveFormatConversionStream(new NAudio.Wave.WaveFormat(EZ_B.EZBv4Sound.AUDIO_SAMPLE_BITRATE, 8, 1), mp3)) {

      using (MemoryStream ms = new MemoryStream()) {

        using (GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
          pcm.CopyTo(gz);

        _compressedAudioArray = ms.ToArray();
      }
    }
  }
} else if (openFileDialog1.FileName.ToLower().Contains(".wav")) {

  using (NAudio.Wave.WaveStream wav = new NAudio.Wave.WaveFileReader(openFileDialog1.FileName)) {

    using (NAudio.Wave.WaveFormatConversionStream pcm = new NAudio.Wave.WaveFormatConversionStream(new NAudio.Wave.WaveFormat(EZ_B.EZBv4Sound.AUDIO_SAMPLE_BITRATE, 8, 1), wav)) {

      using (MemoryStream ms = new MemoryStream()) {

        using (GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
          pcm.CopyTo(gz);

        _compressedAudioArray = ms.ToArray();
      }
    }
  }
} else {

  throw new Exception("Unsupported audio file type.");
}

Playback like this...


using (MemoryStream ms = new MemoryStream(_compressedAudioArray))
using (GZipStream gz = new GZipStream(ms, CompressionMode.Decompress))
  EZBManager.EZBs[_cf.SoundBoardv4.EZBIndex].SoundV4.PlayData(gz, 100);

Israel
#2  

It worked! Thank you very much!