Class: Acapela::VoiceService
- Inherits:
-
Object
- Object
- Acapela::VoiceService
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
#config ⇒ Object
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_response ⇒ Object
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_response ⇒ Object
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_response ⇒ Object
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_response ⇒ Object
8
9
10
|
# File 'lib/acapela/mocks/voice_service.rb', line 8
def self.expected_response
@@expected_response
end
|
.last_posted_params ⇒ Object
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.(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.login,
:cl_app => @config.application,
:cl_pwd => @config.password,
:req_type => 'NEW',
:req_voice => voice.id,
:req_text => text,
}
Response.new(post(params))
end
|