macruby で声を出してみた2011/05/22 20:55

# macrubyで が サンプルあったので
# おはようを言わせてみた
# macruby ***.rb
# 以下 ソースです
framework 'AppKit'
class AppDelegate
def applicationDidFinishLaunching(notification)
voice_type = "com.apple.speech.synthesis.voice.GoodNews"
@voice = NSSpeechSynthesizer.alloc.initWithVoice(voice_type)
end
def windowWillClose(notification)
puts "Bye!"
exit
end

def say_japan(sender)
@voice.startSpeakingString("o ha yo oh !")
puts "おはよう !"
end
end

app = NSApplication.sharedApplication
app.delegate = AppDelegate.new
window = NSWindow.alloc.initWithContentRect([200, 300, 300, 100],
styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask,
backing:NSBackingStoreBuffered,
defer:false)

window.title = 'MacRuby: The Definitive Guide'
window.level = NSModalPanelWindowLevel
window.delegate = app.delegate

button = NSButton.alloc.initWithFrame([80, 10, 120, 80])
button.bezelStyle = 4
button.title = 'おはよう!'
button.target = app.delegate
button.action = 'say_japan:'
window.contentView.addSubview(button)
window.display
window.orderFrontRegardless
app.run

コメント

コメントをどうぞ

※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。

※なお、送られたコメントはブログの管理者が確認するまで公開されません。

※投稿には管理者が設定した質問に答える必要があります。

名前:
メールアドレス:
URL:
次の質問に答えてください:
下記の文字を入力して下さい(半角スペースあります)
Hoge desu

コメント:

トラックバック