Record a monophonic 16-bit PCM sound into either memory space, a file or array.

(This task neglects to specify the sample rate, and whether to use signed samples.
The programs in this page might use signed 16-bit or unsigned 16-bit samples, at 8000 Hz, 44100 Hz, or any other sample rate.
Therefore, these programs might not record sound in the same format.)

package require sound
 
# Helper to do a responsive wait
proc delay t {after $t {set ::doneDelay ok}; vwait ::doneDelay}
 
# Make an in-memory recording object
set recording [snack::sound -encoding "Lin16" -rate 44100 -channels 1]
 
# Set it doing the recording, wait for a second, and stop
$recording record -append true
delay 1000
$recording stop
 
# Convert the internal buffer to viewable numbers, and print them out
binary scan [$recording data -byteorder littleEndian] s* words
puts [join $words ", "]
 
# Destroy the recording object
$recording destroy