Class: Azure::TTS::Speaker

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

Instance Method Summary collapse

Constructor Details

#initialize(text:, voice:, format:) ⇒ Speaker

Returns a new instance of Speaker.



6
7
8
9
10
# File 'lib/azure/tts/speaker.rb', line 6

def initialize(text:, voice:, format:)
  @text = text
  @voice = voice
  @format = format
end

Instance Method Details

#headersObject



25
26
27
28
29
30
31
# File 'lib/azure/tts/speaker.rb', line 25

def headers
  {
    "Content-Type" => "application/ssml+xml",
    "X-Microsoft-OutputFormat" => Azure::TTS::AUDIO_FORMATS[@format],
    "User-Agent" => "Azure::TTS"
  }
end

#speakObject

Raises:



12
13
14
15
16
17
# File 'lib/azure/tts/speaker.rb', line 12

def speak
  response = Azure::TTS.api.tts.post(nil, ssml, headers)
  raise RequestError, response unless response.success?

  response.body
end

#ssmlObject



19
20
21
22
23
# File 'lib/azure/tts/speaker.rb', line 19

def ssml
  ssml = RubySpeech::SSML.draw
  ssml.voice gender: @voice.gender, name: @voice.short_name, language: @voice.locale, content: @text
  ssml.to_s
end