Add NewRandomAudio function. Audio test cmd now writes to stdout.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 18:53:26 +0200
2 files changed,
13 insertions(+),
14 deletions(-)
M
audio.go
→
audio.go
@@ -178,7 +178,17 @@ a.body.Write(endingBeepSound)
return a } -// WriteTo writes captcha audio in WAVE format. +// NewRandomAudio generates a sequence of random numbers with the given length, +// and returns a new audio captcha with this numbers, and the sequence of +// numbers itself. +func NewRandomAudio(length int) (a *Audio, numbers []byte) { + numbers = randomNumbers(length) + a = NewAudio(numbers) + return +} + +// WriteTo writes captcha audio in WAVE format into the given io.Writer, and +// returns the number of bytes written and an error if any. func (a *Audio) WriteTo(w io.Writer) (n int64, err os.Error) { nn, err := w.Write(waveHeader) n = int64(nn)
M
cmd/audio/main.go
→
cmd/audio/main.go
@@ -2,21 +2,10 @@ package main
import ( "github.com/dchest/captcha" - "log" "os" ) func main() { - f, err := os.Create("mixed.wav") - if err != nil { - log.Fatalf("%s", err) - } - defer f.Close() - - c := captcha.NewAudio([]byte{1, 2, 3, 4, 5, 6}) - n, err := c.WriteTo(f) - if err != nil { - log.Fatalf("%s", err) - } - println("written", n) + c, _ := captcha.NewRandomAudio(captcha.StdLength) + c.WriteTo(os.Stdout) }