Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (40 sloc) 1.35 KB
(use-modules (oop goops)
(srfi srfi-18)
(ice-9 format)
(aiscm core)
(aiscm ffmpeg)
(aiscm pulse)
(aiscm util))
(define words (list "stop" "go" "left" "right" "?"))
(define rate 11025)
(define chunk 512)
(define rising 6000)
(define falling 3000)
(define output (open-ffmpeg-output "voice-commands.mp3" #:rate rate #:typecode <sint> #:channels 1 #:audio-bit-rate 80000))
(define csv (open-file "voice-commands.csv" "wl"))
(define record (make <pulse-record> #:typecode <sint> #:channels 1 #:rate rate))
(format csv "chunks,word~&")
(define choice #f)
(define status 'on)
(define n (* 5 64))
(define l #f)
(while #t
(let* [(samples (read-audio record chunk))
(loudness2 (/ (sum (* (to-type <int> samples) samples)) chunk))]
(if (and (eq? status 'off) (> loudness2 (* rising rising)))
(begin
(set! status 'on)
(set! l 0)))
(if (and (eq? status 'on) (or (not l) (< loudness2 (* falling falling))))
(begin
(if l (format csv "~a,~a~&" l choice))
(set! n (1- n))
(if (zero? n) (break))
(set! status 'off)
(set! choice (list-ref words (random (length words))))
(format #t "Say \"~a\"~&" choice)))
(if (eq? status 'on)
(begin
(write-audio samples output)
(set! l (1+ l))))))
(destroy output)