aws-sdk-transcribestreamingservice 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2faf6f761d13fa4553b3d6ea6f8ba73ff3676b9e
4
+ data.tar.gz: db19b99a59e3e99a7efc5b92608b2e81ffc45102
5
+ SHA512:
6
+ metadata.gz: e50c540946d5ac40207ca9f6c648ca200c7cfe3ee3648d640d0f8018f365386bb9b526c4cad6f6b948ea81f6411d51d863a748c8161286c49566a87993a881d8
7
+ data.tar.gz: 7f0b262052a80678a8270bdedec15fe47c108ff203b1b31ca3b016b35d3b4a2198d0863b87673939cbb7b706177ac5b3f69862535156285d5d96bdd4a93d1734
@@ -0,0 +1,49 @@
1
+ # WARNING ABOUT GENERATED CODE
2
+ #
3
+ # This file is generated. See the contributing guide for more information:
4
+ # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
5
+ #
6
+ # WARNING ABOUT GENERATED CODE
7
+
8
+ require 'aws-sdk-core'
9
+ require 'aws-sigv4'
10
+
11
+ require_relative 'aws-sdk-transcribestreamingservice/types'
12
+ require_relative 'aws-sdk-transcribestreamingservice/client_api'
13
+ require_relative 'aws-sdk-transcribestreamingservice/client'
14
+ require_relative 'aws-sdk-transcribestreamingservice/errors'
15
+ require_relative 'aws-sdk-transcribestreamingservice/resource'
16
+ require_relative 'aws-sdk-transcribestreamingservice/customizations'
17
+ require_relative 'aws-sdk-transcribestreamingservice/async_client'
18
+ require_relative 'aws-sdk-transcribestreamingservice/event_streams'
19
+
20
+ # This module provides support for Amazon Transcribe Streaming Service. This module is available in the
21
+ # `aws-sdk-transcribestreamingservice` gem.
22
+ #
23
+ # # Client
24
+ #
25
+ # The {Client} class provides one method for each API operation. Operation
26
+ # methods each accept a hash of request parameters and return a response
27
+ # structure.
28
+ #
29
+ # See {Client} for more information.
30
+ #
31
+ # # Errors
32
+ #
33
+ # Errors returned from Amazon Transcribe Streaming Service all
34
+ # extend {Errors::ServiceError}.
35
+ #
36
+ # begin
37
+ # # do stuff
38
+ # rescue Aws::TranscribeStreamingService::Errors::ServiceError
39
+ # # rescues all service API errors
40
+ # end
41
+ #
42
+ # See {Errors} for more information.
43
+ #
44
+ # @service
45
+ module Aws::TranscribeStreamingService
46
+
47
+ GEM_VERSION = '1.0.0'
48
+
49
+ end
@@ -0,0 +1,437 @@
1
+ # WARNING ABOUT GENERATED CODE
2
+ #
3
+ # This file is generated. See the contributing guide for more information:
4
+ # https://github.com/aws/aws-sdk-ruby/blob/master/CONTRIBUTING.md
5
+ #
6
+ # WARNING ABOUT GENERATED CODE
7
+
8
+ if RUBY_VERSION >= '2.1'
9
+ begin
10
+ require 'http/2'
11
+ rescue LoadError
12
+ STDERR.puts "Unable to load the http/2 gem."
13
+ end
14
+ end
15
+ require 'seahorse/client/plugins/content_length.rb'
16
+ require 'aws-sdk-core/plugins/credentials_configuration.rb'
17
+ require 'aws-sdk-core/plugins/logging.rb'
18
+ require 'aws-sdk-core/plugins/param_converter.rb'
19
+ require 'aws-sdk-core/plugins/param_validator.rb'
20
+ require 'aws-sdk-core/plugins/user_agent.rb'
21
+ require 'aws-sdk-core/plugins/helpful_socket_errors.rb'
22
+ require 'aws-sdk-core/plugins/retry_errors.rb'
23
+ require 'aws-sdk-core/plugins/global_configuration.rb'
24
+ require 'aws-sdk-core/plugins/regional_endpoint.rb'
25
+ require 'aws-sdk-core/plugins/stub_responses.rb'
26
+ require 'aws-sdk-core/plugins/idempotency_token.rb'
27
+ require 'aws-sdk-core/plugins/jsonvalue_converter.rb'
28
+ require 'aws-sdk-core/plugins/invocation_id.rb'
29
+ require 'aws-sdk-core/plugins/signature_v4.rb'
30
+ require 'aws-sdk-core/plugins/protocols/rest_json.rb'
31
+ require 'aws-sdk-core/plugins/event_stream_configuration.rb'
32
+
33
+ Aws::Plugins::GlobalConfiguration.add_identifier(:transcribestreamingservice)
34
+
35
+ module Aws::TranscribeStreamingService
36
+ class AsyncClient < Seahorse::Client::AsyncBase
37
+
38
+ include Aws::AsyncClientStubs
39
+
40
+ @identifier = :transcribestreamingservice
41
+
42
+ set_api(ClientApi::API)
43
+
44
+ add_plugin(Seahorse::Client::Plugins::ContentLength)
45
+ add_plugin(Aws::Plugins::CredentialsConfiguration)
46
+ add_plugin(Aws::Plugins::Logging)
47
+ add_plugin(Aws::Plugins::ParamConverter)
48
+ add_plugin(Aws::Plugins::ParamValidator)
49
+ add_plugin(Aws::Plugins::UserAgent)
50
+ add_plugin(Aws::Plugins::HelpfulSocketErrors)
51
+ add_plugin(Aws::Plugins::RetryErrors)
52
+ add_plugin(Aws::Plugins::GlobalConfiguration)
53
+ add_plugin(Aws::Plugins::RegionalEndpoint)
54
+ add_plugin(Aws::Plugins::StubResponses)
55
+ add_plugin(Aws::Plugins::IdempotencyToken)
56
+ add_plugin(Aws::Plugins::JsonvalueConverter)
57
+ add_plugin(Aws::Plugins::InvocationId)
58
+ add_plugin(Aws::Plugins::SignatureV4)
59
+ add_plugin(Aws::Plugins::Protocols::RestJson)
60
+ add_plugin(Aws::Plugins::EventStreamConfiguration)
61
+
62
+ # @option options [required, Aws::CredentialProvider] :credentials
63
+ # Your AWS credentials. This can be an instance of any one of the
64
+ # following classes:
65
+ #
66
+ # * `Aws::Credentials` - Used for configuring static, non-refreshing
67
+ # credentials.
68
+ #
69
+ # * `Aws::InstanceProfileCredentials` - Used for loading credentials
70
+ # from an EC2 IMDS on an EC2 instance.
71
+ #
72
+ # * `Aws::SharedCredentials` - Used for loading credentials from a
73
+ # shared file, such as `~/.aws/config`.
74
+ #
75
+ # * `Aws::AssumeRoleCredentials` - Used when you need to assume a role.
76
+ #
77
+ # When `:credentials` are not configured directly, the following
78
+ # locations will be searched for credentials:
79
+ #
80
+ # * `Aws.config[:credentials]`
81
+ # * The `:access_key_id`, `:secret_access_key`, and `:session_token` options.
82
+ # * ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']
83
+ # * `~/.aws/credentials`
84
+ # * `~/.aws/config`
85
+ # * EC2 IMDS instance profile - When used by default, the timeouts are
86
+ # very aggressive. Construct and pass an instance of
87
+ # `Aws::InstanceProfileCredentails` to enable retries and extended
88
+ # timeouts.
89
+ #
90
+ # @option options [required, String] :region
91
+ # The AWS region to connect to. The configured `:region` is
92
+ # used to determine the service `:endpoint`. When not passed,
93
+ # a default `:region` is search for in the following locations:
94
+ #
95
+ # * `Aws.config[:region]`
96
+ # * `ENV['AWS_REGION']`
97
+ # * `ENV['AMAZON_REGION']`
98
+ # * `ENV['AWS_DEFAULT_REGION']`
99
+ # * `~/.aws/credentials`
100
+ # * `~/.aws/config`
101
+ #
102
+ # @option options [String] :access_key_id
103
+ #
104
+ # @option options [Boolean] :convert_params (true)
105
+ # When `true`, an attempt is made to coerce request parameters into
106
+ # the required types.
107
+ #
108
+ # @option options [String] :endpoint
109
+ # The client endpoint is normally constructed from the `:region`
110
+ # option. You should only configure an `:endpoint` when connecting
111
+ # to test endpoints. This should be avalid HTTP(S) URI.
112
+ #
113
+ # @option options [Proc] :event_stream_handler
114
+ # When an EventStream or Proc object is provided, it will be used as callback for each chunk of event stream response received along the way.
115
+ #
116
+ # @option options [Proc] :input_event_stream_handler
117
+ # When an EventStream or Proc object is provided, it can be used for sending events for the event stream.
118
+ #
119
+ # @option options [Aws::Log::Formatter] :log_formatter (Aws::Log::Formatter.default)
120
+ # The log formatter.
121
+ #
122
+ # @option options [Symbol] :log_level (:info)
123
+ # The log level to send messages to the `:logger` at.
124
+ #
125
+ # @option options [Logger] :logger
126
+ # The Logger instance to send log messages to. If this option
127
+ # is not set, logging will be disabled.
128
+ #
129
+ # @option options [Proc] :output_event_stream_handler
130
+ # When an EventStream or Proc object is provided, it will be used as callback for each chunk of event stream response received along the way.
131
+ #
132
+ # @option options [String] :profile ("default")
133
+ # Used when loading credentials from the shared credentials file
134
+ # at HOME/.aws/credentials. When not specified, 'default' is used.
135
+ #
136
+ # @option options [Float] :retry_base_delay (0.3)
137
+ # The base delay in seconds used by the default backoff function.
138
+ #
139
+ # @option options [Symbol] :retry_jitter (:none)
140
+ # A delay randomiser function used by the default backoff function. Some predefined functions can be referenced by name - :none, :equal, :full, otherwise a Proc that takes and returns a number.
141
+ #
142
+ # @see https://www.awsarchitectureblog.com/2015/03/backoff.html
143
+ #
144
+ # @option options [Integer] :retry_limit (3)
145
+ # The maximum number of times to retry failed requests. Only
146
+ # ~ 500 level server errors and certain ~ 400 level client errors
147
+ # are retried. Generally, these are throttling errors, data
148
+ # checksum errors, networking errors, timeout errors and auth
149
+ # errors from expired credentials.
150
+ #
151
+ # @option options [Integer] :retry_max_delay (0)
152
+ # The maximum number of seconds to delay between retries (0 for no limit) used by the default backoff function.
153
+ #
154
+ # @option options [String] :secret_access_key
155
+ #
156
+ # @option options [String] :session_token
157
+ #
158
+ # @option options [Boolean] :stub_responses (false)
159
+ # Causes the client to return stubbed responses. By default
160
+ # fake responses are generated and returned. You can specify
161
+ # the response data to return or errors to raise by calling
162
+ # {ClientStubs#stub_responses}. See {ClientStubs} for more information.
163
+ #
164
+ # ** Please note ** When response stubbing is enabled, no HTTP
165
+ # requests are made, and retries are disabled.
166
+ #
167
+ # @option options [Boolean] :validate_params (true)
168
+ # When `true`, request parameters are validated before
169
+ # sending the request.
170
+ #
171
+ def initialize(*args)
172
+ unless Kernel.const_defined?("HTTP2")
173
+ raise "Must include http/2 gem to use AsyncClient instances."
174
+ end
175
+ super
176
+ end
177
+
178
+ # @!group API Operations
179
+
180
+ # Starts a bidirectional HTTP2 stream where audio is streamed to Amazon
181
+ # Transcribe and the transcription results are streamed to your
182
+ # application.
183
+ #
184
+ # The following are encoded as HTTP2 headers:
185
+ #
186
+ # * x-amzn-transcribe-language-code
187
+ #
188
+ # * x-amzn-transcribe-media-encoding
189
+ #
190
+ # * x-amzn-transcribe-sample-rate
191
+ #
192
+ # * x-amzn-transcribe-session-id
193
+ #
194
+ # @option params [required, String] :language_code
195
+ # Indicates the language used in the input audio stream.
196
+ #
197
+ # @option params [required, Integer] :media_sample_rate_hertz
198
+ # The sample rate, in Hertz, of the input audio. We suggest that you use
199
+ # 8000 Hz for low quality audio and 16000 Hz for high quality audio.
200
+ #
201
+ # @option params [required, String] :media_encoding
202
+ # The encoding used for the input audio.
203
+ #
204
+ # @option params [String] :vocabulary_name
205
+ # The name of the vocabulary to use when processing the transcription
206
+ # job.
207
+ #
208
+ # @option params [String] :session_id
209
+ # A identifier for the transcription session. Use this parameter when
210
+ # you want to retry a session. If you don't provide a session ID,
211
+ # Amazon Transcribe will generate one for you and return it in the
212
+ # response.
213
+ #
214
+ # @return [Types::StartStreamTranscriptionResponse] Returns a {Seahorse::Client::Response response} object which responds to the following methods:
215
+ #
216
+ # * {Types::StartStreamTranscriptionResponse#request_id #request_id} => String
217
+ # * {Types::StartStreamTranscriptionResponse#language_code #language_code} => String
218
+ # * {Types::StartStreamTranscriptionResponse#media_sample_rate_hertz #media_sample_rate_hertz} => Integer
219
+ # * {Types::StartStreamTranscriptionResponse#media_encoding #media_encoding} => String
220
+ # * {Types::StartStreamTranscriptionResponse#vocabulary_name #vocabulary_name} => String
221
+ # * {Types::StartStreamTranscriptionResponse#session_id #session_id} => String
222
+ # * {Types::StartStreamTranscriptionResponse#transcript_result_stream #transcript_result_stream} => Types::TranscriptResultStream
223
+ #
224
+ # @example Bi-directional EventStream Operation Example
225
+ #
226
+ # You can signal input events after initial request is
227
+ # established, events will be sent to stream
228
+ # immediately (once stream connection is established successfully).
229
+ #
230
+ # To signal events, you can call #signal methods from an Aws::TranscribeStreamingService::EventStreams::AudioStream object.
231
+ # Make sure signal events before calling #wait or #join! at async response.
232
+ #
233
+ # input_stream = Aws::TranscribeStreamingService::EventStreams::AudioStream.new
234
+ #
235
+ # async_resp = client.start_stream_transcription( # params input,
236
+ # input_event_stream_handler: input_stream) do |out_stream|
237
+ #
238
+ # # register callbacks for events arrival
239
+ # out_stream.on_transcript_event_event do |event|
240
+ # event # => Aws::TranscribeStreamingService::Types::TranscriptEvent
241
+ # end
242
+ # out_stream.on_bad_request_exception_event do |event|
243
+ # event # => Aws::TranscribeStreamingService::Types::BadRequestException
244
+ # end
245
+ # out_stream.on_limit_exceeded_exception_event do |event|
246
+ # event # => Aws::TranscribeStreamingService::Types::LimitExceededException
247
+ # end
248
+ # out_stream.on_internal_failure_exception_event do |event|
249
+ # event # => Aws::TranscribeStreamingService::Types::InternalFailureException
250
+ # end
251
+ # out_stream.on_conflict_exception_event do |event|
252
+ # event # => Aws::TranscribeStreamingService::Types::ConflictException
253
+ # end
254
+ #
255
+ # end
256
+ # # => returns Aws::Seahorse::Client::AsyncResponse
257
+ #
258
+ # # signal events
259
+ # input_stream.signal_audio_event_event( ... )
260
+ #
261
+ # # make sure signaling :end_stream in the end
262
+ # input_stream.signal_end_stream
263
+ #
264
+ # # wait until stream is closed before finalizing sync response
265
+ # resp = async_resp.wait
266
+ # # Or close stream and finalizing sync response immediately
267
+ # # resp = async_resp.join!
268
+ #
269
+ # Inorder to streamingly processing events received, you can also provide an Aws::TranscribeStreamingService::EventStreams::TranscriptResultStream
270
+ # object to register callbacks before initializing request instead of processing from request block
271
+ #
272
+ # output_stream = Aws::TranscribeStreamingService::EventStreams::TranscriptResultStream.new
273
+ # # register callbacks for events arrival
274
+ # output_stream.on_transcript_event_event do |event|
275
+ # event # => Aws::TranscribeStreamingService::Types::TranscriptEvent
276
+ # end
277
+ # output_stream.on_bad_request_exception_event do |event|
278
+ # event # => Aws::TranscribeStreamingService::Types::BadRequestException
279
+ # end
280
+ # output_stream.on_limit_exceeded_exception_event do |event|
281
+ # event # => Aws::TranscribeStreamingService::Types::LimitExceededException
282
+ # end
283
+ # output_stream.on_internal_failure_exception_event do |event|
284
+ # event # => Aws::TranscribeStreamingService::Types::InternalFailureException
285
+ # end
286
+ # output_stream.on_conflict_exception_event do |event|
287
+ # event # => Aws::TranscribeStreamingService::Types::ConflictException
288
+ # end
289
+ # output_stream.on_error_event do |event|
290
+ # # catch unmodeled error event in the stream
291
+ # raise event
292
+ # # => Aws::Errors::EventError
293
+ # # event.event_type => :error
294
+ # # event.error_code => String
295
+ # # event.error_message => String
296
+ # end
297
+ #
298
+ # async_resp = client.start_stream_transcription ( #params input,
299
+ # input_event_stream_handler: input_stream
300
+ # output_event_stream_handler: output_stream
301
+ # )
302
+ #
303
+ # resp = async_resp.wait!
304
+ #
305
+ # Besides above usage patterns for process events when they arrive immediately, you can also
306
+ # iterate through events after response complete.
307
+ #
308
+ # Events are available at resp.transcript_result_stream # => Enumerator
309
+ #
310
+ # @example Request syntax with placeholder values
311
+ #
312
+ # async_resp = async_client.start_stream_transcription({
313
+ # language_code: "en-US", # required, accepts en-US, es-US
314
+ # media_sample_rate_hertz: 1, # required
315
+ # media_encoding: "pcm", # required, accepts pcm
316
+ # vocabulary_name: "VocabularyName",
317
+ # session_id: "SessionId",
318
+ # input_event_stream_hander: EventStreams::AudioStream.new,
319
+ # })
320
+ # # => Seahorse::Client::AsyncResponse
321
+ # async_resp.wait
322
+ # # => Seahorse::Client::Response
323
+ # # Or use async_resp.join!
324
+ #
325
+ # @example Response structure
326
+ #
327
+ # resp.request_id #=> String
328
+ # resp.language_code #=> String, one of "en-US", "es-US"
329
+ # resp.media_sample_rate_hertz #=> Integer
330
+ # resp.media_encoding #=> String, one of "pcm"
331
+ # resp.vocabulary_name #=> String
332
+ # resp.session_id #=> String
333
+ # All events are available at resp.transcript_result_stream:
334
+ # resp.transcript_result_stream #=> Enumerator
335
+ # resp.transcript_result_stream.event_types #=> [:transcript_event, :bad_request_exception, :limit_exceeded_exception, :internal_failure_exception, :conflict_exception]
336
+ #
337
+ # For :transcript_event event available at #on_transcript_event_event callback and response eventstream enumerator:
338
+ # event.transcript.results #=> Array
339
+ # event.transcript.results[0].result_id #=> String
340
+ # event.transcript.results[0].start_time #=> Float
341
+ # event.transcript.results[0].end_time #=> Float
342
+ # event.transcript.results[0].is_partial #=> Boolean
343
+ # event.transcript.results[0].alternatives #=> Array
344
+ # event.transcript.results[0].alternatives[0].transcript #=> String
345
+ # event.transcript.results[0].alternatives[0].items #=> Array
346
+ # event.transcript.results[0].alternatives[0].items[0].start_time #=> Float
347
+ # event.transcript.results[0].alternatives[0].items[0].end_time #=> Float
348
+ # event.transcript.results[0].alternatives[0].items[0].type #=> String, one of "PRONUNCIATION", "PUNCTUATION"
349
+ # event.transcript.results[0].alternatives[0].items[0].content #=> String
350
+ #
351
+ # For :bad_request_exception event available at #on_bad_request_exception_event callback and response eventstream enumerator:
352
+ # event.message #=> String
353
+ #
354
+ # For :limit_exceeded_exception event available at #on_limit_exceeded_exception_event callback and response eventstream enumerator:
355
+ # event.message #=> String
356
+ #
357
+ # For :internal_failure_exception event available at #on_internal_failure_exception_event callback and response eventstream enumerator:
358
+ # event.message #=> String
359
+ #
360
+ # For :conflict_exception event available at #on_conflict_exception_event callback and response eventstream enumerator:
361
+ # event.message #=> String
362
+ #
363
+ # @see http://docs.aws.amazon.com/goto/WebAPI/transcribe-streaming-2017-10-26/StartStreamTranscription AWS API Documentation
364
+ #
365
+ # @overload start_stream_transcription(params = {})
366
+ # @param [Hash] params ({})
367
+ def start_stream_transcription(params = {}, options = {}, &block)
368
+ params = params.dup
369
+ input_event_stream_handler = _event_stream_handler(
370
+ :input,
371
+ params.delete(:input_event_stream_handler),
372
+ EventStreams::AudioStream
373
+ )
374
+ output_event_stream_handler = _event_stream_handler(
375
+ :output,
376
+ params.delete(:output_event_stream_handler) || params.delete(:event_stream_handler),
377
+ EventStreams::TranscriptResultStream
378
+ )
379
+
380
+ yield(output_event_stream_handler) if block_given?
381
+
382
+ req = build_request(:start_stream_transcription, params)
383
+
384
+ req.context[:input_event_stream_handler] = input_event_stream_handler
385
+ req.handlers.add(Aws::Binary::EncodeHandler, priority: 95)
386
+ req.context[:output_event_stream_handler] = output_event_stream_handler
387
+ req.handlers.add(Aws::Binary::DecodeHandler, priority: 95)
388
+
389
+ req.send_request(options, &block)
390
+ end
391
+
392
+ # @!endgroup
393
+
394
+ # @param params ({})
395
+ # @api private
396
+ def build_request(operation_name, params = {})
397
+ handlers = @handlers.for(operation_name)
398
+ context = Seahorse::Client::RequestContext.new(
399
+ operation_name: operation_name,
400
+ operation: config.api.operation(operation_name),
401
+ client: self,
402
+ params: params,
403
+ http_response: Seahorse::Client::Http::AsyncResponse.new,
404
+ config: config)
405
+ context[:gem_name] = 'aws-sdk-transcribestreamingservice'
406
+ context[:gem_version] = '1.0.0'
407
+ Seahorse::Client::Request.new(handlers, context)
408
+ end
409
+
410
+ private
411
+
412
+ def _event_stream_handler(type, handler, event_stream_class)
413
+ case handler
414
+ when event_stream_class then handler
415
+ when Proc then event_stream_class.new.tap(&handler)
416
+ when nil then event_stream_class.new
417
+ else
418
+ msg = "expected #{type}_event_stream_handler to be a block or "\
419
+ "instance of Aws::TranscribeStreamingService::#{event_stream_class}"\
420
+ ", got `#{handler.inspect}` instead"
421
+ raise ArgumentError, msg
422
+ end
423
+ end
424
+
425
+ class << self
426
+
427
+ # @api private
428
+ attr_reader :identifier
429
+
430
+ # @api private
431
+ def errors_module
432
+ Errors
433
+ end
434
+
435
+ end
436
+ end
437
+ end