Skip to content

Instantly share code, notes, and snippets.

@blmarket
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blmarket/1619ed00cb11306c51f0 to your computer and use it in GitHub Desktop.
Save blmarket/1619ed00cb11306c51f0 to your computer and use it in GitHub Desktop.
말하는 서버.

SpeakServer

말하는 서버. 여러개를 동시에 넣어도 큐에 두고 처리함.

Requirement

OS X proper voice pack.(시스템 환경설정에서 설치 가능)

Usage

$ npm install express NodObjC
$ coffee main.coffee
...

run curl http://localhost:8000/speak/Hello%20World to let server speak 'Hello World'.

TODO

Implement other component that uses this.

http = require 'http'
express = require 'express'
$ = require 'NodObjC'
app = express()
$.framework 'Foundation'
$.framework 'AppKit'
pool = $.NSAutoreleasePool('alloc')('init')
sp = null
do init_speech = ->
sp = $.NSSpeechSynthesizer('alloc')('init')
sp 'setUsesFeedbackWindow', true
sp 'setVoice', $('com.apple.speech.synthesis.voice.yuna.premium')
do ->
SynthDelegate = $.NSObject.extend('NSSpeechSynthesizerDelegate')
SynthDelegate.addMethod 'didFinishSpeaking:', 'v@:@', (self, _cmd, notif) ->
console.log _cmd
console.log notif
return
SynthDelegate.register()
delegate = SynthDelegate('alloc')('init')
sp 'setDelegate', delegate
return
sp 'startSpeakingString', $('Hello World')
return
speak_queue = []
# even though Speech API provides delegate that handles end of speech,
# I failed to integrate that feature into my program. so i loop-poll
# whether code is speaking or not.
setInterval(
->
if sp('isSpeaking') == 1 or speak_queue.length == 0
return
sp 'startSpeakingString', $(speak_queue.shift())
50
)
init_application = ->
application = $.NSApplication('sharedApplication')
AppDelegate = $.NSObject.extend('AppDelegate')
AppDelegate.addMethod('applicationDidFinishLaunching:', 'v@:@', (self, _cmd, notif) ->
console.log('got applicationDidFinishLauching')
console.log(notif)
init_speech()
return
)
AppDelegate.register()
dele = AppDelegate('alloc')('init')
application 'setDelegate', dele
application 'activateIgnoringOtherApps', true
application 'run'
return
app.get '/speak/:str', (req, res) ->
str = req.param 'str'
speak_queue.push str
# sp 'startSpeakingString', $(str)
res.send(204)
return
http.createServer(app).listen 8000, ->
console.log 'Listening'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment