Debian Codegraph @

lab/cocoa-speak.ss

raw
1 #!/usr/bin/env ikarus --r6rs-script
2
3 (import (ikarus) (objc) (Cocoa helpers))
4
5 (define-class NSSpeechSynthesizer)
6
7 (define (get-voice-name)
8 (if (= 2 (length (command-line)))
9 (cadr (command-line))
10 #f))
11
12 (define (make-speaker voice)
13 (define base-string "com.apple.speech.synthesis.voice.")
14 (define (synthesizer x)
15 [$ [$ NSSpeechSynthesizer alloc]
16 initWithVoice:
17 (and x (nsstring (string-append base-string x)))])
18 (define (voice->synthesizer voice)
19 (or (synthesizer voice)
20 (begin
21 (printf "~a is not available\n" voice)
22 (synthesizer #f))
23 (error #f "cannot initialize voice")))
24 (let ([st (voice->synthesizer voice)])
25 (lambda (x)
26 [$ st startSpeakingString: (nsstring x)])))
27
28 (define speak (make-speaker (get-voice-name)))
29
30 (speak "may I help you?")
31 (let loop ()
32 (printf "> ")
33 (let ([x (get-line (current-input-port))])
34 (unless (eof-object? x)
35 (speak x)
36 (loop))))
37 (newline)
38