voice 0.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/voice.rb +59 -0
  3. data/lib/voice/say.rb +43 -0
  4. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01a859a568488454225d6ce22f796a514a62a288
4
+ data.tar.gz: 61407e22e17df5b3741862766a52f707b68c1020
5
+ SHA512:
6
+ metadata.gz: 16cc7dac21205b113c25a6cfb673bf67017db602559d4579c78254e5080aa285932c6cd55c3d8530fe4507d73772cbac75ec97c6e1e038ba404522cb2a61f665
7
+ data.tar.gz: daff275652c439c874aed70c2b1509209fc6d2dc61b9595ae522dec8bd910f6324c3d9261c851ac33da6eedb381b567c64df4a578af4942b7954d3ec1663debd
@@ -0,0 +1,59 @@
1
+ require 'voice/say'
2
+
3
+ module Voice
4
+
5
+ PLATFORM_IS_OSX = (Object::RUBY_PLATFORM =~ /darwin/i)
6
+
7
+ DEFAULT_VOICE = 'Kathy'
8
+
9
+ NOVELTY_VOICES = ["Albert", "Bad News", "Bahh", "Bells",
10
+ "Boing", "Bubbles", "Cellos", "Deranged", "Good News",
11
+ "Hysterical", "Pipe Organ", "Trinoides", "Whisper", "Zarvox"
12
+ ]
13
+
14
+ if PLATFORM_IS_OSX
15
+ @@all = `say -v ? | cut -f1 -d' '`.split("\n")
16
+ @@novelty = @@all.select{|v| NOVELTY_VOICES.include?(v)}
17
+ @@all = @@all - @@novelty
18
+ else
19
+ @@all = nil
20
+ @@novelty = nil
21
+ end
22
+
23
+ def self.all(opts={})
24
+ return nil if @@all.nil?
25
+ opts = {} unless opts.is_a?(Hash)
26
+
27
+ if opts[:novelty] == 'only'
28
+ @@novelty
29
+ elsif opts[:novelty]
30
+ @@all + @@novelty
31
+ else
32
+ @@all
33
+ end
34
+ end
35
+
36
+ def self.default
37
+ return DEFAULT_VOICE if @@all.include?(DEFAULT_VOICE)
38
+ return @@all.first
39
+ end
40
+
41
+ def self.get_rand(opts={})
42
+ return nil if @@all.nil?
43
+ opts = {} unless opts.is_a?(Hash)
44
+
45
+ voices = self.all(opts)
46
+
47
+ voices[rand(voices.size)]
48
+ end
49
+
50
+ def self.say(text, opts={})
51
+ opts = {} unless opts.is_a?(Hash)
52
+ opts[:voice] = self.get_rand(opts) if opts[:random]
53
+ opts[:voice] ||= self.default
54
+
55
+ Say.say(text, opts)
56
+ return nil
57
+ end
58
+
59
+ end
@@ -0,0 +1,43 @@
1
+ module Say
2
+
3
+ DEFAULT_SAY = '/usr/bin/say'
4
+
5
+ DICT = {
6
+ '...' => 'ellipsis',
7
+ '&' => 'and',
8
+ '+' => 'plus',
9
+ '!' => 'exclamation point',
10
+ '?' => 'question mark',
11
+ ':' => 'colon',
12
+ '>' => 'greater than',
13
+ '<' => 'less than',
14
+ '^' => 'carrot'
15
+ }
16
+
17
+ EMOTICONS = {
18
+ '8==D' => 'dick',
19
+ '<3' => 'heart',
20
+ ':)' => 'smiley face',
21
+ '=)' => 'smiley face',
22
+ ':-)' => 'smiley face',
23
+ ';)' => 'winkey face',
24
+ ';-)' => 'winkey face',
25
+ '=D' => 'excited smiley face',
26
+ ':D' => 'excited smiley face',
27
+ '8==D~~' => 'dick with sperm shooting out'
28
+ }
29
+
30
+ def self.say(text, opts={})
31
+ return if text.empty?
32
+
33
+ for key in EMOTICONS.keys.sort{|a,b| b.length <=> a.length}
34
+ text.gsub!(key, " #{EMOTICONS[key]} ")
35
+ end
36
+
37
+ for key in DICT.keys.sort{|a,b| b.length <=> a.length}
38
+ text.gsub!(key, " #{DICT[key]} ")
39
+ end
40
+
41
+ system "#{DEFAULT_SAY} #{"-v #{opts[:voice]}" if opts[:voice]} '#{text}'"
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: voice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Davy Stevenson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Provides access to OSX say command and custom voices
14
+ email: davy.stevenson@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/voice.rb
20
+ - lib/voice/say.rb
21
+ homepage: http://github.com/davy/voice
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Gives you a voice
45
+ test_files: []