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

Discover the limitless potential of robot programming with Synthiam ARC Pro – where innovation and creativity meet seamlessly.

#1  

Can use this in a script instead of using the sound board to play mp3 files?... Just replace the file with the new updated mp3 as you need to...


PlayAudio(c:\temp\saythisnext.mp3)

PRO
Synthiam
#2  

Are you playing the audio through the EZB or the PC Speaker? Richard's option will work with the PC speaker, and uses the file system which is very dynamic.

Optionally, if you're capable of C# programming - can provide the details necessary to create a plugin that either populates the soundboard -or performs soundboard functions that you require.

I think a plugin that populates the soundboard is the best course of action if your needs are to use the EZB speaker. Otherwise, using the file system works for PC speaker.

Netherlands
#3  

Thanks for the super-quick replies.

I do want the EZB to play the file. The plugin seems to be the best option. I trust that I'll manage C#. I just found the resources on how to make plugins so I'll let you know if I run into trouble. I need a bit of time to get familiar with API etc.

Will report back!

#4  

If the sound file: 'saythisnext.mp3' is being updated and you'd like ARC to play the file when it has changed, more or less. The code RichardR provided will indeed play the file via script, but it won't kick it off when the file has changed.

If your external Ai software has a link with the Ivona's cloud service, does it also have a link to ARC to get data and send data? If so, you'd want to set some sort of change variable to let ARC know the mp3 file was updated then put the play mp3 code into a loop to watch for a change of the variable and if there is a change then play your mp3.

#5  

@JustinRatliff He wants to play the file through his EZB, so my code was no good anyway....

Netherlands
#6  

@JustinRatliff As @DJ mentions the solution from @Richard plays the file from the computer speaker instead of the EZB. Currently waiting for VS to download to make a plugin... will probably have it finished later this week.

In case you're curious; Ivona has a Java API. I have my core A.I. running in Java as well which communicates through tcp and telnet with ARC. The project is slowly becoming a mumbo-jumbo of applications, Ivona, Dragon Naturally Speaking, ARC, my Java agent platform and a Prolog based ontology system. I use webinterfaces between all of them.

#7  

@Bas, your setup sounds pretty neat. I wasn't clear on what your main question was until now.

@All, So you can't script playing a sound file through the EZ-B currently? I guess I did not know this.

#8  

@JustinRatliff

You can, but only if the sound file has been installed in the EZ-B v4 Soundboard object. You can't just play a file directly.

Alan

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.