Sha256: c7509efd34c2f8c1aa4cb17f5d66f07858bb579b8e35162761c2436c4d4bea77

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module AzureSTT
  module Parsers
    #
    # Parse a recognized phrase from a result file to Models::RecognizedPhrase
    #
    class RecognizedPhrase < Base
      protected

      #
      # Build a hash to instantiate a Models::RecognizedPhrase
      #
      # @return [Hash]
      #
      def build_attributes
        {
          recognition_status: hash['recognitionStatus'],
          channel: hash['channel'],
          speaker: hash['speaker'],
          offset: hash['offset'],
          duration: hash['duration'],
          offset_in_ticks: hash['offsetInTicks'],
          duration_in_ticks: hash['durationInTicks'],
          n_best: build_n_best
        }.compact
      end

      private

      #
      # Build the n_best fiels if the RecognizedPhrase.
      #
      # @return [Array[Models::Sentence]]
      #
      def build_n_best
        hash['nBest'].map do |sentence_hash|
          Models::Sentence.new(
            Sentence.new(sentence_hash).attributes
          )
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
azure_stt-0.4.0 lib/azure_stt/parsers/recognized_phrase.rb
azure_stt-0.3.0 lib/azure_stt/parsers/recognized_phrase.rb
azure_stt-0.2.0 lib/azure_stt/parsers/recognized_phrase.rb
azure_stt-0.1.1 lib/azure_stt/parsers/recognized_phrase.rb
azure_stt-0.1.0 lib/azure_stt/parsers/recognized_phrase.rb