User Guide
Ruby Component
Sounds
FlowBotics Studio has a comprehensive signal processing engine for handling sound. Using this you can do just about anything you want
from an audio perspective.
However, sometimes all you want to do is play a sound. So to save you having to bother with the audio engine we have provided a simple
way to play a sound from within your Ruby code.
You do this using the playSound method.
Playing
This method takes a path to the sound file that you want to play. For example:
playSound “C:/Windows/Media/chimes.wav”
This will play the wave file chimes.wav once from beginning to end.
If you don't provide a path then FlowBotics Studio will look in the folder where the schematic is currently located. You can use relative paths
to this too, for example: “Sounds\explosion.wav”.
By default the method plays the sound asynchronously. This means that your program continues executing as the sound plays.
Waiting for Completion
If you want, you can override the asynchronous behaviour and have execution wait for the sound to complete. To do this you add a second
input parameter and pass the string “sync” (meaning synchronous). For example:
playSound “C:/Windows/Media/chimes.wav”,”sync”
This will play the wave file chimes.wav once from beginning to end as before but the next instruction will not execute until the sound has
finished playing.
As a result this is only suitable for very short sounds. If you try and play a sound that has a long duration it could lock up the Ruby thread and
cause errors.
Looping
A sound can be made to loop continuously. You can do this by passing “loop” as the second parameter to the playSound method. For
example:
playSound “C:/Windows/Media/chimes.wav”,”loop”
Stopping
At any time you can interrupt and stop the currently playing sound by passing nil to the playSound method. For example:
playSound nil
157 of 212