Skip to content

Commit

Permalink
Added Commander::UI#speak
Browse files Browse the repository at this point in the history
MacOS speech sythesis support via applescript
  • Loading branch information
tj committed May 12, 2009
1 parent 5538f08 commit 0eda5cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.rdoc
Expand Up @@ -20,6 +20,7 @@ features, and an elegant API.
* Highly customizable progress bar with intuative, simple usage
* Multi-word command name support such as 'drupal module install MOD', rather than 'drupal module_install MOD'
* Sexy paging for long bodies of text
* Support for MacOS text-to-speech
* Command aliasing (very powerful, as both switches and arguments can be used)
* Growl notification support for MacOS
* Use the 'commander' executable to initialize a commander driven program
Expand Down Expand Up @@ -155,6 +156,11 @@ simplify common tasks using the following methods:
end
# $stdin / $stdout reset back to original streams

# Speech synthesis
speak 'What is your favorite food? '
food = ask 'favorite food?: '
speak "wow, I like #{food} too. We have so much alike."

== Commander Goodies

=== Option Defaults
Expand Down
19 changes: 19 additions & 0 deletions lib/commander/user_interaction.rb
Expand Up @@ -55,6 +55,25 @@ def log action, *args
say '%15s %s' % [action, args.join(' ')]
end

##
# Speak +message+ using +voice+ which defaults
# to 'Alex', which is one of the better voices.
#
# === Examples
#
# speak 'What is your favorite food? '
# food = ask 'favorite food?: '
# speak "wow, I like #{food} too. We have so much alike."
#
# === Notes
#
# * MacOS only
#

def speak message, voice = :Alex
Thread.new { `osascript -e 'say #{message.inspect} using #{voice.to_s.inspect}'` }
end

##
# Normalize IO streams, allowing for redirection of
# +input+ and/or +output+, for example:
Expand Down

0 comments on commit 0eda5cd

Please sign in to comment.