Class: AssemblyAI::Realtime::RealtimeBaseTranscript
- Inherits:
-
Object
- Object
- AssemblyAI::Realtime::RealtimeBaseTranscript
- Defined in:
- lib/assemblyai/realtime/types/realtime_base_transcript.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#audio_end ⇒ Integer
readonly
End time of audio sample relative to session start, in milliseconds.
-
#audio_start ⇒ Integer
readonly
Start time of audio sample relative to session start, in milliseconds.
-
#confidence ⇒ Float
readonly
The confidence score of the entire transcription, between 0 and 1.
-
#created ⇒ DateTime
readonly
The timestamp for the partial transcript.
-
#text ⇒ String
readonly
The partial transcript for your audio.
-
#words ⇒ Array<AssemblyAI::Realtime::Word>
readonly
An array of objects, with the information for each word in the transcription text.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ AssemblyAI::Realtime::RealtimeBaseTranscript
Deserialize a JSON object to an instance of RealtimeBaseTranscript.
-
.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(audio_start:, audio_end:, confidence:, text:, words:, created:, additional_properties: nil) ⇒ AssemblyAI::Realtime::RealtimeBaseTranscript constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of RealtimeBaseTranscript to a JSON object.
Constructor Details
#initialize(audio_start:, audio_end:, confidence:, text:, words:, created:, additional_properties: nil) ⇒ AssemblyAI::Realtime::RealtimeBaseTranscript
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 45 def initialize(audio_start:, audio_end:, confidence:, text:, words:, created:, additional_properties: nil) @audio_start = audio_start @audio_end = audio_end @confidence = confidence @text = text @words = words @created = created @additional_properties = additional_properties @_field_set = { "audio_start": audio_start, "audio_end": audio_end, "confidence": confidence, "text": text, "words": words, "created": created } end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
27 28 29 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 27 def additional_properties @additional_properties end |
#audio_end ⇒ Integer (readonly)
Returns End time of audio sample relative to session start, in milliseconds.
14 15 16 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 14 def audio_end @audio_end end |
#audio_start ⇒ Integer (readonly)
Returns Start time of audio sample relative to session start, in milliseconds.
12 13 14 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 12 def audio_start @audio_start end |
#confidence ⇒ Float (readonly)
Returns The confidence score of the entire transcription, between 0 and 1.
16 17 18 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 16 def confidence @confidence end |
#created ⇒ DateTime (readonly)
Returns The timestamp for the partial transcript.
25 26 27 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 25 def created @created end |
#text ⇒ String (readonly)
Returns The partial transcript for your audio.
18 19 20 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 18 def text @text end |
#words ⇒ Array<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.
23 24 25 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 23 def words @words end |
Class Method Details
.from_json(json_object:) ⇒ AssemblyAI::Realtime::RealtimeBaseTranscript
Deserialize a JSON object to an instance of RealtimeBaseTranscript
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 67 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) 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( 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.
103 104 105 106 107 108 109 110 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 103 def self.validate_raw(obj:) 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 RealtimeBaseTranscript to a JSON object
93 94 95 |
# File 'lib/assemblyai/realtime/types/realtime_base_transcript.rb', line 93 def to_json(*_args) @_field_set&.to_json end |