Class: AssemblyAI::Transcripts::TranscriptSentence

Inherits:
Object
  • Object
show all
Defined in:
lib/assemblyai/transcripts/types/transcript_sentence.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, start:, end_:, confidence:, words:, channel: OMIT, speaker: OMIT, additional_properties: nil) ⇒ AssemblyAI::Transcripts::TranscriptSentence

Parameters:

  • text (String)

    The transcript of the sentence

  • start (Integer)

    The starting time, in milliseconds, for the sentence

  • end_ (Integer)

    The ending time, in milliseconds, for the sentence

  • confidence (Float)

    The confidence score for the transcript of this sentence

  • words (Array<AssemblyAI::Transcripts::TranscriptWord>)

    An array of words in the sentence

  • channel (String) (defaults to: OMIT)

    The channel of the sentence. The left and right channels are channels 1 and 2. Additional channels increment the channel number sequentially.

  • speaker (String) (defaults to: OMIT)

    The speaker of the sentence if [Speaker Diarization](www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 47

def initialize(text:, start:, end_:, confidence:, words:, channel: OMIT, speaker: OMIT,
               additional_properties: nil)
  @text = text
  @start = start
  @end_ = end_
  @confidence = confidence
  @words = words
  @channel = channel if channel != OMIT
  @speaker = speaker if speaker != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "text": text,
    "start": start,
    "end": end_,
    "confidence": confidence,
    "words": words,
    "channel": channel,
    "speaker": speaker
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



28
29
30
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 28

def additional_properties
  @additional_properties
end

#channelString (readonly)

Returns The channel of the sentence. The left and right channels are channels 1 and 2. Additional channels increment the channel number sequentially.

Returns:

  • (String)

    The channel of the sentence. The left and right channels are channels 1 and 2. Additional channels increment the channel number sequentially.



22
23
24
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 22

def channel
  @channel
end

#confidenceFloat (readonly)

Returns The confidence score for the transcript of this sentence.

Returns:

  • (Float)

    The confidence score for the transcript of this sentence



17
18
19
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 17

def confidence
  @confidence
end

#end_Integer (readonly)

Returns The ending time, in milliseconds, for the sentence.

Returns:

  • (Integer)

    The ending time, in milliseconds, for the sentence



15
16
17
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 15

def end_
  @end_
end

#speakerString (readonly)

Returns The speaker of the sentence if [Speaker Diarization](www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null.

Returns:



26
27
28
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 26

def speaker
  @speaker
end

#startInteger (readonly)

Returns The starting time, in milliseconds, for the sentence.

Returns:

  • (Integer)

    The starting time, in milliseconds, for the sentence



13
14
15
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 13

def start
  @start
end

#textString (readonly)

Returns The transcript of the sentence.

Returns:

  • (String)

    The transcript of the sentence



11
12
13
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 11

def text
  @text
end

#wordsArray<AssemblyAI::Transcripts::TranscriptWord> (readonly)

Returns An array of words in the sentence.

Returns:



19
20
21
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 19

def words
  @words
end

Class Method Details

.from_json(json_object:) ⇒ AssemblyAI::Transcripts::TranscriptSentence

Deserialize a JSON object to an instance of TranscriptSentence

Parameters:

  • json_object (String)

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 74

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  text = struct["text"]
  start = struct["start"]
  end_ = struct["end"]
  confidence = struct["confidence"]
  words = parsed_json["words"]&.map do |v|
    v = v.to_json
    AssemblyAI::Transcripts::TranscriptWord.from_json(json_object: v)
  end
  channel = struct["channel"]
  speaker = struct["speaker"]
  new(
    text: text,
    start: start,
    end_: end_,
    confidence: confidence,
    words: words,
    channel: channel,
    speaker: speaker,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


112
113
114
115
116
117
118
119
120
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 112

def self.validate_raw(obj:)
  obj.text.is_a?(String) != false || raise("Passed value for field obj.text is not the expected type, validation failed.")
  obj.start.is_a?(Integer) != false || raise("Passed value for field obj.start is not the expected type, validation failed.")
  obj.end_.is_a?(Integer) != false || raise("Passed value for field obj.end_ is not the expected type, validation failed.")
  obj.confidence.is_a?(Float) != false || raise("Passed value for field obj.confidence is not the expected type, validation failed.")
  obj.words.is_a?(Array) != false || raise("Passed value for field obj.words is not the expected type, validation failed.")
  obj.channel&.is_a?(String) != false || raise("Passed value for field obj.channel is not the expected type, validation failed.")
  obj.speaker&.is_a?(String) != false || raise("Passed value for field obj.speaker is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of TranscriptSentence to a JSON object

Returns:

  • (String)


102
103
104
# File 'lib/assemblyai/transcripts/types/transcript_sentence.rb', line 102

def to_json(*_args)
  @_field_set&.to_json
end