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: http://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:
- 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);
- 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);
- 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();
}
- 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);
- 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);
}
- 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);
The error cannot read the COM file, I downloaded it and when I follow the instructions, I get an error, while other files read normally. .
sorry for me but i tried many different ways but still show the error,I couldn't find EZ_B.dll file even though I downloaded it
None of the required references are in your list. Please follow the tutorial. It explains exactly how to click the browse button and navigate to the folder and select the files.
Sorry, but the reason I can't reference is because there is no file in the EZ_B folder and there is an error : this folder is empty , I am trying to solve it. I would like to thank DJ sure for answering my superfluous questions and I'm sorry for bothering you
I need to playback 5 Serial Bus servos in sequence.
What protocol is it? A "serial bus" is a generic term for anything using a UART that's chained together sharing the same RX line. Also, why did you add a photo with the question text added in your response?
Are you planning on making a skill control to do this? You wrote the question in the skill control thread in a comment - I'd like to make sure your question is in the right place to help you out.
To begin, I would recommend starting with servo Script control so you can make the serial bus protocol work - then consider making a skill control only if you're planning on distributing the effort to others: https://synthiam.com/Products/Controls/Scripting/Servo-Script-19068
He seems rather demanding as well. I guess he needs the benefit of the doubt as English may not be his native language....
I have installed all the software dependencies and still ARC does not detect that I have Visual Studio installed. OS is Windows 10, .NET 4.8 or newer, Visual Studio Community 2019.