acappella 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c26718b7718d6472e64e75621286167b823032f
4
- data.tar.gz: e3a6ba550d871c0f72201076259f83ffc2735caa
3
+ metadata.gz: fb789efe1546c8327f8f9bf712dd7099109a9cfa
4
+ data.tar.gz: 60001dbdc4f4646ff4ce93222f7cbe388d3d138e
5
5
  SHA512:
6
- metadata.gz: 42e20dbc440f230aeb6326acc213ceaf5d8fa430ae9145baa48f5b36b8c6e62efdbadfc3d56df21ad9fad354cc487ca031ebfdf7acbf1ff1900ae9bed41656d4
7
- data.tar.gz: 73774fa65942d583a13e8d878fb5c8b3c354f55ea5ab5722c2f4558e8a411c07c55a9b7903c72f72e47855c1dbb0fdb0bfafcd326163a43ebff120f5ef93c23b
6
+ metadata.gz: 75acf468845b8b6726310c2041dec46ffa56b91fc01bfe8432401dc853546aa8b24e1ce15323a6598f67e5b8170e357770feff9fc60a09c1170d33f90c378085
7
+ data.tar.gz: 88309aacfce2c3f477b2ae75951e4fd7cda277783e3e8260e11b1e1a8737243efd67419f34077165520f7e9de79849cc856dba210bf0b2ee86abcdbd81535981
data/README.md CHANGED
@@ -10,22 +10,23 @@ $ gem install acappella
10
10
 
11
11
  ## USAGE
12
12
 
13
- 1. Please perform the following in server side terminal.
13
+ ### 1. Please perform the following in server side terminal.
14
14
 
15
15
  ```
16
16
  $ acappella-server
17
- acappella 0.0.1 starting on druby://localhost:8989
17
+ acappella 0.1.0 starting on druby://localhost:8989
18
18
  Run `acappella-server --help` for more startup options
19
19
  Ctrl-C to shutdown server
20
20
  ```
21
21
 
22
- 2. Please perform the following in client side terminal.
22
+ ### 2. Please perform the following in client side terminal.
23
23
 
24
24
  ```
25
25
  $ acappella-client
26
26
  Connect to druby://localhost:8989
27
+ Run `acappella-client --help` for more startup options
27
28
  Ctrl-D to exit
28
- > words you want to talk'
29
+ > words you want to talk
29
30
  ```
30
31
 
31
32
  Server speak characters that client was typing.
@@ -6,7 +6,8 @@ $:.unshift(lib_path)
6
6
  require 'acappella'
7
7
  require 'readline'
8
8
 
9
- options = ACappella::OptionParser.parse(ARGV) rescue exit(false)
9
+ option_parser = ACappella::OptionParser.new
10
+ options = option_parser.parse!(ARGV) rescue exit(false)
10
11
 
11
12
  client = ACappella::Client.new(options)
12
13
 
@@ -5,8 +5,19 @@ $:.unshift(lib_path)
5
5
 
6
6
  require 'acappella'
7
7
 
8
- options = ACappella::OptionParser.parse(ARGV) rescue exit(false)
8
+ option_parser = ACappella::OptionParser.new
9
+ option_parser.add_option('-v', '--voice=VAL')
9
10
 
10
- server = ACappella::Server.new(options)
11
+ options = option_parser.parse!(ARGV) rescue exit(false)
12
+
13
+ begin
14
+ server = ACappella::Server.new(options)
15
+ rescue ACappella::VoiceTypeError => e
16
+ quoted_voice_names = ACappella::VoiceType::VOICE_VARIATIONS.map {|v| "'#{v}'" }
17
+
18
+ puts "#{e.message} --voice=VAL accepts #{quoted_voice_names.join(', ')}."
19
+
20
+ exit(false)
21
+ end
11
22
 
12
23
  server.start
@@ -7,3 +7,4 @@ require 'acappella/set_list'
7
7
  require 'acappella/singer'
8
8
  require 'acappella/songwriter'
9
9
  require 'acappella/version'
10
+ require 'acappella/voice_type'
@@ -2,19 +2,33 @@ require 'optparse'
2
2
 
3
3
  module ACappella
4
4
  class OptionParser
5
- def self.parse(argv)
6
- opt = ::OptionParser.new
5
+ def initialize
6
+ @opt = ::OptionParser.new
7
7
 
8
- options = {}
8
+ @options = {}
9
9
 
10
- opt.on('-h', '--host=VAL') {|v| options[:host] = v }
11
- opt.on('-p', '--port=VAL') {|v| options[:port] = v }
10
+ @added_options = []
11
+ end
12
+
13
+ def add_option(short, long, desc = '')
14
+ @added_options << [short, long, desc]
15
+ end
16
+
17
+ def parse!(argv)
18
+ @opt.on('-h', '--host=VAL') {|v| @options[:host] = v }
19
+ @opt.on('-p', '--port=VAL') {|v| @options[:port] = v }
20
+
21
+ @added_options.each do |added_option|
22
+ short, long, desc = added_option
23
+
24
+ @opt.on(short, long, desc) {|v| @options[:voice] = v }
25
+ end
12
26
 
13
- opt.parse!(argv)
27
+ @opt.parse!(argv)
14
28
 
15
- options
29
+ @options
16
30
  rescue ::OptionParser::MissingArgument => e
17
- puts opt.help
31
+ puts @opt.help
18
32
 
19
33
  raise e
20
34
  end
@@ -6,6 +6,7 @@ module ACappella
6
6
  def initialize(options = {})
7
7
  host = options[:host] || 'localhost'
8
8
  port = options[:port] || '8989'
9
+ voice = options[:voice] || ACappella::VoiceType::DEFAULT_VOICE
9
10
 
10
11
  @uri = URI.parse("druby://#{host}:#{port}").to_s
11
12
 
@@ -13,7 +14,7 @@ module ACappella
13
14
 
14
15
  @songwriter = Songwriter.new(@set_list)
15
16
 
16
- @singer = Singer.new
17
+ @singer = Singer.new(voice)
17
18
  end
18
19
 
19
20
  def start
@@ -4,8 +4,8 @@ module ACappella
4
4
  @songs = []
5
5
  end
6
6
 
7
- def request(lyrics)
8
- @songs << lyrics
7
+ def request(song)
8
+ @songs << song
9
9
  end
10
10
 
11
11
  def next_song
@@ -1,17 +1,31 @@
1
+ require 'shellwords'
2
+
1
3
  module ACappella
2
4
  class Singer
5
+ def initialize(voice)
6
+ raise ACappella::VoiceTypeError.new("can't sing voice.") unless valid_voice?(voice)
7
+
8
+ @voice = voice
9
+ end
10
+
3
11
  def sing(lyrics)
4
12
  logging(lyrics)
5
13
 
6
- system('say', lyrics)
14
+ shellescaped_args = [@voice, lyrics].shelljoin
15
+
16
+ system("say -v #{shellescaped_args}")
7
17
  end
8
18
 
9
19
  private
10
20
 
21
+ def valid_voice?(voice)
22
+ ACappella::VoiceType::VOICE_VARIATIONS.include?(voice)
23
+ end
24
+
11
25
  def logging(lyrics)
12
- sung_at = Time.now.strftime('%Y-%m-%d %H:%M:%S')
26
+ sang_at = Time.now.strftime('%Y-%m-%d %H:%M:%S')
13
27
 
14
- puts [sung_at, lyrics].join("\t")
28
+ puts [sang_at, lyrics].join("\t")
15
29
  end
16
30
  end
17
31
  end
@@ -1,3 +1,3 @@
1
1
  module ACappella
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,15 @@
1
+ module ACappella
2
+ class VoiceTypeError < StandardError; end
3
+
4
+ class VoiceType
5
+ DEFAULT_VOICE = 'Bruce'
6
+
7
+ FEMALE_VOICES = %w(Agnes Kathy Princess Vicki Victoria)
8
+ MALE_VOICES = %w(Bruce Fred Junior Ralph)
9
+ NOVELTY_VOICES = [
10
+ 'Albert', 'Bad News', 'Bahh', 'Bells', 'Boing', 'Bubbles', 'Cellos', 'Deranged', 'Good News', 'Hysterical', 'Pipe Organ', 'Trinoids', 'Whisper', 'Zarvox'
11
+ ]
12
+
13
+ VOICE_VARIATIONS = FEMALE_VOICES + MALE_VOICES + NOVELTY_VOICES
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acappella
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi ITO
@@ -31,6 +31,7 @@ files:
31
31
  - lib/acappella/singer.rb
32
32
  - lib/acappella/songwriter.rb
33
33
  - lib/acappella/version.rb
34
+ - lib/acappella/voice_type.rb
34
35
  homepage: http://github.com/koic/acappella
35
36
  licenses:
36
37
  - MIT