Record sound: Difference between revisions
Content deleted Content added
Taking down to draft |
→Tcl: Added implementation |
||
Line 21: | Line 21: | ||
data = stream.read(chunk) |
data = stream.read(chunk) |
||
print [ord(i) for i in data]</lang> |
print [ord(i) for i in data]</lang> |
||
=={{header|Tcl}}== |
|||
{{libheader|Snack}} |
|||
<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> |
Revision as of 13:36, 30 December 2010
Record sound is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Record sound (mono 16-bit PCM) into an integer array.
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>