Record sound: Difference between revisions
Content added Content deleted
m ({{omit from|Lotus 123 Macro Scripting}}) |
|||
Line 53: | Line 53: | ||
{{omit from|Lotus 123 Macro Scripting}} |
{{omit from|Lotus 123 Macro Scripting}} |
||
[[Category:Temporal media]] |
Revision as of 22:43, 11 July 2011
Record sound
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Record a monophonic 16-bit PCM sound into either memory space, a file or array.
PicoLisp
<lang PicoLisp>(in '(rec -q -c1 -tu16 - trim 0 2) # Record 2 seconds
(make (while (rd 2) (link @) ) ) )</lang>
Output:
-> (16767 19071 17279 ... 5503 9343 14719) # 96000 numbers
Python
<lang python>import pyaudio
chunk = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 44100
p = pyaudio.PyAudio()
stream = p.open(format = FORMAT,
channels = CHANNELS, rate = RATE, input = True, frames_per_buffer = chunk)
data = stream.read(chunk) print [ord(i) for i in data]</lang>
Tcl
<lang tcl>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</lang>