Class: Speaker::Base
- Inherits:
-
Object
- Object
- Speaker::Base
- Defined in:
- lib/speaker/base.rb
Constant Summary collapse
- FILE_NAME =
'audio'
- GOOGLE_TRANSLATOR_PATH =
"http://translate.google.com/translate_tts?"
- DEFAULT_LANGUAGE =
'en'
- DEFAULT_TEXT =
'Nothing to say'
Instance Attribute Summary collapse
-
#audio_file_path ⇒ Object
writeonly
Sets the attribute audio_file_path.
-
#language ⇒ Object
Returns the value of attribute language.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #audio_file ⇒ Object
- #has_audio? ⇒ Boolean
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #play ⇒ Object
- #to_audio ⇒ Object
- #tts ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 |
# File 'lib/speaker/base.rb', line 17 def initialize(={}) @language = [:language] || DEFAULT_LANGUAGE @text = [:text] || DEFAULT_TEXT delete_audio_file end |
Instance Attribute Details
#audio_file_path=(value) ⇒ Object
Sets the attribute audio_file_path
10 11 12 |
# File 'lib/speaker/base.rb', line 10 def audio_file_path=(value) @audio_file_path = value end |
#language ⇒ Object
Returns the value of attribute language.
10 11 12 |
# File 'lib/speaker/base.rb', line 10 def language @language end |
#text ⇒ Object
Returns the value of attribute text.
10 11 12 |
# File 'lib/speaker/base.rb', line 10 def text @text end |
Instance Method Details
#audio_file ⇒ Object
49 50 51 |
# File 'lib/speaker/base.rb', line 49 def audio_file "#{audio_file_path}/#{FILE_NAME}.mp3" end |
#has_audio? ⇒ Boolean
36 37 38 |
# File 'lib/speaker/base.rb', line 36 def has_audio? File.exist?(audio_file) end |
#play ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/speaker/base.rb', line 40 def play if has_audio? `#{player} #{audio_file}` @text else "There is no audio file yet" end end |
#to_audio ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/speaker/base.rb', line 28 def to_audio split_sentence build_mp3 join_audio_files delete_audio_files nil end |
#tts ⇒ Object
23 24 25 26 |
# File 'lib/speaker/base.rb', line 23 def tts to_audio play end |