all repos — captcha @ e40250a1247fc6f98cb9d209ffe875af18f7d68c

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Add NewRandomAudio function.

Audio test cmd now writes to stdout.
Dmitry Chestnykh dmitry@codingrobots.com
Sat, 23 Apr 2011 18:53:26 +0200
commit

e40250a1247fc6f98cb9d209ffe875af18f7d68c

parent

797447596cf268e3bf3a1f4459c3977ba6415605

2 files changed, 13 insertions(+), 14 deletions(-)

jump to
M audio.goaudio.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.gocmd/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) }