Class: AssemblyAI::Transcripts::TranscriptWord
- Inherits:
-
Object
- Object
- AssemblyAI::Transcripts::TranscriptWord
- Defined in:
- lib/assemblyai/transcripts/types/transcript_word.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#channel ⇒ String
readonly
The channel of the word.
-
#confidence ⇒ Float
readonly
The confidence score for the transcript of this word.
-
#end_ ⇒ Integer
readonly
The ending time, in milliseconds, for the word.
-
#speaker ⇒ String
readonly
The speaker of the word if [Speaker Diarization](www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null.
-
#start ⇒ Integer
readonly
The starting time, in milliseconds, for the word.
-
#text ⇒ String
readonly
The text of the word.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ AssemblyAI::Transcripts::TranscriptWord
Deserialize a JSON object to an instance of TranscriptWord.
-
.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.
Instance Method Summary collapse
- #initialize(confidence:, start:, end_:, text:, channel: OMIT, speaker: OMIT, additional_properties: nil) ⇒ AssemblyAI::Transcripts::TranscriptWord constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of TranscriptWord to a JSON object.
Constructor Details
#initialize(confidence:, start:, end_:, text:, channel: OMIT, speaker: OMIT, additional_properties: nil) ⇒ AssemblyAI::Transcripts::TranscriptWord
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 43 def initialize(confidence:, start:, end_:, text:, channel: OMIT, speaker: OMIT, additional_properties: nil) @confidence = confidence @start = start @end_ = end_ @text = text @channel = channel if channel != OMIT @speaker = speaker if speaker != OMIT @additional_properties = additional_properties @_field_set = { "confidence": confidence, "start": start, "end": end_, "text": text, "channel": channel, "speaker": speaker }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
25 26 27 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 25 def additional_properties @additional_properties end |
#channel ⇒ String (readonly)
Returns The channel of the word. The left and right channels are channels 1 and 2. Additional channels increment the channel number sequentially.
19 20 21 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 19 def channel @channel end |
#confidence ⇒ Float (readonly)
Returns The confidence score for the transcript of this word.
10 11 12 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 10 def confidence @confidence end |
#end_ ⇒ Integer (readonly)
Returns The ending time, in milliseconds, for the word.
14 15 16 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 14 def end_ @end_ end |
#speaker ⇒ String (readonly)
Returns The speaker of the word if [Speaker Diarization](www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null.
23 24 25 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 23 def speaker @speaker end |
#start ⇒ Integer (readonly)
Returns The starting time, in milliseconds, for the word.
12 13 14 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 12 def start @start end |
#text ⇒ String (readonly)
Returns The text of the word.
16 17 18 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 16 def text @text end |
Class Method Details
.from_json(json_object:) ⇒ AssemblyAI::Transcripts::TranscriptWord
Deserialize a JSON object to an instance of TranscriptWord
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 67 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) confidence = struct["confidence"] start = struct["start"] end_ = struct["end"] text = struct["text"] channel = struct["channel"] speaker = struct["speaker"] new( confidence: confidence, start: start, end_: end_, text: text, 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.
99 100 101 102 103 104 105 106 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 99 def self.validate_raw(obj:) obj.confidence.is_a?(Float) != false || raise("Passed value for field obj.confidence 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.text.is_a?(String) != false || raise("Passed value for field obj.text 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 TranscriptWord to a JSON object
89 90 91 |
# File 'lib/assemblyai/transcripts/types/transcript_word.rb', line 89 def to_json(*_args) @_field_set&.to_json end |