speech synthesizer demo
This commit is contained in:
parent
a2c910d990
commit
90175f528f
|
@ -0,0 +1,38 @@
|
||||||
|
#!/usr/bin/env ikarus --r6rs-script
|
||||||
|
|
||||||
|
(import (ikarus) (objc) (Cocoa helpers))
|
||||||
|
|
||||||
|
(define-class NSSpeechSynthesizer)
|
||||||
|
|
||||||
|
(define (get-voice-name)
|
||||||
|
(if (= 2 (length (command-line)))
|
||||||
|
(cadr (command-line))
|
||||||
|
#f))
|
||||||
|
|
||||||
|
(define (make-speaker voice)
|
||||||
|
(define base-string "com.apple.speech.synthesis.voice.")
|
||||||
|
(define (synthesizer x)
|
||||||
|
[$ [$ NSSpeechSynthesizer alloc]
|
||||||
|
initWithVoice:
|
||||||
|
(and x (nsstring (string-append base-string x)))])
|
||||||
|
(define (voice->synthesizer voice)
|
||||||
|
(or (synthesizer voice)
|
||||||
|
(begin
|
||||||
|
(printf "~a is not available\n" voice)
|
||||||
|
(synthesizer #f))
|
||||||
|
(error #f "cannot initialize voice")))
|
||||||
|
(let ([st (voice->synthesizer voice)])
|
||||||
|
(lambda (x)
|
||||||
|
[$ st startSpeakingString: (nsstring x)])))
|
||||||
|
|
||||||
|
(define speak (make-speaker (get-voice-name)))
|
||||||
|
|
||||||
|
(speak "may I help you?")
|
||||||
|
(let loop ()
|
||||||
|
(printf "> ")
|
||||||
|
(let ([x (get-line (current-input-port))])
|
||||||
|
(unless (eof-object? x)
|
||||||
|
(speak x)
|
||||||
|
(loop))))
|
||||||
|
(newline)
|
||||||
|
|
|
@ -2,11 +2,6 @@
|
||||||
|
|
||||||
(import (ikarus) (objc) (Cocoa) (Cocoa helpers))
|
(import (ikarus) (objc) (Cocoa) (Cocoa helpers))
|
||||||
|
|
||||||
(define (nsstring x)
|
|
||||||
[$ [$ NSString alloc]
|
|
||||||
initWithCharactersNoCopy: x
|
|
||||||
length: (string-length x)
|
|
||||||
freeWhenDone: #t])
|
|
||||||
|
|
||||||
(define pool [$ [$ NSAutoreleasePool alloc] init])
|
(define pool [$ [$ NSAutoreleasePool alloc] init])
|
||||||
|
|
||||||
|
@ -67,6 +62,7 @@
|
||||||
|
|
||||||
[$ win setTitle: (nsstring "Hello Ikarus")]
|
[$ win setTitle: (nsstring "Hello Ikarus")]
|
||||||
[$ win makeKeyAndOrderFront: win]
|
[$ win makeKeyAndOrderFront: win]
|
||||||
|
;[$ win setAlphaValue: 0.5] ; cute
|
||||||
|
|
||||||
[$ NSApp run]
|
[$ NSApp run]
|
||||||
[$ pool release]
|
[$ pool release]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
(library (Cocoa helpers)
|
(library (Cocoa helpers)
|
||||||
(export make-app)
|
(export make-app nsstring)
|
||||||
(import (ikarus) (ikarus system $foreign))
|
(import (ikarus) (Cocoa) (objc) (ikarus system $foreign))
|
||||||
|
|
||||||
(define (make-app)
|
(define (make-app)
|
||||||
(define kProcessTransformToForegroundApplication 1)
|
(define kProcessTransformToForegroundApplication 1)
|
||||||
|
@ -19,6 +19,14 @@
|
||||||
(transform-process-type p kProcessTransformToForegroundApplication)
|
(transform-process-type p kProcessTransformToForegroundApplication)
|
||||||
(set-front-process p)
|
(set-front-process p)
|
||||||
(free p)))
|
(free p)))
|
||||||
|
|
||||||
|
|
||||||
|
(define (nsstring x)
|
||||||
|
[$ [$ NSString alloc]
|
||||||
|
initWithCharactersNoCopy: x
|
||||||
|
length: (string-length x)
|
||||||
|
freeWhenDone: #t])
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
14
lib/objc.ss
14
lib/objc.ss
|
@ -6,6 +6,11 @@
|
||||||
define-object
|
define-object
|
||||||
string->char*
|
string->char*
|
||||||
get-selector
|
get-selector
|
||||||
|
get-class-list
|
||||||
|
get-class
|
||||||
|
class-methods
|
||||||
|
class-name
|
||||||
|
method-name
|
||||||
$)
|
$)
|
||||||
(import
|
(import
|
||||||
(ikarus)
|
(ikarus)
|
||||||
|
@ -124,10 +129,7 @@
|
||||||
|
|
||||||
(define (method-name x)
|
(define (method-name x)
|
||||||
(check 'method-name method? x)
|
(check 'method-name method? x)
|
||||||
(string-append
|
(selector-name (method-selector x)))
|
||||||
(selector-name (method-selector x))
|
|
||||||
" "
|
|
||||||
(method-types x)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -377,7 +379,8 @@
|
||||||
|
|
||||||
(define (convert-incoming t x)
|
(define (convert-incoming t x)
|
||||||
(case t
|
(case t
|
||||||
[(object) (make-object x)]
|
[(object)
|
||||||
|
(if (nil? x) #f (make-object x))]
|
||||||
[(char) x]
|
[(char) x]
|
||||||
[(void) (void)]
|
[(void) (void)]
|
||||||
[else (error 'convert-incoming "invalid type" t)]))
|
[else (error 'convert-incoming "invalid type" t)]))
|
||||||
|
@ -412,6 +415,7 @@
|
||||||
[(lazy-object? x)
|
[(lazy-object? x)
|
||||||
(pointer-ref (lazy-object-ptr x) 0)]
|
(pointer-ref (lazy-object-ptr x) 0)]
|
||||||
[(class? x) (class-ptr x)]
|
[(class? x) (class-ptr x)]
|
||||||
|
[(not x) (integer->pointer 0)]
|
||||||
[else (error 'convert-output "cannot convert to object" x)])]
|
[else (error 'convert-output "cannot convert to object" x)])]
|
||||||
[(float)
|
[(float)
|
||||||
(cond
|
(cond
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1613
|
1616
|
||||||
|
|
Loading…
Reference in New Issue