nuance 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,8 @@
2
2
  faraday
3
3
  celluloid
4
4
  hashie
5
+ waveinfo
6
+ securerandom
5
7
  nuance/version
6
8
  nuance/transcription
7
9
  nuance/text_to_speech
@@ -1,30 +1,30 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIFLTCCBBWgAwIBAgIDAcXvMA0GCSqGSIb3DQEBBQUAMEAxCzAJBgNVBAYTAlVT
3
- MRcwFQYDVQQKEw5HZW9UcnVzdCwgSW5jLjEYMBYGA1UEAxMPR2VvVHJ1c3QgU1NM
4
- IENBMB4XDTEyMTAyNDEzMTA0NFoXDTE0MTEyNjE0MTA1NVowgbkxKTAnBgNVBAUT
5
- IHk5Sk5Db3ZoUGJOQ2EvaUJNZE9jNGthWWhqNjhhSTliMQswCQYDVQQGEwJVUzEW
6
- MBQGA1UECBMNTWFzc2FjaHVzZXR0czEQMA4GA1UEBxMHUGVhYm9keTEjMCEGA1UE
7
- ChMaTnVhbmNlIENvbW11bmljYXRpb25zIEluYy4xETAPBgNVBAsTCE1vYmlsaXR5
8
- MR0wGwYDVQQDDBQqLm51YW5jZW1vYmlsaXR5Lm5ldDCCASIwDQYJKoZIhvcNAQEB
9
- BQADggEPADCCAQoCggEBAMV2moXwKA1tLUVmTdM5ZaVBr9a4I2OkTIjefNdFxtuH
10
- YBWKXA2eCDcy6pHk9V34HbGqAo1aEylJiXN90Y2uL43QdkAM9lPnRZRzynpPcKCh
11
- VODhWa8brXT1gVeoGlh9OXZE3RiK+rPHNUUfAOfGTg7bnXmiK6Bml58SExLpQxtI
12
- 9Wy9tNoTWJ4v1L6bxK776qE12DvaxyFNFgJp5m0R7hQmMXeyQzSrylsjlfUcgKR/
13
- O1LSxnAq7Kv3ijUxA0gKu7elWYdXI71/zRdjvNr9dSekb19rP/rcoNZsGQvT3uuc
14
- JnJVdujLbmSBm9U/JWHjzOC5Yhoul4RogGX442wMmXsCAwEAAaOCAbQw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jZW1vYmlsaXR5Lm5ldDA9BgNVHR8ENjA0MDKg
18
+ MKAuhixodHRwOi8vZ3Rzc2wtY3JsLmdlb3RydXN0LmNvbS9jcmxzL2d0c3NsLmNy
19
+ bDAdBgNVHQ4EFgQUNuyQCo6RJvAYlmfaaSZIVfPZpiMwDAYDVR0TAQH/BAIwADBv
20
+ BggrBgEFBQcBAQRjMGEwKgYIKwYBBQUHMAGGHmh0dHA6Ly9ndHNzbC1vY3NwLmdl
21
+ b3RydXN0LmNvbTAzBggrBgEFBQcwAoYnaHR0cDovL2d0c3NsLWFpYS5nZW90cnVz
22
+ dC5jb20vZ3Rzc2wuY3J0MEwGA1UdIARFMEMwQQYKYIZIAYb4RQEHNjAzMDEGCCsG
23
+ AQUFBwIBFiVodHRwOi8vd3d3Lmdlb3RydXN0LmNvbS9yZXNvdXJjZXMvY3BzMA0G
24
+ CSqGSIb3DQEBBQUAA4IBAQBA81miz43odjvvarBucFDKfKbhrQAWrEQB+Avri97g
25
+ ytN0xkfpdov0b/qLRNxm2oohqRKmKG0QdsVKfObWL1GoJrZo/YJc3IRcoBlZXUr2
26
+ QGZShAmAV6nBXlPAcbp+ryfLWEGRPCc3rs1TLsGrExxsLW6QcnKdnaoTuR7rWfbD
27
+ CnBoPFRnOgakXf1hxyNSSRgcx0oetFSL/jASD2bylRPU09eA9beZsOEcfGp4I7ON
28
+ +U77F36aRMgOfwE1JWiAjgcsUywHCfRo7084HtozrvUYmqgaxi2J5KQ6JOxsbOFS
29
+ 8hAxHOOsAqEUWOje7shQBTGW30FheDKjms7yUPuYh5me
30
+ -----END CERTIFICATE-----
@@ -20,13 +20,12 @@ module Nuance
20
20
  raise ArgumentError, ':app_key must be set' if !options[:app_key]
21
21
  raise ArgumentError, ':id must be set' if !options[:id]
22
22
 
23
- @base_uri = options[:base_uri] || 'https://dictation.nuancemobility.net'
24
- @app_id = options[:app_id] || ENV['NUANCE_APP_ID']
25
- @app_key = options[:app_key] || ENV['NUANCE_APP_KEY']
26
- @id = options[:id] || rand(100000000)
23
+ @base_uri = options[:base_uri] || 'https://dictation.nuancemobility.net'
24
+ @app_id = options[:app_id] || ENV['NUANCE_APP_ID']
25
+ @app_key = options[:app_key] || ENV['NUANCE_APP_KEY']
26
+ @id = options[:id] || rand(100000000)
27
+ @logging = options[:logging] || false
27
28
  @resource = "/NMDPAsrCmdServlet/dictation?appId=#{@app_id}&appKey=#{@app_key}&id=#{@id}"
28
- @logging = options[:logging] || false
29
-
30
29
  self
31
30
  end
32
31
 
@@ -43,7 +42,6 @@ module Nuance
43
42
  #
44
43
  # @return [Hash] the resulting response from the Nuance API
45
44
  def transcribe(options={}, &block)
46
- @content_type = options[:content_type] || 'audio/x-wav;codec=pcm;bit=16;rate=8000'
47
45
  @accept_topic = options[:accept_topic] || 'Dictation'
48
46
  @accept_language = options[:language] || 'en_US'
49
47
  @accept = options[:accept] || 'application/xml'
@@ -53,6 +51,12 @@ module Nuance
53
51
  raise ArgumentError, ':file_contents must be present' if !options[:file_contents]
54
52
  raise ArgumentError, ':language must be valid' if !language_valid?(options[:language])
55
53
 
54
+ if options[:content_type].nil?
55
+ @content_type = options[:content_type] || "audio/x-wav;codec=pcm;bit=16;rate=#{sample_rate(options[:file_contents]).to_s}"
56
+ else
57
+ @content_type = options[:content_type]
58
+ end
59
+
56
60
  create_connection
57
61
 
58
62
  begin
@@ -74,6 +78,19 @@ module Nuance
74
78
  end
75
79
  end
76
80
 
81
+ ##
82
+ # Determines the sample rate of the file
83
+ #
84
+ # @param [Object] file_contents of the file
85
+ # @return [String] the sample rate
86
+ def sample_rate(file_contents)
87
+ filename = '/tmp/' + SecureRandom.uuid + '.wav'
88
+ IO.binwrite filename, file_contents
89
+ wave = WaveInfo.new filename
90
+ File.delete filename
91
+ wave.sample_rate
92
+ end
93
+
77
94
  private
78
95
 
79
96
  ##
@@ -148,7 +165,7 @@ module Nuance
148
165
  end
149
166
 
150
167
  private
151
-
168
+
152
169
  def process(response)
153
170
  Hashie::Mash.new({ :status => 200, :body => response.body.split(/\r?\n/)[0] })
154
171
  end
@@ -1,3 +1,3 @@
1
1
  module Nuance
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency "hashie","=1.2.0"
24
24
  spec.add_runtime_dependency "faraday", "= 0.8.7"
25
25
  spec.add_runtime_dependency "celluloid", "= 0.12.4"
26
-
26
+ spec.add_runtime_dependency "waveinfo", "= 0.0.2"
27
27
  spec.add_development_dependency "bundler", "~> 1.3"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "rspec", "= 2.12.0"
@@ -57,7 +57,8 @@ describe Nuance::Transcription do
57
57
 
58
58
  describe '#validations' do
59
59
  it 'should allow a valid content type' do
60
- content_types = %w{ audio/x-wav;codec=pcm;bit=16;rate=8000
60
+ content_types = %w{
61
+ audio/x-wav;codec=pcm;bit=16;rate=8000
61
62
  audio/x-wav;codec=pcm;bit=16;rate=16000
62
63
  audio/x-speex;rate=8000
63
64
  audio/x-speex;rate=16000
@@ -199,7 +200,7 @@ describe Nuance::Transcription do
199
200
  :app_key => @options[:app_key],
200
201
  :id => @options[:id] })
201
202
  result = nil
202
- nuance_transcription.transcribe!(:file_contents => File.open('spec/DT-202c.wav').read) do |transcription|
203
+ nuance_transcription.transcribe!(:file_contents => File.open('spec/DT-202c.wav').read) do |transcription|
203
204
  result = transcription
204
205
  end
205
206
  sleep 0.1
@@ -207,5 +208,15 @@ describe Nuance::Transcription do
207
208
  result.body.should eql @transcription
208
209
  end
209
210
  end
211
+
212
+ describe '#audio file details' do
213
+ it 'should return a sample rate for the wave file' do
214
+ file_contents = File.open('spec/DT-202c.wav').read
215
+ nuance_transcription = Nuance::Transcription.new({ :app_id => @options[:app_id],
216
+ :app_key => @options[:app_key],
217
+ :id => @options[:id] })
218
+ nuance_transcription.sample_rate(file_contents).should eql 8000
219
+ end
220
+ end
210
221
  end
211
222
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nuance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-08 00:00:00.000000000 Z
13
+ date: 2013-07-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hashie
@@ -60,6 +60,22 @@ dependencies:
60
60
  - - '='
61
61
  - !ruby/object:Gem::Version
62
62
  version: 0.12.4
63
+ - !ruby/object:Gem::Dependency
64
+ name: waveinfo
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - '='
69
+ - !ruby/object:Gem::Version
70
+ version: 0.0.2
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - '='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.0.2
63
79
  - !ruby/object:Gem::Dependency
64
80
  name: bundler
65
81
  requirement: !ruby/object:Gem::Requirement
@@ -263,7 +279,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
263
279
  version: '0'
264
280
  segments:
265
281
  - 0
266
- hash: -4419268677901697390
282
+ hash: -4357327388774372871
267
283
  required_rubygems_version: !ruby/object:Gem::Requirement
268
284
  none: false
269
285
  requirements:
@@ -272,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
288
  version: '0'
273
289
  segments:
274
290
  - 0
275
- hash: -4419268677901697390
291
+ hash: -4357327388774372871
276
292
  requirements: []
277
293
  rubyforge_project:
278
294
  rubygems_version: 1.8.23