att_speech 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # att_speech
2
2
 
3
+ ![Build Status](https://secure.travis-ci.org/jsgoecke/att_speech.png)
4
+
3
5
  A Ruby library for consuming the AT&T [Speech API](https://developer.att.com/developer/apiDetailPage.jsp?passedItemId=10700023) for speech to text. API details may be found [here](http://developer.att.com/developer/apiDetailPage.jsp?passedItemId=10900039).
4
6
 
5
7
  ## Installation
@@ -18,7 +20,7 @@ secret_key = 'bar'
18
20
 
19
21
  att_speech = ATTSpeech.new(api_key, secret_key)
20
22
 
21
- # Block operation
23
+ # Blocking operation
22
24
  p att_speech.speech_to_text('bostonSeltics.wav', type='audio/wav')
23
25
  #<Hashie::Mash recognition=#<Hashie::Mash n_best=#<Hashie::Mash confidence=1 grade="accept" hypothesis="Boston celtics." language_id="en-us" result_text="Boston celtics." word_scores=[1, 1] words=["Boston", "celtics."]> response_id="452d848c6d1a4be3f2bc987e5201ae38">>
24
26
 
@@ -26,6 +28,13 @@ p att_speech.speech_to_text('bostonSeltics.wav', type='audio/wav')
26
28
  future = att_speech.future(:speech_to_text, 'bostinSeltics.wav', type='audio/wav')
27
29
  p future.value
28
30
  #<Hashie::Mash recognition=#<Hashie::Mash n_best=#<Hashie::Mash confidence=1 grade="accept" hypothesis="Boston celtics." language_id="en-us" result_text="Boston celtics." word_scores=[1, 1] words=["Boston", "celtics."]> response_id="452d848c6d1a4be3f2bc987e5201ae38">>
31
+
32
+ # Non-blocking operation that will call a block when the transcrption is returned
33
+ # Note: Remember, this is a concurrent operation so don't pass self and avoid mutable objects in the block
34
+ # from the calling context, better to have discreet actions contained in the block, such as inserting in a
35
+ # datastore or POSTing to a REST webservice as a callback
36
+ att_speech.speech_to_text!('spec/spec_helper.rb') { |transcription| p transcription }
37
+ #<Hashie::Mash recognition=#<Hashie::Mash n_best=#<Hashie::Mash confidence=1 grade="accept" hypothesis="Boston celtics." language_id="en-us" result_text="Boston celtics." word_scores=[1, 1] words=["Boston", "celtics."]> response_id="452d848c6d1a4be3f2bc987e5201ae38">>
29
38
  ```
30
39
 
31
40
  ## Copyright
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -13,6 +13,7 @@ class ATTSpeech
13
13
  #
14
14
  # @return [Object] an instance of ATTSpeech
15
15
  def initialize(api_key, secret_key, base_url='https://api.att.com')
16
+ @signaled = false
16
17
  @api_key = api_key
17
18
  @secret_key = secret_key
18
19
  @base_url = base_url
@@ -32,9 +33,10 @@ class ATTSpeech
32
33
  # @param [String] file_contents to be processed
33
34
  # @param [String] type of file to be processed, may be audio/wav, application/octet-stream or audio/amr
34
35
  # @param [String] speech_context to use to evaluate the audio Generic, UVerseEPG, BusinessSearch, Websearch, SMS, Voicemail, QuestionAndAnswer
36
+ # @param [Block] block to be called when the transcription completes
35
37
  #
36
38
  # @return [Hash] the resulting response from the AT&T Speech API
37
- def speech_to_text(file_contents, type='audio/wav', speech_context='Generic')
39
+ def speech_to_text(file_contents, type='audio/wav', speech_context='Generic', &block)
38
40
  resource = "/rest/1/SpeechToText"
39
41
 
40
42
  if type == "application/octet-stream"
@@ -49,14 +51,16 @@ class ATTSpeech
49
51
  :Content_Type => type,
50
52
  :Accept => 'application/json'
51
53
 
52
- process_response(response)
54
+ result = process_response(response)
55
+ block.call result if block_given?
56
+ result
53
57
  rescue => e
54
58
  raise RuntimeError, e.to_s
55
59
  end
56
60
  end
57
61
 
58
62
  private
59
-
63
+
60
64
  ##
61
65
  # Creates the Faraday connection object
62
66
  def create_connection
@@ -1,3 +1,3 @@
1
1
  class ATTSpeech
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -42,10 +42,20 @@ describe "AttSpeech" do
42
42
  future.instance_of?(Celluloid::Future).should eql true
43
43
  end
44
44
 
45
- it "should allow us to user a future to process an audio file" do
45
+ it "should allow us to use a future to process an audio file" do
46
46
  future = att_speech.future(:speech_to_text, 'spec/spec_helper.rb')
47
47
  future.value[:recognition][:response_id].should eql '2b0bdcf4301f5c4aba57e2765b59bcbe'
48
48
  future.value[:recognition][:n_best][:confidence].should eql 1
49
49
  end
50
50
  end
51
+
52
+ describe 'non-blocking call with a block' do
53
+ it "should allow us to use a future to process an audio file and pass a block" do
54
+ result = nil
55
+ att_speech.speech_to_text!('spec/spec_helper.rb') { |transcription| result = transcription }
56
+ sleep 0.5
57
+ result[:recognition][:response_id].should eql '2b0bdcf4301f5c4aba57e2765b59bcbe'
58
+ result[:recognition][:n_best][:confidence].should eql 1
59
+ end
60
+ end
51
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: att_speech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: