Class: Acapela::VoiceService

Inherits:
Object
  • Object
show all
Includes:
Mocks
Defined in:
lib/acapela/voice_service.rb,
lib/acapela/mocks/voice_service.rb

Constant Summary collapse

CLIENT_ENVIRONMENT =
"RUBY_#{RUBY_VERSION}"
ERROR_MISSING_CONFIG =
Error.new("VoiceService requires configuration.")
@@expected_response =
EXAMPLE_ACAPELA_RESPONSE_OK
@@last_posted_params =
nil

Constants included from Mocks

Mocks::EXAMPLE_ACAPELA_RESPONSE_ACCESS_DENIED, Mocks::EXAMPLE_ACAPELA_RESPONSE_INVALID_PARAM, Mocks::EXAMPLE_ACAPELA_RESPONSE_OK, Mocks::RESPONSE_TEST_FILE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Acapela.config) ⇒ VoiceService

Returns a new instance of VoiceService.



12
13
14
15
16
17
18
# File 'lib/acapela/voice_service.rb', line 12

def initialize(config = Acapela.config)
  if config.is_a?(Acapela::Config)
    @config = config
  else
    raise ERROR_MISSING_CONFIG
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/acapela/voice_service.rb', line 10

def config
  @config
end

Class Method Details

.expect_access_denied_responseObject



24
25
26
# File 'lib/acapela/mocks/voice_service.rb', line 24

def self.expect_access_denied_response
  @@expected_response = EXAMPLE_ACAPELA_RESPONSE_ACCESS_DENIED
end

.expect_invalid_param_responseObject



20
21
22
# File 'lib/acapela/mocks/voice_service.rb', line 20

def self.expect_invalid_param_response
  @@expected_response = EXAMPLE_ACAPELA_RESPONSE_INVALID_PARAM
end

.expect_ok_responseObject



16
17
18
# File 'lib/acapela/mocks/voice_service.rb', line 16

def self.expect_ok_response
  @@expected_response = EXAMPLE_ACAPELA_RESPONSE_OK
end

.expected_responseObject



8
9
10
# File 'lib/acapela/mocks/voice_service.rb', line 8

def self.expected_response
  @@expected_response
end

.last_posted_paramsObject



12
13
14
# File 'lib/acapela/mocks/voice_service.rb', line 12

def self.last_posted_params
  @@last_posted_params
end

Instance Method Details

#generate_sound(text, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/acapela/voice_service.rb', line 20

def generate_sound(text, options = {})
  voice = Voice.extract_from_options(options)

  case options[:quality]
  when :low
    voice.low_quality!
  when :high
    voice.high_quality!
  end

  generate_with_voice(text, voice)
end

#generate_with_voice(text, voice) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/acapela/voice_service.rb', line 33

def generate_with_voice(text, voice)
  params = {
    :prot_vers => @config.protocol,
    :cl_env => CLIENT_ENVIRONMENT,
    :cl_vers => @config.version,
    :cl_login => @config.,
    :cl_app => @config.application,
    :cl_pwd => @config.password,
    :req_type => 'NEW',
   #:req_snd_id => nil,
    :req_voice => voice.id,
    :req_text => text,
   #:req_vol => nil, # Volume: min = 50, default = 32768, max = 65535
   #:req_spd => nil, # Speed: min = 60, default = 180, max = 360
   #:req_vct => nil, # Shaping: min = 50, default = 100, max = 150
   # Equalizer:  min = -100, default = 0, max = 100
   #:req_eq1 => nil, # Band 275Hz
   #:req_eq2 => nil, # Band: 2.2kHz
   #:req_eq3 => nil, # Band: 5kHz
   #:req_eq4 => nil, # Band: 8.3kHz
   #:req_snd_type => 'MP3', # Sound file type: MP3, WAV, RAW
   #:req_snd_ext => '.mp3', # Sound file extentions: .mp3 .wav .raw
   #:req_snd_kbps => 'CBR_48', # Variable bit rate VBR_5 to VRB_9 (5 = max quality, 9 min) or Constant Bit Rate CBR_8,16,32,48
   #:req_alt_snd_type => 'MP3', # Alternative Sound file type: MP3, WAV, RAW
   #:req_alt_snd_ext => '.mp3', # Alternative Sound file extentions: .mp3 .wav .raw
   #:req_wp => nil,  # 'ON' to receive word file URL
   #:req_bp => nil, # 'ON' to receive bookmark file URL
   #:req_mp => nil,  # 'ON' to receive mouth file URL
   #:req_comment => '', Information to store about the operation.
   #:req_start_time => nil, # The start time of the request will be used to calculate the deadline for request treatment
   #:req_timeout => nil, # The time allocated to request treatment in seconds.
   #:req_asw_type => 'SOUND', # Type of response:
                              #   "INFO", key/value params.
                              #   "SOUND", sound bytes once genearted.
                              #   "STREAM", bytes as they are generated.
   #:req_asw_as_alt_snd => 'no', # Receive alternative file as response.
   #:req_err_as_id3 => 'no', # Reveive errors encapsulated in ID3 tag of MP3.
   #:req_echo => '',  # Receive some creation request fields in response.
   #:req_asw_redirect_url => nil, # Redirect response to a different URL.
  }

  Response.new(post(params))
end