Record sound: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) Rename Perl 6 -> Raku, alphabetize, minor clean-up |
Replaced code which no longer work on modern Linux with code using "arecord" and "aplay". |
||
Line 467:
=={{header|Nim}}==
{{trans|
This code is for Linux systems and uses “arecord” and “aplay”. Previous code which used “/dev/dsp” no longer works on modern OS.
<lang nim>import osproc, strutils
var name = ""
while name.len == 0:
stdout.write "Enter output file name (without extension): "
name = stdin.readLine().strip()
name.add ".wav"
var
while rate notin 2000..19_200:
stdout.write "Enter sampling rate in Hz (2000 to 192000): "
try: rate = parseInt(stdin.readLine().strip())
except ValueError: discard
var duration = 0
while duration notin 5..30:
stdout.write "Enter duration in seconds (5 to 30): "
try: duration = parseInt(stdin.readLine().strip())
except ValueError: discard
echo "OK, start speaking now..."
# Default arguments: -c 1, -t wav. Note that only signed 16 bit format supported.
let args = ["-r", $rate, "-f", "S16_LE", "-d", $duration, name]
echo execProcess("arecord", args = args, options = {poStdErrToStdOut, poUsePath})
echo "'$1' created on disk and will now be played back..." % name
echo execProcess("aplay", args = [name], options = {poStdErrToStdOut, poUsePath})
echo "Playback completed"</lang>
=={{header|OCaml}}==
|