Class: Speaker::Base

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options={})
	@language = options[:language] || DEFAULT_LANGUAGE
	@text = options[:text] || DEFAULT_TEXT
	delete_audio_file
end

Instance Attribute Details

#audio_file_path=(value) ⇒ Object

Sets the attribute audio_file_path

Parameters:

  • value

    the value to set the attribute audio_file_path to.



10
11
12
# File 'lib/speaker/base.rb', line 10

def audio_file_path=(value)
  @audio_file_path = value
end

#languageObject

Returns the value of attribute language.



10
11
12
# File 'lib/speaker/base.rb', line 10

def language
  @language
end

#textObject

Returns the value of attribute text.



10
11
12
# File 'lib/speaker/base.rb', line 10

def text
  @text
end

Instance Method Details

#audio_fileObject



49
50
51
# File 'lib/speaker/base.rb', line 49

def audio_file
	"#{audio_file_path}/#{FILE_NAME}.mp3"
end

#has_audio?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/speaker/base.rb', line 36

def has_audio?
	File.exist?(audio_file)
end

#playObject



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_audioObject



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

#ttsObject



23
24
25
26
# File 'lib/speaker/base.rb', line 23

def tts
	to_audio
	play
end