Class: Azure::TTS::Speaker
- Inherits:
-
Object
- Object
- Azure::TTS::Speaker
- Defined in:
- lib/azure/tts/speaker.rb
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(text:, voice:, format:) ⇒ Speaker
constructor
A new instance of Speaker.
- #speak ⇒ Object
- #ssml ⇒ Object
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
#headers ⇒ Object
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 |
#speak ⇒ Object
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 |
#ssml ⇒ Object
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 |