Class: AgileNotifier::TTS::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/agile_notifier/tts.rb

Constant Summary collapse

@@temp_file =
File.dirname(__FILE__) + '/temp_tts'

Class Method Summary collapse

Class Method Details

.mary_tts(text, language) ⇒ Object



99
100
101
102
103
104
# File 'lib/agile_notifier/tts.rb', line 99

def mary_tts(text, language)
  url = 'http://mary.dfki.de:59125/'
  text = encode_www_form_and_remove_punctuation(text)
  audio_format = 'WAVE_FILE'
  play(url + "process?INPUT_TEXT=#{text}&INPUT_TYPE=TEXT&OUTPUT_TYPE=AUDIO&LOCALE=#{language}&AUDIO=#{audio_format}")
end

.speak_on_linux(text, language, voice = nil) ⇒ Object



59
60
61
62
# File 'lib/agile_notifier/tts.rb', line 59

def speak_on_linux(text, language, voice = nil)
  # TODO: should check service availability first, if not raise exception
  mary_tts(text, language)
end

.speak_on_osx(text, language, voice) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/agile_notifier/tts.rb', line 64

def speak_on_osx(text, language, voice)
  if voice
    unless osx_speech(voice, text)
      raise("No available voice found, please check if you have downloaded voice [#{voice}] in System Preferences -> Speech")
    end
  else
    list_of_available_voices = `say -v '?'`.split("\n")
    voices = list_of_available_voices.inject({}) do |collection, record|
      matched_results = record.match(/^(.*[^\s])\s+([a-z]{2})[_-][a-zA-Z]{2,}\s+/)
      available_language = matched_results[2].downcase.intern
      available_voice = matched_results[1]
      if collection.has_key?(available_language)
        collection[available_language] << available_voice
      else
        collection[available_language] = [available_voice]
      end
      collection
    end
    osx_speech(voices[language.intern].first, text)
  end
end

.speak_on_windows(text, language, voice = nil) ⇒ Object

Raises:

  • (NotImplementedError)


86
87
88
# File 'lib/agile_notifier/tts.rb', line 86

def speak_on_windows(text, language, voice = nil)
  raise(NotImplementedError, "Method [#{__method__}] is empty, please implement", caller)
end

.tts_api(text) ⇒ Object



94
95
96
97
# File 'lib/agile_notifier/tts.rb', line 94

def tts_api(text)
  url = 'http://tts-api.com/tts.mp3?q='
  play(url + encode_www_form_and_remove_punctuation(text))
end