Netherlands
Asked — Edited
Resolved Resolved by DJ Sures!

Refreshing/Updating A File On The Soundboard

Hi,

I wonder whether it is possible to refresh through script the mp3/wav files that are added to the soundboard control for an EZ-B v4 in ARC. Right now it seems that the only way to refresh the file is to do it manually through ARC.

My A.I. software (which is exogenous to ARC) generates mp3/wav files for speech synthesis, and I basically want a script to play the latest version of the 'saythisnext.mp3' file that I store locally. I could not find anything in the learning sections or script help inside ARC.

Before people kindly point me to the text-to-speech options in ARC: I want to make use of Ivona's developers cloud service so that I may also use for instance the Speech Synthesis Markup Language. Though I may switch to other tts options that allow markup for emotional intonation. In any case, I end up with a music file that I want to play.

Thanks in advance!


ARC Pro

Upgrade to ARC Pro

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!

PRO
Synthiam
#9  

Here's the code to get you started...



      string filename = @"c:\test\blah.mp3";

      using (var fm = new EZ_Builder.UCForms.FormMicChooseSoundBoardv4()) {

        fm.StartPosition = FormStartPosition.CenterParent;

        if (fm.ShowDialog() != System.Windows.Forms.DialogResult.OK)
          return;

        var soundBoard = (EZ_Builder.UCForms.FormSoundBoardEZBv4)EZ_Builder.EZBManager.FormMain.GetControlByNameAllPages(fm.DestinationFormName);

        var csb = new EZ_Builder.Config.Sub.SoundBoardv4Config();

        csb.Filename = "FILENAME OF MP3 to SHOW IN SOuNDBOARD";

          if (filename.ToLower().Contains(".mp3")) {

            using (NAudio.Wave.Mp3FileReader mp3 = new NAudio.Wave.Mp3FileReader(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);

                  csb = new SoundBoardv4Config(Path.GetFileName(filename), ms.ToArray());
                }
              }
            }
          } else if (filename.ToLower().Contains(".wav")) {

            using (NAudio.Wave.WaveStream wav = new NAudio.Wave.WaveFileReader(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);

                  csb = new SoundBoardv4Config(Path.GetFileName(filename), ms.ToArray());
                }
              }
            }
          } else {

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




        soundBoard.AddSoundInfoToFirstEmptySlot(csb);
      }

#10  

One thing to keep in mind is that the EZB speaker is not the only way to get the robot to talk. If you have the room on your robot, you can also mount a wireless speaker (perhaps Bluetooth) on the robot and use the wireless channel to transmit whatever you want directly from the computer.

Since the script language has a function for calling external programs, you can still use a script to determine when the file will play and what file it should be.

Netherlands
#11  

@WBS00001 Good suggestion. I hope to share my software with as many EZ-Robot users as I can some day, hence my preference for using the onboard speaker to make it available out-of-the-box. But a Bluetooth device might be a personal option later on. (actually, later on I want to have an Alan, (looking at you @fxrtst))

@DJSures I managed to get quite far (the plugin tutorial rocks, and thanks for the demo code!). The only thing that bugs me is:

soundBoard.AddSoundInfoToFirstEmptySlot(csb);

I tried to find a way to do something like:


if(/* no sounds in the sound board */){
    soundBoard.AddSoundInfoToFirstEmptySlot(csb);
} else {
   // Overwrite the first sound
}

PRO
Synthiam
#12  

Hmmm - that's easy.. try this



var cfg = soundBoard.GetConfiguration();

if (cfg.SoundBoardv4.length == 0) {

    soundBoard.AddSoundInfoToFirstEmptySlot(csb);
} else {

    cfg.SoundBoardv4.SoundBoardList[2] = csb;

    soundBoard.SetConfiguration(cfg);
}

That will extract the entire configuration data of the soundboard. All sounds and respective data are in the SoundBoardList array. Change out the index with the new configuration. And finally, set the configuration back into the control.

Netherlands
#13  

Thanks! I got it to work now. Also thanks to all the other users for input and suggestions.