class AzureSTT::Session

A session is the class the end user uses to retrieve the Transcription. It contains a client.

Attributes

client[R]

Public Class Methods

new(region: AzureSTT.configuration.region, subscription_key: AzureSTT.configuration.subscription_key) click to toggle source

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_transcription(content_urls:, properties:, locale:, display_name:) click to toggle source

Create a transcription by calling the API.

@see centralus.dev.cognitive.microsoft.com/docs/services/speech-to-text-api-v3-0/operations/CreateTranscription

@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_transcription(id) click to toggle source

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.

@see westus.dev.cognitive.microsoft.com/docs/services/speech-to-text-api-v3-0/operations/DeleteTranscription

@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_transcription(id) click to toggle source

Get a transcription identified by an id.

@see centralus.dev.cognitive.microsoft.com/docs/services/speech-to-text-api-v3-0/operations/GetTranscription

@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_transcriptions(skip: nil, top: nil) click to toggle source

Get multiple transcriptions.

@see centralus.dev.cognitive.microsoft.com/docs/services/speech-to-text-api-v3-0/operations/GetTranscriptions

@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_transcription_from_hash(hash) click to toggle source

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