Class: AssemblyAI::Realtime::FinalTranscript

Inherits:
Object
  • Object
show all
Defined in:
lib/assemblyai/realtime/types/final_transcript.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_type:, punctuated:, text_formatted:, audio_start:, audio_end:, confidence:, text:, words:, created:, additional_properties: nil) ⇒ AssemblyAI::Realtime::FinalTranscript

Parameters:

  • message_type (String)

    Describes the type of message

  • punctuated (Boolean)

    Whether the text is punctuated and cased

  • text_formatted (Boolean)

    Whether the text is formatted, for example Dollar -> $

  • audio_start (Integer)

    Start time of audio sample relative to session start, in milliseconds

  • audio_end (Integer)

    End time of audio sample relative to session start, in milliseconds

  • confidence (Float)

    The confidence score of the entire transcription, between 0 and 1

  • text (String)

    The partial transcript for your audio

  • words (Array<AssemblyAI::Realtime::Word>)

    An array of objects, with the information for each word in the transcription text. Includes the start and end time of the word in milliseconds, the confidence score of the word, and the text, which is the word itself.

  • created (DateTime)

    The timestamp for the partial transcript

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 54

def initialize(message_type:, punctuated:, text_formatted:, audio_start:, audio_end:, confidence:, text:, words:,
               created:, additional_properties: nil)
  @message_type = message_type
  @punctuated = punctuated
  @text_formatted = text_formatted
  @audio_start = audio_start
  @audio_end = audio_end
  @confidence = confidence
  @text = text
  @words = words
  @created = created
  @additional_properties = additional_properties
  @_field_set = {
    "message_type": message_type,
    "punctuated": punctuated,
    "text_formatted": text_formatted,
    "audio_start": audio_start,
    "audio_end": audio_end,
    "confidence": confidence,
    "text": text,
    "words": words,
    "created": created
  }
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



33
34
35
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 33

def additional_properties
  @additional_properties
end

#audio_endInteger (readonly)

Returns End time of audio sample relative to session start, in milliseconds.

Returns:

  • (Integer)

    End time of audio sample relative to session start, in milliseconds



20
21
22
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 20

def audio_end
  @audio_end
end

#audio_startInteger (readonly)

Returns Start time of audio sample relative to session start, in milliseconds.

Returns:

  • (Integer)

    Start time of audio sample relative to session start, in milliseconds



18
19
20
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 18

def audio_start
  @audio_start
end

#confidenceFloat (readonly)

Returns The confidence score of the entire transcription, between 0 and 1.

Returns:

  • (Float)

    The confidence score of the entire transcription, between 0 and 1



22
23
24
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 22

def confidence
  @confidence
end

#createdDateTime (readonly)

Returns The timestamp for the partial transcript.

Returns:

  • (DateTime)

    The timestamp for the partial transcript



31
32
33
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 31

def created
  @created
end

#message_typeString (readonly)

Returns Describes the type of message.

Returns:

  • (String)

    Describes the type of message



12
13
14
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 12

def message_type
  @message_type
end

#punctuatedBoolean (readonly)

Returns Whether the text is punctuated and cased.

Returns:

  • (Boolean)

    Whether the text is punctuated and cased



14
15
16
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 14

def punctuated
  @punctuated
end

#textString (readonly)

Returns The partial transcript for your audio.

Returns:

  • (String)

    The partial transcript for your audio



24
25
26
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 24

def text
  @text
end

#text_formattedBoolean (readonly)

Returns Whether the text is formatted, for example Dollar -> $.

Returns:

  • (Boolean)

    Whether the text is formatted, for example Dollar -> $



16
17
18
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 16

def text_formatted
  @text_formatted
end

#wordsArray<AssemblyAI::Realtime::Word> (readonly)

Returns An array of objects, with the information for each word in the transcription text. Includes the start and end time of the word in milliseconds, the confidence score of the word, and the text, which is the word itself.

Returns:

  • (Array<AssemblyAI::Realtime::Word>)

    An array of objects, with the information for each word in the transcription text. Includes the start and end time of the word in milliseconds, the confidence score of the word, and the text, which is the word itself.



29
30
31
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 29

def words
  @words
end

Class Method Details

.from_json(json_object:) ⇒ AssemblyAI::Realtime::FinalTranscript

Deserialize a JSON object to an instance of FinalTranscript

Parameters:

  • json_object (String)

Returns:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 83

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  message_type = struct["message_type"]
  punctuated = struct["punctuated"]
  text_formatted = struct["text_formatted"]
  audio_start = struct["audio_start"]
  audio_end = struct["audio_end"]
  confidence = struct["confidence"]
  text = struct["text"]
  words = parsed_json["words"]&.map do |v|
    v = v.to_json
    AssemblyAI::Realtime::Word.from_json(json_object: v)
  end
  created = (DateTime.parse(parsed_json["created"]) unless parsed_json["created"].nil?)
  new(
    message_type: message_type,
    punctuated: punctuated,
    text_formatted: text_formatted,
    audio_start: audio_start,
    audio_end: audio_end,
    confidence: confidence,
    text: text,
    words: words,
    created: created,
    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)


125
126
127
128
129
130
131
132
133
134
135
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 125

def self.validate_raw(obj:)
  obj.message_type.is_a?(String) != false || raise("Passed value for field obj.message_type is not the expected type, validation failed.")
  obj.punctuated.is_a?(Boolean) != false || raise("Passed value for field obj.punctuated is not the expected type, validation failed.")
  obj.text_formatted.is_a?(Boolean) != false || raise("Passed value for field obj.text_formatted is not the expected type, validation failed.")
  obj.audio_start.is_a?(Integer) != false || raise("Passed value for field obj.audio_start is not the expected type, validation failed.")
  obj.audio_end.is_a?(Integer) != false || raise("Passed value for field obj.audio_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.text.is_a?(String) != false || raise("Passed value for field obj.text 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.created.is_a?(DateTime) != false || raise("Passed value for field obj.created is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of FinalTranscript to a JSON object

Returns:

  • (String)


115
116
117
# File 'lib/assemblyai/realtime/types/final_transcript.rb', line 115

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