Method: AssemblyAI::Transcripts::TranscriptSentence.from_json

Defined in:
lib/assemblyai/transcripts/types/transcript_sentence.rb

.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