class AzureSTT::Session
A session is the class the end user uses to retrieve the Transcription. It contains a client.
Attributes
Public Class Methods
Create a session. If you don't provide any subscription_key or region, the value is read from configuration.
@param [String] region The region, optional, default is read from configuration @param [String] subscription_key The subscription, optional, default is read from configuration
# File lib/azure_stt/session.rb, line 20 def initialize(region: AzureSTT.configuration.region, subscription_key: AzureSTT.configuration.subscription_key) @client = Client.new(region: region, subscription_key: subscription_key) end
Public Instance Methods
Create a transcription by calling the API.
@param [Array] content_urls The urls of your files @param [Hash] properties The properties you want to use for the transcription @param [String] locale The locale of the contained data @param [String] display_name The name of the transcription (can be left empty)
@return [Models::Transcription] The transcription
# File lib/azure_stt/session.rb, line 39 def create_transcription(content_urls:, properties:, locale:, display_name:) transcription_hash = client.create_transcription( { contentUrls: content_urls, properties: properties, locale: locale, displayName: display_name } ) build_transcription_from_hash(transcription_hash) end
Delete an API transcription with a given ID. The transcription will not exist anymore in the API, therefore you won't be able to retrieve it.
@param [String] id The id of the transcription in the API
@return [Boolean] true if the transcription had been deleted, raises an error else
# File lib/azure_stt/session.rb, line 94 def delete_transcription(id) client.delete_transcription(id) end
Get a transcription identified by an id.
@param [String] id The identifier of the transcription
@return [Models::Transcription] the transcription
# File lib/azure_stt/session.rb, line 60 def get_transcription(id) transcription_hash = client.get_transcription(id) build_transcription_from_hash(transcription_hash) end
Get multiple transcriptions.
@param [Integer] skip Number of transcriptions that will be skipped (optional) @param [Integer] top Number of transcriptions that will be included after skipping (optional)
@return [Array]
# File lib/azure_stt/session.rb, line 76 def get_transcriptions(skip: nil, top: nil) transcriptions_array = client.get_transcriptions(skip: skip, top: top) transcriptions_array.map do |transcription_hash| build_transcription_from_hash(transcription_hash) end end
Private Instance Methods
Build a transcription from a hash returned by the client. This hash contains the information from the JSON. It is then parsed and the transcription is intantiated.
@param [Hash] hash The hash that the client returned
@return [Models::Transcription] the created transcription
# File lib/azure_stt/session.rb, line 109 def build_transcription_from_hash(hash) Models::Transcription.new( Parsers::Transcription.new(hash).attributes.merge({ client: client }) ) end