Sample file format converter 2
Minimal sound spectrum analyzer
Minimal two-channel real-time sound spectrum analyzer
Audio client/server applications
Audio client/server applications 2
Sending audio between two applications
#!/usr/local/bin/wish
package require snack snack::sound s
|
![]() |
convert.tcl file.au file.wav
(Assuming you have named the script convert.tcl)
#!/usr/local/bin/tclsh
package require sound
sound::sound snd
snd read [lindex $argv 0]
snd write [lindex $argv 1]
You could just as well use wish for this script. The exit command at the end prevents the opening of the main window.
#!/usr/local/bin/wish
package require snack
snack::sound snd
snd read [lindex $argv 0]
snd write [lindex $argv 1]
exit
convert2.tcl -frequency 44100 -format LIN16 file.raw file.wav
(Assuming you have named the script convert2.tcl)
#!/usr/local/bin/tclsh
package require sound
sound::sound snd
set args [llength $argv]
eval snd read [lindex $argv [expr $args - 2]] [lrange
$argv 0 [expr $args - 3]]
snd write [lindex $argv end]
(This script can be given any of the options which can be given to the sound read command.)
#!/usr/local/bin/tclsh
package require sound
sound::sound snd
set file_list [glob *.au]
foreach file $file_list {
snd read $file
snd convert -format lin16 -channels
1 -frequency 8000
snd write [file rootname $file].wav
}
If the files are in raw format you can specify their characteristics
after the snd read command using,
e. g.,
snd configure -format MULAW -frequency
8000.
If you have a file containing a list of the files you want to convert,
you would read this file first:
set f [open "filenamnes"]
set file_list [read $f]
close $f
If you modify the snd write
command the sound files to convert can reside in different directories.
snd write [lindex [file split [file
rootname $file]] end].wav
#!/usr/local/bin/wish
package require snack pack [canvas .c -height 200] snack::sound s -load ex1.wav .c create spectrogram 0 0 -sound s -height 200 |
|
To add a waveform of the same sound the line
.c create waveform 0 0 -sound s -height 100
could be added to the script
(with some minor modifications), giving:
#!/usr/local/bin/wish
package require snack pack [canvas .c -height 300] snack::sound s -load ex1.wav .c create waveform 0 0 -sound s -height 100 .c create spectrogram 0 100 -sound s -height 200 |
![]() |
package require snack
snack::sound s
set width 600
set wheight 180
set cheight 200
pack [canvas .c -width $width -height $cheight]
pack [button .p -text Play -command Play]
pack [button .l -text Open -command Open]
.c create waveform 0 0 -sound s -width $width -height
$wheight
.c create poly -1 -1 -1 -1 -1 -1 -fill red -tags
pm
proc Open {} {
s read [tk_getOpenFile]
}
proc Play {} {
s play -command StopPlayMarker
after 0 PutPlayMarker
}
proc StopPlayMarker {} {
after cancel PutPlayMarker
}
proc PutPlayMarker {} {
global width cheight
set x [expr $width / [s length
-units seconds] * [audio elapsed]]
set y [expr $cheight - 5]
.c coords pm [expr $x-5] $y $x
[expr $y-10] [expr $x+5] $y
after 50 PutPlayMarker
}
#!/usr/local/bin/tclsh
package require sound
sound::sound s -format lin16
-frequency 16000
s length 32000 -units samples
set period 16
set amp 10000
for {set i 0} {$i < [s
length]} {incr i} {
s sample
$i [expr int($amp*sin($i*6.283185/$period))]
}
s write "sine1khz.wav"
#!/usr/local/bin/wish
package require snack snack::sound s set tp 01
proc Play {filename} {
pack [ frame .f ]
for {set i 0} {$i < [llength $files]} {incr i}
{
pack [button .b -text Ready -command {
|
#!/usr/local/bin/wish
package require snack snack::sound s
if [catch {open sent.txt r} fd] {
pack [ frame .f ]
proc NextSent {} {
s write $tp.$i.wav
|
Last updated January 23, 2006