speaker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Speaker
2
2
 
3
- Flexible text to speech using Google Translator
3
+ Flexible text to speech using Google Translator.
4
+
5
+ One nice touch of Speaker is that you can transform *texts of any size* to audio.
6
+ Google Translator API limits texts to 100 characters. Speaker deals with that for you.
7
+
8
+ But, of course, good sense is always appreciated. The longer the text is, the longer will take to transform it to audio.
9
+
10
+ All said, enjoyt it!
4
11
 
5
12
  ## Installation
6
13
 
@@ -18,7 +25,81 @@ Or install it yourself as:
18
25
 
19
26
  ## Usage
20
27
 
21
- TODO: Write usage instructions here
28
+ All you need to start is to create a new Speaker object passing the text you want to transform in audio:
29
+
30
+ ```ruby
31
+ speaker = Speaker.new(text: "My name is Bond. James Bond")
32
+ ```
33
+
34
+ Now you can just do "text to speech":
35
+
36
+ ```ruby
37
+ speaker.tts # It will say "My name is Bond. James Bond"
38
+ ```
39
+
40
+ If you want to listen it again:
41
+
42
+ ```ruby
43
+ speaker.play # Do not create the audio again. Instead, just play it.
44
+ ```
45
+
46
+ If you want, you can create the audio and play it in two steps. (This is exactly what the tts method does):
47
+
48
+ ```ruby
49
+ speaker.to_audio # Creates the audio
50
+ speaker.play # Play it
51
+ ```
52
+
53
+ Whenever a new Speaker object is created, there is no more audio file to play until you want it. So, if you create a new Speaker object and try to play it, there will be no audio file to play and Speaker will let you know that:
54
+
55
+ ```ruby
56
+ speaker = Speaker.new
57
+ speaker.play # It will return the string: "There is no audio file yet"
58
+ ```
59
+
60
+ You can check if there is an audio file by typing:
61
+
62
+ ```ruby
63
+ speaker.has_audio? # It returns true or false
64
+ ```
65
+
66
+ You can create and play you text in one line by doing:
67
+
68
+ ```ruby
69
+ Speaker.new(text: "My name is Bond. James Bond").tts
70
+ ```
71
+
72
+ By default, the audio file will be created inside the root path where the gem is running. But, of course, you can change it:
73
+
74
+ ```ruby
75
+ Speaker.configure do |config|
76
+ config.audio_file_path = '/new/path' # i.e.: /myapp/media
77
+ end
78
+ ```
79
+
80
+ To check what is the current audio file path:
81
+
82
+ ```ruby
83
+ Speaker.configuration.audio_file_path
84
+ ```
85
+
86
+ If you want to create tts in anothers languages:
87
+
88
+ ```ruby
89
+ speaker = Speaker.new(language: 'pt', text: 'Olá meu amigo')
90
+ speaker.tts # It will say 'Olá meu amigo', which is 'Hello my friend' in portuguese.
91
+ ```
92
+
93
+ If you want to return the text and the language:
94
+
95
+ ```ruby
96
+ speaker.text # It will return 'Olá meu amigo'
97
+ speaker.language # I will return 'pt'
98
+ ```
99
+
100
+ English is the default language.
101
+
102
+ If you create a new Speaker object without passing any information, Speaker will create an object with the text 'Nothing to say'.
22
103
 
23
104
  ## Contributing
24
105
 
data/lib/speaker.rb CHANGED
@@ -13,7 +13,7 @@ module Speaker
13
13
  yield(configuration)
14
14
  end
15
15
 
16
- def self.new(params)
16
+ def self.new(params={})
17
17
  Base.new(params)
18
18
  end
19
19
 
data/lib/speaker/base.rb CHANGED
@@ -39,7 +39,7 @@ module Speaker
39
39
 
40
40
  def play
41
41
  if has_audio?
42
- `afplay #{audio_file}`
42
+ `#{player} #{audio_file}`
43
43
  @text
44
44
  else
45
45
  "There is no audio file yet"
@@ -123,6 +123,14 @@ module Speaker
123
123
  File.delete(audio_file) if has_audio?
124
124
  end
125
125
 
126
+ def player
127
+ if RUBY_PLATFORM.include?("darwin")
128
+ 'afplay'
129
+ else
130
+ 'mpg123'
131
+ end
132
+ end
133
+
126
134
  end
127
135
 
128
136
  end
@@ -1,3 +1,3 @@
1
1
  module Speaker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-06 00:00:00.000000000 Z
12
+ date: 2012-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 2.5.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 2.5.1
30
30
  description: Flexible text to speech using Google Translator
31
31
  email:
32
32
  - david@webhall.com.br
@@ -41,7 +41,7 @@ files:
41
41
  - LICENSE
42
42
  - Rakefile
43
43
  - README.md
44
- homepage: ''
44
+ homepage: https://github.com/davidwilliam/speaker
45
45
  licenses: []
46
46
  post_install_message:
47
47
  rdoc_options: []