tropo-webapi-ruby 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +39 -1
- data/VERSION +1 -1
- data/lib/tropo-webapi-ruby.rb +3 -0
- data/lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb +13 -1
- data/lib/tropo-webapi-ruby/tropo-webapi-ruby.rb +29 -4
- data/spec/tropo-webapi-ruby_spec.rb +92 -1
- data/tropo-webapi-ruby.gemspec +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -9,7 +9,7 @@ your own web servers.
|
|
9
9
|
|
10
10
|
== Requirements
|
11
11
|
|
12
|
-
* Ruby v1.8.6
|
12
|
+
* Unit tests passed on: Ruby MRI v1.8.6/1.8.7 and JRuby v1.5.0
|
13
13
|
* RubyGems
|
14
14
|
|
15
15
|
Note: If using with ActiveSupport, v2.3.5 or better of ActiveSupport is required.
|
@@ -185,6 +185,44 @@ Using the great RESTful Web Services framework Sinatra for Ruby.
|
|
185
185
|
Tropo::Generator.reject
|
186
186
|
end
|
187
187
|
|
188
|
+
==== Setting a default voice for speech synthesis (text-to-speech/TTS)
|
189
|
+
|
190
|
+
post '/speak.json' do
|
191
|
+
t = Tropo::Generator.new(:voice => 'kate')
|
192
|
+
t.say 'Hello!' # Will speak as kate now
|
193
|
+
|
194
|
+
# or
|
195
|
+
|
196
|
+
t = Tropo::Generator.new
|
197
|
+
t.voice = 'kate'
|
198
|
+
t.say 'Hello!' # Will speak as kate now
|
199
|
+
end
|
200
|
+
|
201
|
+
==== Setting a default recognizer for speech recognition (ASR)
|
202
|
+
|
203
|
+
post '/ask.json' do
|
204
|
+
t = Tropo::Generator.new(:recognizer => 'fr-fr')
|
205
|
+
t.ask({ :name => 'account_number', # Will now use the French speech recognition engine
|
206
|
+
:bargein => 'true',
|
207
|
+
:timeout => 30,
|
208
|
+
:require => 'true' }) do
|
209
|
+
say :value => "S'il vous plaît dire votre numéro de compte", :voice => 'florence'
|
210
|
+
choices :value => '[5 DIGITS]'
|
211
|
+
end
|
212
|
+
|
213
|
+
# or
|
214
|
+
|
215
|
+
t = Tropo::Generator.new
|
216
|
+
t.recognizer = 'fr-fr'
|
217
|
+
t.ask({ :name => 'account_number', # Will now use the French speech recognition engine
|
218
|
+
:bargein => 'true',
|
219
|
+
:timeout => 30,
|
220
|
+
:require => 'true' }) do
|
221
|
+
say :value => "S'il vous plaît dire votre numéro de compte", :voice => 'florence'
|
222
|
+
choices :value => '[5 DIGITS]'
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
188
226
|
=== Additional Examples
|
189
227
|
|
190
228
|
May be found by checking out the project from Github, and then looking in $PROJECT_HOME/examples and $PROJECT_HOME/spec/tropo-webapi-ruby_spec.rb.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/lib/tropo-webapi-ruby.rb
CHANGED
@@ -1,2 +1,5 @@
|
|
1
1
|
$: << File.expand_path(File.dirname(__FILE__))
|
2
2
|
%w(uri json hashie time tropo-webapi-ruby/tropo-webapi-ruby-helpers tropo-webapi-ruby/tropo-webapi-ruby).each { |lib| require lib }
|
3
|
+
|
4
|
+
# Add the instance_exec method to the object class for Ruby 1.8.6 support
|
5
|
+
require 'tropo-webapi-ruby/object_patch' if RUBY_VERSION == '1.8.6'
|
@@ -144,7 +144,7 @@ module Tropo
|
|
144
144
|
def decamelize(camel_string)
|
145
145
|
camel_string.gsub(/[A-Z]/) { |char| '_' + char.downcase }
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
##
|
149
149
|
# Formats the @response instance variable to JSON before making it available to the accessor
|
150
150
|
#
|
@@ -153,6 +153,18 @@ module Tropo
|
|
153
153
|
@response.to_json
|
154
154
|
end
|
155
155
|
|
156
|
+
##
|
157
|
+
# Determines if there is a voice or recognizer specified, if not set it to the default specified and if not default leave it alone
|
158
|
+
# this is for the speech synthesis and speech recognition language to use on a say/ask methods
|
159
|
+
#
|
160
|
+
# @params [Hash] the array of values to check if a voice and recognizer are present
|
161
|
+
# @return [Hash] Will return the params with the appropriate voice/recognizer values set
|
162
|
+
def set_language(params)
|
163
|
+
params.merge!({ :recognizer => @recognizer }) if params[:recognizer].nil? && @recognizer
|
164
|
+
params.merge!({ :voice => @voice }) if params[:voice].nil? && @voice
|
165
|
+
params
|
166
|
+
end
|
167
|
+
|
156
168
|
##
|
157
169
|
# Returns an hash from a collapsed array, using the values of 'key' or 'name' as the collpassed hash key
|
158
170
|
#
|
@@ -4,8 +4,10 @@ module Tropo
|
|
4
4
|
include Tropo::Helpers
|
5
5
|
|
6
6
|
##
|
7
|
-
# Set a couple of Booleans to indicate the session type as a convenience
|
8
|
-
|
7
|
+
# Set a couple of Booleans to indicate the session type as a convenience
|
8
|
+
# Set a default voice for speech synthesis
|
9
|
+
# Set a default recognizer for speech recognition
|
10
|
+
attr_reader :voice_session, :text_session, :voice, :recognizer
|
9
11
|
|
10
12
|
##
|
11
13
|
# Defines the actions on self so that we may call them individually
|
@@ -23,13 +25,18 @@ module Tropo
|
|
23
25
|
#
|
24
26
|
# @overload initialize()
|
25
27
|
# @overload initialize(params)
|
28
|
+
# @param [String] voice sets the value of the default voice
|
26
29
|
# @param [Object] pass in an object that may be accessed inside the block
|
27
30
|
# @overload initialize(params, &block)
|
28
31
|
# @param [Object] pass in an object that may be accessed inside the block
|
32
|
+
# @param [String] voice sets the value of the default voice
|
29
33
|
# @param [Block] a block of code to execute (optional)
|
30
34
|
# @return [Object] a new Generator object
|
31
|
-
def initialize(params=
|
35
|
+
def initialize(params={}, &block)
|
32
36
|
@response = { :tropo => Array.new }
|
37
|
+
@voice = params[:voice] if params[:voice]
|
38
|
+
@recognizer = params[:recognizer] if params[:recognizer]
|
39
|
+
|
33
40
|
if block_given?
|
34
41
|
# Lets us know were are in the midst of building a block, so we only rendor the JSON
|
35
42
|
# response at the end of executing the block, rather than at each action
|
@@ -64,6 +71,7 @@ module Tropo
|
|
64
71
|
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
65
72
|
# if the method has been called from inside a block
|
66
73
|
def ask(params={}, &block)
|
74
|
+
params = set_language(params)
|
67
75
|
if block_given?
|
68
76
|
create_nested_hash('ask', params)
|
69
77
|
instance_exec(&block)
|
@@ -157,7 +165,7 @@ module Tropo
|
|
157
165
|
# @option params [optional, String] :exit_tone whether to play a beep when this user exits a conference
|
158
166
|
# @return [String, nil] the JSON string to be passed back to Tropo or nil
|
159
167
|
# if the method has been called from inside a block
|
160
|
-
def conference(params={}, &block)
|
168
|
+
def conference(params={}, &block)
|
161
169
|
if block_given?
|
162
170
|
create_nested_hash('conference', params)
|
163
171
|
instance_exec(&block)
|
@@ -287,6 +295,14 @@ module Tropo
|
|
287
295
|
transformed_response = Hashie::Mash.new(transformed_response)
|
288
296
|
end
|
289
297
|
|
298
|
+
##
|
299
|
+
# Sets the default recognizer for the object
|
300
|
+
#
|
301
|
+
# @param [String] recognizer the value to set the default voice to
|
302
|
+
def recognizer=(recognizer)
|
303
|
+
@recognizer = recognizer
|
304
|
+
end
|
305
|
+
|
290
306
|
##
|
291
307
|
# Plays a prompt (audio file or text to speech) and optionally waits for a response from the caller that is recorded.
|
292
308
|
# If collected, responses may be in the form of DTMF or speech recognition using a simple grammar format defined below.
|
@@ -414,10 +430,12 @@ module Tropo
|
|
414
430
|
|
415
431
|
if params.kind_of? Array
|
416
432
|
params.each do |param|
|
433
|
+
param = set_language(param)
|
417
434
|
hash = build_action('say', param)
|
418
435
|
response[:say] << hash
|
419
436
|
end
|
420
437
|
else
|
438
|
+
params = set_language(params)
|
421
439
|
hash = build_action('say', params)
|
422
440
|
response[:say] << hash
|
423
441
|
end
|
@@ -513,5 +531,12 @@ module Tropo
|
|
513
531
|
render_response if @building.nil?
|
514
532
|
end
|
515
533
|
|
534
|
+
##
|
535
|
+
# Sets the default voice for the object
|
536
|
+
#
|
537
|
+
# @param [String] voice the value to set the default voice to
|
538
|
+
def voice=(voice)
|
539
|
+
@voice = voice
|
540
|
+
end
|
516
541
|
end
|
517
542
|
end
|
@@ -487,7 +487,7 @@ describe "Tropo" do
|
|
487
487
|
|
488
488
|
it "should generate a valid JSON string for a record method with a transcription request" do
|
489
489
|
hash_result = {"tropo"=>[{"record"=>{"name"=>"foo", "transcription"=>{"email_format"=>"encoded", "url"=>"mailto:jose@voxeo.com", "id"=>"bling"}, "say"=>[{"value"=>"Please say your account number"}], "beep"=>true, "url"=>"http://sendme.com/tropo", "exitTone"=>"#", "sendTones"=>false, "choices"=>{"value"=>"[5 DIGITS]"}}}]}
|
490
|
-
tropo = Tropo::Generator.record({ :name
|
490
|
+
tropo = Tropo::Generator.record({ :name => 'foo',
|
491
491
|
:url => 'http://sendme.com/tropo',
|
492
492
|
:beep => true,
|
493
493
|
:send_tones => false,
|
@@ -519,4 +519,95 @@ describe "Tropo" do
|
|
519
519
|
:choices => { :value => yes_no_choices}
|
520
520
|
JSON.parse(t.response).should == hash_result
|
521
521
|
end
|
522
|
+
|
523
|
+
it "should set the voice variable when called" do
|
524
|
+
t = Tropo::Generator.new
|
525
|
+
t.voice.should == nil
|
526
|
+
|
527
|
+
t = Tropo::Generator.new(:voice => 'barnie')
|
528
|
+
t.voice.should == 'barnie'
|
529
|
+
|
530
|
+
t = Tropo::Generator.new
|
531
|
+
t.voice = 'barnie'
|
532
|
+
t.voice.should == 'barnie'
|
533
|
+
end
|
534
|
+
|
535
|
+
it "should handle the setting of the voice parameter based on defaults" do
|
536
|
+
t = Tropo::Generator.new
|
537
|
+
t.say 'Hi there!'
|
538
|
+
JSON.parse(t.response)['tropo'][0]['say'][0]['voice'].should == nil
|
539
|
+
|
540
|
+
t = Tropo::Generator.new
|
541
|
+
t.say 'Hi there!', :voice => 'barnie'
|
542
|
+
JSON.parse(t.response)['tropo'][0]['say'][0]['voice'].should == 'barnie'
|
543
|
+
|
544
|
+
t = Tropo::Generator.new(:voice => 'barnie')
|
545
|
+
t.say 'Hi there!'
|
546
|
+
t.say 'Wow!'
|
547
|
+
JSON.parse(t.response)['tropo'][0]['say'][0]['voice'].should == 'barnie'
|
548
|
+
JSON.parse(t.response)['tropo'][1]['say'][0]['voice'].should == 'barnie'
|
549
|
+
|
550
|
+
t = Tropo::Generator.new(:voice => 'barnie')
|
551
|
+
t.say 'Hi there!'
|
552
|
+
t.say 'Wow!', :voice => 'jack'
|
553
|
+
JSON.parse(t.response)['tropo'][0]['say'][0]['voice'].should == 'barnie'
|
554
|
+
JSON.parse(t.response)['tropo'][1]['say'][0]['voice'].should == 'jack'
|
555
|
+
|
556
|
+
t = Tropo::Generator.new
|
557
|
+
t.voice = 'barnie'
|
558
|
+
t.say 'Hi there!'
|
559
|
+
t.say 'Wow!', :voice => 'jack'
|
560
|
+
JSON.parse(t.response)['tropo'][0]['say'][0]['voice'].should == 'barnie'
|
561
|
+
JSON.parse(t.response)['tropo'][1]['say'][0]['voice'].should == 'jack'
|
562
|
+
end
|
563
|
+
|
564
|
+
it "should set the recognizer variable when called" do
|
565
|
+
t = Tropo::Generator.new
|
566
|
+
t.recognizer.should == nil
|
567
|
+
|
568
|
+
t = Tropo::Generator.new(:recognizer => 'fr-fr')
|
569
|
+
t.recognizer.should == 'fr-fr'
|
570
|
+
|
571
|
+
t = Tropo::Generator.new
|
572
|
+
t.recognizer = 'fr-fr'
|
573
|
+
t.recognizer.should == 'fr-fr'
|
574
|
+
end
|
575
|
+
|
576
|
+
it "should handle the setting of the recognizer parameter based on defaults" do
|
577
|
+
t = Tropo::Generator.new
|
578
|
+
t.ask({ :name => 'foo',
|
579
|
+
:bargein => 'true',
|
580
|
+
:timeout => 30,
|
581
|
+
:require => 'true' })
|
582
|
+
JSON.parse(t.response)['tropo'][0]['ask']['recognizer'].should == nil
|
583
|
+
|
584
|
+
t = Tropo::Generator.new(:recognizer => 'fr-fr')
|
585
|
+
t.ask({ :name => 'foo',
|
586
|
+
:bargein => 'true',
|
587
|
+
:timeout => 30,
|
588
|
+
:require => 'true' })
|
589
|
+
JSON.parse(t.response)['tropo'][0]['ask']['recognizer'].should == 'fr-fr'
|
590
|
+
|
591
|
+
t = Tropo::Generator.new
|
592
|
+
t.recognizer = 'fr-fr'
|
593
|
+
t.ask({ :name => 'foo',
|
594
|
+
:bargein => 'true',
|
595
|
+
:timeout => 30,
|
596
|
+
:require => 'true' })
|
597
|
+
JSON.parse(t.response)['tropo'][0]['ask']['recognizer'].should == 'fr-fr'
|
598
|
+
|
599
|
+
t = Tropo::Generator.new
|
600
|
+
t.recognizer = 'fr-fr'
|
601
|
+
t.ask({ :name => 'foo',
|
602
|
+
:bargein => 'true',
|
603
|
+
:timeout => 30,
|
604
|
+
:require => 'true' })
|
605
|
+
t.ask({ :name => 'foo',
|
606
|
+
:bargein => 'true',
|
607
|
+
:timeout => 30,
|
608
|
+
:require => 'true',
|
609
|
+
:recognizer => 'de-de' })
|
610
|
+
JSON.parse(t.response)['tropo'][0]['ask']['recognizer'].should == 'fr-fr'
|
611
|
+
JSON.parse(t.response)['tropo'][1]['ask']['recognizer'].should == 'de-de'
|
612
|
+
end
|
522
613
|
end
|
data/tropo-webapi-ruby.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tropo-webapi-ruby}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jason Goecke"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-14}
|
13
13
|
s.description = %q{Ruby library for interacting with the Tropo Web API via REST & JSON}
|
14
14
|
s.email = %q{jsgoecke@voxeo.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tropo-webapi-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Goecke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-05-14 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|