user
An audio frequency generator produces a continual audible monotone at a set frequency and level of volume.
There are controls to adjust the frequency and the volume up and down as desired.
Some also have a selector to switch the waveform type between sine wave, square wave and triangular sawtooth.

The task is to emulate an audio frequency generator.
It is permissible to use an inbuilt computer speaker
if the system does not have the facility to utilize dedicated sound hardware.

The solution should include:

* A demonstration of how to check for availability of sound hardware on the system (on systems where this is possible)
* A demonstration of how to produce a continual audible monotone (on sound hardware this would typically be a sine wave)
* A method of adjusting the frequency and volume of the monotone. (one way would be to use left and right arrow keys to increase or decrease frequency, and up and down keys to increase or decrease the volume)
* A method to silence or reset the sound hardware on exit.

Optionally the solution can also include:

* A demonstration of how to fall back to internal speaker, if sound hardware is not available
* A facility to switch between sine wave, square wave and triangular sawtooth

Languages that provide no facilities for utilizing sound hardware of any kind should be omitted.
assistant
**Translation of**: Go

```
# 20240130 Raku programming solution

my ($kindS, $kind, $freq, $vol, $dur) = 'sine', |(0 xx *);

while $freq < 40 || $freq > 10000 {
   print "Enter frequency in Hz (40 to 10000) : ";
   $freq = prompt().Int;
}

while $vol < 1 || $vol > 50 {
   print "Enter volume in dB (1 to 50) : ";
   $vol = prompt().Int;
}

while $dur < 2 || $dur > 10 {
   print "Enter duration in seconds (2 to 10) : ";
   $dur = prompt().Int;
}

while $kind < 1 || $kind > 3 {
   print 'Enter kind (1 = Sine, 2 = Square, 3 = Sawtooth) : ';
   given $kind = prompt().Int {
      when $kind == 2 { $kindS = 'square'   }
      when $kind == 3 { $kindS = 'sawtooth' }
   }
}

my @args = "-n", "synth", $dur, $kindS, $freq, "vol", $vol, "dB";
run 'play', @args, :out('/dev/null'), :err('/dev/null');

```