Using Snack on the web

General information on using Tcl/Tk on the web can be found at http://tcl.activestate.com/products/tcltk/plugin/.

Suppose you want to create a web page with an embedded real time spectrogram. A very simple program to do this using Snack could look like this
 
package require snack
option add *background grey75

sound s
pack  [ canvas .c -width 600 -height 200]
.c create spectrogram 0 0 -sound s -width 600 -height 200 -pixelspersecond 250
pack  [ frame .f -height 35] -fill x
place [ button .f.r -text Record -command {s record}] -relx .3 -anchor n
place [ button .f.s -text Stop -wi 6 -command {s stop}] -relx .5 -anchor n
place [ button .f.p -text Play -wi 6 -command {s play}] -relx .7 -anchor n

.c create spectrogram 0 0 -sound s -width 600 -height 200 -pixelspersecond 250

Save this piece of code in a file named speg.tcl and put it in the same directory as your HTML page. This page should contain an embed tag like this

<EMBED SRC=speg.tcl WIDTH=600 HEIGHT=235>

When you access your web page it will contain an embedded application looking like this (after recording something into it)

If you already have the plug-in installed you can play with the spectrogram below right now

You can also try the above script interactively in your browser window using Jeff Hobbs TkCon.
 

Examples of Snack web pages


Snack home