Make An ARC Skill

Example: Output Audio from EZ-B

This is an example with source code about how to play audio out of the EZ-B. The EZ-B will output audio as a stream or byte array.

This example can be run as a plugin by installing it here: https://www.ez-robot.com/EZ-Builder/Plugins/view/202

Source code as a plugin project is here: OutputAudioFromEZ-BSource.zip

*Dependency: Additional to adding EZ-Builder.exe and EZ-B.DLL, this plugin requires NAudio.DLL library to be added as a project reference. Remember to UNSELECT "Copy Files"!

This plugin provides the following examples:

  1. Load audio from MP3 or WAV file

// MP3
NAudio.Wave.Mp3FileReader mp3 = new NAudio.Wave.Mp3FileReader(openFileDialog1.FileName);

// WAV
NAudio.Wave.WaveStream wav = new NAudio.Wave.WaveFileReader(openFileDialog1.FileName);
  1. Convert audio file to uncompressed PCM data to supported EZ-B sample rate and sample size

NAudio.Wave.WaveFormatConversionStream pcm = new NAudio.Wave.WaveFormatConversionStream(new NAudio.Wave.WaveFormat(EZ_B.EZBv4Sound.AUDIO_SAMPLE_BITRATE, 8, 1), mp3);
  1. Compress PCM data with gzip to be stored in project STORAGE

                using (MemoryStream ms = new MemoryStream()) {

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

                  _cf.STORAGE[ConfigTitles.COMPRESSED_AUDIO_DATA] = ms.ToArray();
                }
  1. Play audio data from compressed project STORAGE

        using (MemoryStream ms = new MemoryStream(compressedAudioData))
        using (GZipStream gz = new GZipStream(ms, CompressionMode.Decompress))
          EZBManager.EZBs[0].SoundV4.PlayData(gz);
  1. Supports ControlCommand() for Play and Stop of audio to be used in external scripts

    public override object[] GetSupportedControlCommands() {

      List items = new List();

      items.Add(ControlCommands.StartPlayingAudio);
      items.Add(ControlCommands.StopPlayingAudio);

      return items.ToArray();
    }

    public override void SendCommand(string windowCommand, params string[] values) {

      if (windowCommand.Equals(ControlCommands.StartPlayingAudio, StringComparison.InvariantCultureIgnoreCase))
        playStoredAudio();
      else if (windowCommand.Equals(ControlCommands.StopPlayingAudio, StringComparison.InvariantCultureIgnoreCase))
        stopPlaying();
      else
        base.SendCommand(windowCommand, values);
    }
  1. Changes the status of the button when audio is playing globally from anywhere in ARC on EZ-B #0

    public FormMain() {

      InitializeComponent();

      EZBManager.EZBs[0].SoundV4.OnStartPlaying += SoundV4_OnStartPlaying;
      EZBManager.EZBs[0].SoundV4.OnStopPlaying += SoundV4_OnStopPlaying;
    }

    private void FormMain_FormClosing(object sender, FormClosingEventArgs e) {

      EZBManager.EZBs[0].SoundV4.OnStartPlaying -= SoundV4_OnStartPlaying;
      EZBManager.EZBs[0].SoundV4.OnStopPlaying -= SoundV4_OnStopPlaying;
    }

    private void SoundV4_OnStopPlaying() {

      Invokers.SetText(btnPlayAudio, "Play");
    }

    private void SoundV4_OnStartPlaying() {

      Invokers.SetText(btnPlayAudio, "Stop");
    }

Output Text to Speech You can output text to speech easily as well, using the following code example...


      using (MemoryStream s = EZBManager.EZBs[0].SpeechSynth.SayToStream("I am speaking out of the EZ-B))
        EZBManager.EZBs[0].SoundV4.PlayData(s);

ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

Author Avatar
United Kingdom
#1  

Is this out of date? There doesn't seem to be a GetConfiguration function within EZ_Builder.Config.Sub.PluginV1

Author Avatar
PRO
Synthiam
#2  

Look at the tutorial step titled "Code: Saving/Loading Configuration"

The get and set configuration methods are overrides of the form. There’s a great video on the first step of this tutorial that demonstrates the step by step of building a plugin. I recommend watching that because it helps fill in any steps that were missed.

When you’ve done it once, it makes sense and voila, you can rinse and repeat:)

Author Avatar
United Kingdom
#3  

Excellent, thanks - I will do. I really must learn not to just jump ahead in the process:)

Author Avatar
PRO
Synthiam
#4  

Hey no problem - I do it all the time, and end up frustrated because I dont know what it was that I missed. Excitement gets the best of me

Author Avatar
United Kingdom
#5  

Trying to follow the tutorials but can't find where the plugin page has gone. How do I add a new plugin to the ez-robot / Synthiam site to get the XML?

Author Avatar
United Kingdom
#6  

Never mind. Just found the "Create skill control" link:)

#7  

I am trying to follow the instructions for adding my own plugin but I cannot seem to find the place to register the plugin based on the instructions.

Any help is appreciated.

Thanks

Author Avatar
PRO
Synthiam
#8   — Edited

The new button to create a plugin skill control is less than an inch below the button you pressed to create this question. :)

User-inserted image