Asked
Resolved Resolved by Synthiam Support!

Simultaneously Playing Sound Files In ARC

I have a question regarding the ability to play two sound files simultaneously using ARC's PC Soundboard feature. Unfortunately, I can't test this myself at the moment, as I am in the process of rebuilding my robot. However, having an answer would greatly assist in my planning.

Here’s an overview of my current setup:

  • My robot includes a Single Board Computer (SBC) running Windows 11, on which ARC is installed.
  • The SBC is connected to multiple EZ-B controllers that manage the lights and motors.
  • The sound files for my robot are played through the computer's audio output jack, which is linked to ARC's PC Soundboard.
  • The audio output from the computer is connected to a small amplifier with speakers to play the files.

My goal is as follows:

  • I want to play two sound files from ARC at the same time.
  • I have experience with triggering voice files using JavaScript in ARC's PC Soundboard.
  • I aim to play a continuous background sound file independently of the intermittently script-triggered voice file.
  • I need to manage the background sound file's volume using JavaScript scripts, as well as toggle it on and off.
  • There are a couple of buttons on the robot that are monitored by the ADC and connected to an EZ-B, and I plan to use these to control the background sound file.
  • It is important that all sound is output through the same audio jack, which is connected to a sound amp and speakers.
  • For reference, the voice files are recorded on the right stereo channel, and the background sound file is on the left stereo channel.

Can ARC and Windows facilitate this setup and functionality using JavaScript scripts? Any advice or guidance would be greatly appreciated.


Related Hardware EZ-B v4
Related Control Soundboard v2 (PC)

ARC Pro

Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

PRO
Canada
#1  

Below is some background and guidance on your setup and requirements:


Simultaneous Audio Playback in ARC

By default, ARC’s PC Soundboard is designed to play one file at a time through the computer’s default audio output. Although Windows supports playing and mixing multiple audio streams at the system level, the Soundboard skill (and the builtin ARC audio functions like Audio.playAudioFile and Audio.say) are not setup to give you independent control of two separate streams on different stereo channels with separate volume controls.


Your Goal

You want to have:
A continuous background sound file (on the left stereo channel), which you can start/stop and adjust the volume
An on-demand voice file (on the right stereo channel) triggered via JavaScript

Because both sounds would be routed to the same audio output jack (and thus through the same amplifier/speakers), achieving independent channel control (and separate volume control) isn’t a feature that ARC’s PC Soundboard currently offers out-of-the-box.


What Are Your Options?

  1. Using ARC’s Built-in Audio APIs
    You can use JavaScript to trigger Audio.playAudioFile(filename) or Audio.say(txt) to play sounds. However, if you try to play a second file while one is already playing, one of the audio streams may stop or the sounds may mix in an uncontrolled fashion. In other words, ARC isn’t currently configured to run two independent audio file streams with separate volume controls via the built-in PC Soundboard.

  2. Custom robot skill or External Audio Mixer
    To get the functionality you’re aiming for (two simultaneous audio streams on separate stereo channels with independent control), you may need to develop a custom robot skill. For example, you could create a JavaScript (or Python) skill that utilizes an external audio library on Windows capable of playing multiple streams concurrently. This would allow you to:

    • Assign one audio stream to the left channel (background)
    • Assign the other stream to the right channel (voice)
    • Adjust the volume of the streams independently in your scripts

    You can get started learning about creating custom robot skills here:
    Create a robot skill Overview

  3. Audio File Preparation
    Another approach (if a full custom skill is more than you need) is to pre-mix your sound files into one stereo file. For example, edit your audio files with Audacity (or a similar tool) so that the background is sent exclusively to the left channel and the voice to the right, then trigger additional controls (or even swaps) via ARC. However, note that this approach limits the independent volume control and on/off toggling of the background sound in real time.


Next Steps

  • Evaluate the Requirements:
    Decide if the added complexity of developing a custom skill (or using an external audio library) is worth the flexibility you’re seeking.

  • Explore a Custom Skill:
    If you choose to develop a custom solution, start by reviewing the ARC documentation and look into JavaScript audio libraries that work well on Windows. You might then call these libraries from within ARC’s JavaScript environment.

  • Ask Follow-Up Questions:
    Feel free to share more details about which parts are most critical for your project. For example:
    Is independent volume control a high priority, or would simultaneous playback (even if mixed) be acceptable?
    Would you be open to using a custom audio mixer application outside of ARC that you control via scripts?

For more information on using the PC Soundboard in ARC, visit:
Soundboard (PC) Skill on Synthiam

And don’t forget to check out ARC’s downloads and resources if you need additional tools:
ARC Downloads and Info


Example JavaScript Snippet (Conceptual)

Here’s a conceptual example using ARC’s JavaScript API to trigger a sound file. (Remember that this uses the built-in Audio.playAudioFile - so this will work for one stream at a time unless supplemented with a custom solution.)

print("Playing background sound file...");
Audio.playAudioFile("C:\\Sounds\\background.wav");

// Later, trigger the voice file:
print("Playing voice file...");
Audio.playAudioFile("C:\\Sounds\\voice.wav");

In a custom setup, you’d need to interface with an audio API that handles multiple streams concurrently.


I hope this helps clarify what’s possible with the current capabilities of ARC and points you in the right direction for implementing your desired audio functionality. Would you like to explore more details on developing a custom robot skill for advanced audio control, or do you have any other questions?


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#2  

OK, thanks for helping me to think this through.

What if I placed the background sound file in an EZB soundboard and ran this file through the EZB speaker? Could I get separate control from the PC soundboard voice files and turn the background sounds on and off and also control it's volume that way? I know the EZB soundboard has a volume control built into it.

PRO
Canada
#3  

Below is an explanation and some guidance based on your updated scenario.


Using Separate Soundboards

  • EZB Soundboard for Background Audio:
    If you place your continuously playing background sound file in the EZB Soundboard, you benefit from having its builtin volume control and on/off capability. When triggered, the EZB soundboard will output the background sound via the EZB speaker port.

  • PC Soundboard for Voice Audio:
    Your interrupt-driven voice files played via the PC Soundboard will continue using the PC’s audio output. These two soundboards run from separate sources within ARC.


Considerations for Your Setup

  1. Independent Volume Control:

    • The EZB Soundboard allows you to adjust the volume of the background file independently (through its own volume slider or via scripts that control the EZB soundboard’s volume).
    • Meanwhile, the PC Soundboard volume (or your script commands) will control the voice files. This gives you the separation you desire.
  2. Simultaneous Playback:

    • ARC is capable of running multiple skills at the same time. Using two different soundboards (one on the EZB and one on the PC) means you'll be triggering audio on two different output channels.
    • However, if your design requires the two audio signals to be mixed or heard through the same amplifier/speakers, you’ll need to combine them externally. For example, you might route both the EZB's audio output and the PC's audio output into a hardware mixer before the amplifier.
  3. Stereo Channel Considerations:

    • In your original plan, you were planning to record the voice files on the right channel and the background on the left. With the updated approach, you’re essentially separating them into two physical outputs (EZB versus PC).
    • If you ultimately want them merged into a single stereo signal (with independent control), you must implement a physical or software mixing solution to combine the outputs. Often, a small external audio mixer can take two inputs and mix them as needed.

Implementing Control via JavaScript Scripts

  • Triggering EZB Soundboard:
    You can use ARC’s built-in ControlCommand() or JavaScript calls to start or stop the EZB background sound. For instance, you might use:

    // Example to start playing the background sound on the EZB Soundboard:
    controlCommand("Soundboard EZB", "Track_0");
    

    And then later, to stop it:

    controlCommand("Soundboard EZB", "Stop");
    
  • Adjusting Volume:
    If you need to adjust the background sound’s volume via scripts, the EZB Soundboard typically provides volume controls. Check the skill’s properties for any available methods or script commands to adjust its volume. You might also inspect the volume setting property in the skill control.

  • Triggering PC Soundboard Voice File:
    Likewise, you would trigger the voice file on the PC Soundboard using a similar script command:

    // Example to play a voice file on the PC Soundboard:
    controlCommand("Soundboard PC", "Track_1");
    

Summary

Yes, by placing the background sound file in an EZB Soundboard, you can achieve separate control over that sound using its built-in volume and on/off functionality. Meanwhile, your PC Soundboard can handle the intermittently triggered voice files. Just keep in mind:

  • The two soundboards are outputting from two different physical sources.
  • If you require that all sound is ultimately heard through the same amplifier and speakers, you will need to combine the outputs (typically using an external mixer or a similar solution).

I hope this clarifies how you can separate control over the background and voice audio. Do you need further details on any of these steps or more help with JavaScript scripting in ARC? Feel free to ask!


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
PRO
Synthiam
#4   — Edited
  1. EZB can only stream one audio at a time

  2. Using the Audio.playAudioFile() command is good but uses the pc speaker

  3. In order to play two or more audio files from sound boards, there must be multiple sound boards. A soundboard can only play one file. This is PC audio only as mentioned in #1 the EZB can only stream one audio at a time

PRO
Canada
#5  

Below is some additional clarification based on DJ_Sures's points:

  • EZB Audio Streaming Limitation:
    The EZB firmware supports streaming only one audio file at a time. This means that if you’re using the EZB Soundboard, it can only output one audio stream at any given moment.

  • PC Audio Streaming via Audio.playAudioFile():
    The command Audio.playAudioFile() plays audio using the computer’s speaker. While this works well, it is limited to one audio stream per instance of that command. If you want multiple audio files playing concurrently from the PC side, you would need to work with separate instances (or separate sound boards) so that each one handles its own audio stream.

  • Soundboard Limitations:
    As noted, each sound board-whether it's the PC Soundboard or an EZB Soundboard-is designed to play one file at a time. If simultaneous playback is required, you must have multiple sound boards. For example, if you want one sound board handling a continuous background audio and another to handle intermittent voice files, you would need to route those through separate sound boards. However, keep in mind that:

    • The EZB Soundboard can only stream one audio file because of the hardware limitation.
    • The PC Soundboard is also limited to a single audio stream per instance.
  • Overall Implications for Your Setup:
    This means that if you need simultaneous playback of two different audio files (for instance, background audio and triggerable voice), you will have to spread them across different sound board instances and potentially mix the outputs externally. For example:

    • You could use the EZB Soundboard for the background audio (leveraging its built-in volume control), and the PC Soundboard for the voice files.
    • Once the outputs are generated, if the goal is to have them both output through the same amplifier/speakers, you would need to use a hardware mixer or a similar external solution to combine the audio channels.

I hope this further clarifies the limitations and helps you plan your audio strategy more effectively. Do you have any additional questions or need further guidance on configuring or setting up these sound boards in your project?


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#6  

Thanks for the guidance, I think I have this all figured out.

I was able to get my robot's computer that runs ARC and it's sound system up and running enough to test all this out. It's better than I expected.

So, I can do all this through the robot's SBC computers sound output and using different ARC PC soundboards. I won't have to use any extra external mixing devices other than the sound amp that has been handling my robots voice files with two speakers attached to it. One for the right channel and one for the left.

Since I have all my voice files already recorded on the left stereo channel and the background noise file recorded on the right channel, each naturally comes out of a different speaker. So to be clear, the voice files when triggered will come out of the right speaker and the robot's mechanical noise file will come out of the left speaker.

With your help I was able to understand that I needed to be using different ARC PC soundboards to get the effect I wanted. One (or more) soundboards for all the voice files and one dedicated, loan ARC PC Soundboard for the background mechanical sound file. This way the background sound file will continue to loop and play while the voice files are triggered to play when called. The background noise files plays nicely, well, in the background when the voice files are played. Furthermore, I can use scripts in ARC to turn the background sound file on and off  when I get tired of hearing it or it needs to stop for some reason. I can even use ARC's Bing Voice Recognition to turn it on and off. The only thing I lack is volume control on the background sound speaker. It's volume will go up and down with the voice volume when the amp is adjusted. However if I use Audacity I think I can lower the background sound file's amplified level to a acceptable level so It sounds natural and in the background. Once I get the voice volume set I hardly have to adjust that anyway.

I am still looking into a way to adjust the volume of the speaker (Between the amp and speaker) that handles this background sound. Something small and compact that can fit into my robot. I don't know if there is such a thing. Anyone know of a mini line leveler that can do this?

I'm really happy in the direction I'm heading with this. My prior setup to play the background sounds was complicated, took up a lot of room and was clunkily. I had a dedicated soundcard that looped the file that was loaded on board. It was attached to its own sound amp and had its own speaker. I did have total volume and on & off control but only by hand at the amp.

I hope to make a video of all this soon. Stay tuned.

One more question concerning the background sound file. It's an MP3 file and only about 30 seconds long. I had it loaded on the old sound card its self and would automatically loop it for indefinite play. Is there a Javascript script I can use in ARC that will start this file and then replay it when it reached the end until either I or another script calls for it to halt? It needs to sound uninterrupted at the end of the file when it loops around again. Right now there is no silent space at either the start or end of the sound file.

Thanks!

PRO
Canada
#7  

Below are two possible approaches to automatically loop your background MP3 file in ARC so that, once started, it repeats seamlessly until another script stops it.

Method 1: Using the Soundboard’s "Sound Complete Script" Property

Every soundboard skill in ARC has a "Sound Complete Script" field. When the audio file finishes playing, this script is executed, which lets you easily trigger the file to play again.

For example, if you name your dedicated PC Soundboard for your background file "Soundboard PC Background" and the track is "Track_Background", do the following:

  1. Open the background sound file’s soundboard skill properties.
  2. In the "Sound Complete Script" field, add a command that re-triggers the file. For example:

controlCommand(Soundboard PC Background, Track_Background)

This command tells ARC, "When the file finishes playing, play it again."
If you need a way in your scripts to stop the loop, simply call the Stop command:

controlCommand(Soundboard PC Background, Stop)

This method leverages the built-in sound complete callback, ensuring the file replays immediately after finishing.

Method 2: Using a JavaScript Function with a Global Flag

If you’d prefer to control playback entirely in JavaScript, you can set a global flag that determines whether the loop should continue. In your background audio soundboard skill, you could write a JavaScript function such as:

// Set a global variable to indicate background sound is active
setVar("$BackgroundLoopActive", "true");

// Function that plays the background file and loops if the flag remains true
function playBackgroundLoop() {
  // Check if the loop is still active
  if (getVar("$BackgroundLoopActive", "false") == "true") {
    // Play the background file using the dedicated PC soundboard (via ControlCommand)
    controlCommand(Soundboard PC Background, Track_Background);
    
    // Wait for the duration of the file (e.g., 30000 ms for a 30-second file)
    // You might need to adjust this value to match your audio duration.
    sleep(30000);
    
    // After the wait, call the function again to restart the file
    playBackgroundLoop();
  }
}

// To start the looping background sound, run:
playBackgroundLoop();

// To stop looping from another script, set the variable to false:
setVar("$BackgroundLoopActive", "false");

// And also stop the audio immediately if needed:
controlCommand(Soundboard PC Background, Stop);

Notes for Method 2: Be aware that using sleep with a fixed duration works if you’re sure the file length is constant (or if your file always loops seamlessly).
Using the sound complete callback (Method 1) is more reliable since it is invoked precisely when the audio file completes.

Summary

By using separate soundboards (one for background audio and one for voice files), you can achieve simultaneous control over audio streams. Your background MP3 will loop indefinitely until you call a Stop command. Use either the soundboard’s "Sound Complete Script" property for a built-in loop or a custom JavaScript method with a looping function.

This setup lets you leave the background sound playing via its dedicated PC soundboard (which handles its own volume control), while your voice files can be triggered as needed from their own soundboard. You mentioned you are working on controlling the amplifier’s volume separately for the background speaker; adjusting the file in Audacity to a lower level is a smart idea if hardware volume control on that speaker isn’t available.

Does this solution match your needs, or would you like further details on any part of the process?


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#8  

OK, thanks! That's exactly what I needed to know. I'll try method 1 today. I didn't realize that ARC's PC soundboards had the ability to run a script when the sound completes. This sound prefect. I hope there is no pause in the loop while the command is sent to run the sound file again. We'll see.

Also, after thinking over night about controlling the volume on the speaker playing the right channel (the background sound file) I think I'm going to try a different way. I have a small 12 volt 15w sound amp that's only a few inches side to side an 1/2 inch high. I'm going to install this above the main 100w amp I was talking about above. I'll then split the sound output from the SBC between the two amps. I'll then run the right channel RCA plug, handling the background sound file, to the small 15w amp from the SBC. This adds a little more complexity but in the end I think this will give me the results I'm wanting.

I asked Google AI if this can be done safety and got tis answer: Question: Can I attach the right channel to one sound amp and the left channel to a seconded sound amp out of an SBC computer AI Overview: Yes, you can connect the left and right audio channels from a Single Board Computer (SBC) to two separate sound amplifiers, with each amp handling a single channel. This setup requires you to connect the SBC's left audio output to the first amp's input and the SBC's right audio output to the second amp's input. You will then connect the output of the first amplifier to the left speaker and the output of the second amplifier to the right speaker, which is the standard way to create a stereo system. Here's how to do it:

  1. Check your SBC's audio output: Your SBC will have a way to output stereo audio, often through a 3.5mm jack or dedicated pins.
  2. Use appropriate cables: You will need an audio cable to split the stereo output into two separate mono signals. A Y-adapter or a cable with separate left and right RCA connectors (or other suitable connectors for your amps) will work.
  3. Connect the cables to the amps: Connect the left audio signal from your SBC to the audio input of your first amplifier.
  4. Connect the other channel: Connect the right audio signal from your SBC to the audio input of your second amplifier.
  5. Connect the speakers: Connect the left speaker to the output of the first amplifier and the right speaker to the output of the second amplifier. Important Considerations: Mono vs. Stereo: You are aiming to create a stereo system where the left and right channels are processed by different amplifiers and play through separate speakers.

@Athena , Do you agree this method is a safe way to split my signal from my SBC computer and get the results I want as described above? Are there any other considerations I should be aware of? The only other thing I want to add is that each sound amp will be powered from a different ac to dc power converter plugged into 120v AC house current. One converter is 12v powering th e15w amp and the other is 40v powering the 100w amp. Is this a problem?

Also, If there is anybody out there knowledgeable and skilled with sound systems and can advise on this method I would appreacheate it. Thanks!