assemblyai 1.0.0.pre.beta.7 → 1.0.0.pre.beta.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/lib/assemblyai/files/client.rb +4 -2
  3. data/lib/assemblyai/files/types/uploaded_file.rb +20 -11
  4. data/lib/assemblyai/lemur/client.rb +256 -150
  5. data/lib/assemblyai/lemur/types/lemur_action_items_response.rb +28 -14
  6. data/lib/assemblyai/lemur/types/lemur_base_params.rb +83 -54
  7. data/lib/assemblyai/lemur/types/lemur_base_params_context.rb +11 -5
  8. data/lib/assemblyai/lemur/types/lemur_base_response.rb +20 -11
  9. data/lib/assemblyai/lemur/types/lemur_question.rb +57 -31
  10. data/lib/assemblyai/lemur/types/lemur_question_answer.rb +28 -14
  11. data/lib/assemblyai/lemur/types/lemur_question_answer_response.rb +29 -14
  12. data/lib/assemblyai/lemur/types/lemur_question_context.rb +13 -6
  13. data/lib/assemblyai/lemur/types/lemur_summary_response.rb +28 -14
  14. data/lib/assemblyai/lemur/types/lemur_task_response.rb +28 -14
  15. data/lib/assemblyai/lemur/types/purge_lemur_request_data_response.rb +32 -17
  16. data/lib/assemblyai/realtime/client.rb +30 -14
  17. data/lib/assemblyai/realtime/types/configure_end_utterance_silence_threshold.rb +24 -13
  18. data/lib/assemblyai/realtime/types/final_transcript.rb +72 -41
  19. data/lib/assemblyai/realtime/types/force_end_utterance.rb +20 -11
  20. data/lib/assemblyai/realtime/types/message_type.rb +1 -0
  21. data/lib/assemblyai/realtime/types/partial_transcript.rb +62 -34
  22. data/lib/assemblyai/realtime/types/realtime_base_message.rb +22 -13
  23. data/lib/assemblyai/realtime/types/realtime_base_transcript.rb +57 -31
  24. data/lib/assemblyai/realtime/types/realtime_error.rb +20 -11
  25. data/lib/assemblyai/realtime/types/realtime_message.rb +44 -18
  26. data/lib/assemblyai/realtime/types/realtime_temporary_token_response.rb +20 -11
  27. data/lib/assemblyai/realtime/types/realtime_transcript.rb +15 -9
  28. data/lib/assemblyai/realtime/types/session_begins.rb +31 -14
  29. data/lib/assemblyai/realtime/types/session_information.rb +69 -0
  30. data/lib/assemblyai/realtime/types/session_terminated.rb +20 -11
  31. data/lib/assemblyai/realtime/types/terminate_session.rb +20 -11
  32. data/lib/assemblyai/realtime/types/word.rb +36 -18
  33. data/lib/assemblyai/streaming/types/receive_message.rb +113 -0
  34. data/lib/assemblyai/{realtime → streaming}/types/send_message.rb +26 -14
  35. data/lib/assemblyai/streaming/types/streaming.rb +11 -0
  36. data/lib/assemblyai/transcripts/client.rb +50 -18
  37. data/lib/assemblyai/transcripts/list_by_url_client.rb +6 -4
  38. data/lib/assemblyai/transcripts/polling_client.rb +12 -2
  39. data/lib/assemblyai/transcripts/types/auto_highlight_result.rb +40 -19
  40. data/lib/assemblyai/transcripts/types/auto_highlights_result.rb +38 -14
  41. data/lib/assemblyai/transcripts/types/chapter.rb +40 -20
  42. data/lib/assemblyai/transcripts/types/content_safety_label.rb +32 -16
  43. data/lib/assemblyai/transcripts/types/content_safety_label_result.rb +51 -29
  44. data/lib/assemblyai/transcripts/types/content_safety_labels_result.rb +51 -29
  45. data/lib/assemblyai/transcripts/types/entity.rb +41 -21
  46. data/lib/assemblyai/transcripts/types/page_details.rb +59 -33
  47. data/lib/assemblyai/transcripts/types/paragraphs_response.rb +37 -19
  48. data/lib/assemblyai/transcripts/types/redact_pii_audio_quality.rb +4 -1
  49. data/lib/assemblyai/transcripts/types/redacted_audio_response.rb +29 -15
  50. data/lib/assemblyai/transcripts/types/sentences_response.rb +37 -19
  51. data/lib/assemblyai/transcripts/types/sentiment_analysis_result.rb +62 -35
  52. data/lib/assemblyai/transcripts/types/severity_score_summary.rb +32 -16
  53. data/lib/assemblyai/transcripts/types/speech_model.rb +1 -0
  54. data/lib/assemblyai/transcripts/types/substitution_policy.rb +3 -1
  55. data/lib/assemblyai/transcripts/types/timestamp.rb +28 -14
  56. data/lib/assemblyai/transcripts/types/topic_detection_model_result.rb +39 -19
  57. data/lib/assemblyai/transcripts/types/topic_detection_result.rb +40 -21
  58. data/lib/assemblyai/transcripts/types/topic_detection_result_labels_item.rb +31 -15
  59. data/lib/assemblyai/transcripts/types/transcript.rb +512 -293
  60. data/lib/assemblyai/transcripts/types/transcript_custom_spelling.rb +30 -15
  61. data/lib/assemblyai/transcripts/types/transcript_language_code.rb +3 -2
  62. data/lib/assemblyai/transcripts/types/transcript_list.rb +33 -17
  63. data/lib/assemblyai/transcripts/types/transcript_list_item.rb +60 -34
  64. data/lib/assemblyai/transcripts/types/transcript_optional_params.rb +334 -191
  65. data/lib/assemblyai/transcripts/types/transcript_paragraph.rb +61 -33
  66. data/lib/assemblyai/transcripts/types/transcript_ready_notification.rb +30 -16
  67. data/lib/assemblyai/transcripts/types/transcript_sentence.rb +61 -33
  68. data/lib/assemblyai/transcripts/types/transcript_status.rb +2 -1
  69. data/lib/assemblyai/transcripts/types/transcript_utterance.rb +55 -31
  70. data/lib/assemblyai/transcripts/types/transcript_word.rb +55 -24
  71. data/lib/assemblyai/transcripts/types/word_search_match.rb +40 -20
  72. data/lib/assemblyai/transcripts/types/word_search_response.rb +36 -17
  73. data/lib/assemblyai/types/error.rb +32 -16
  74. data/lib/requests.rb +80 -34
  75. data/lib/types_export.rb +4 -3
  76. metadata +6 -5
  77. data/lib/assemblyai/realtime/types/audio_data.rb +0 -7
  78. data/lib/assemblyai/realtime/types/receive_message.rb +0 -87
@@ -1,73 +1,101 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "transcript_word"
4
+ require "ostruct"
4
5
  require "json"
5
6
 
6
7
  module AssemblyAI
7
8
  class Transcripts
8
9
  class TranscriptParagraph
9
- attr_reader :text, :start, :end_, :confidence, :words, :speaker, :additional_properties
10
+ # @return [String]
11
+ attr_reader :text
12
+ # @return [Integer]
13
+ attr_reader :start
14
+ # @return [Integer]
15
+ attr_reader :end_
16
+ # @return [Float]
17
+ attr_reader :confidence
18
+ # @return [Array<AssemblyAI::Transcripts::TranscriptWord>]
19
+ attr_reader :words
20
+ # @return [String] The speaker of the sentence if [Speaker
21
+ # Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is
22
+ # enabled, else null
23
+ attr_reader :speaker
24
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
25
+ attr_reader :additional_properties
26
+ # @return [Object]
27
+ attr_reader :_field_set
28
+ protected :_field_set
29
+
30
+ OMIT = Object.new
10
31
 
11
32
  # @param text [String]
12
33
  # @param start [Integer]
13
34
  # @param end_ [Integer]
14
35
  # @param confidence [Float]
15
- # @param words [Array<Transcripts::TranscriptWord>]
16
- # @param speaker [String] The speaker of the sentence if [Speaker Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null
36
+ # @param words [Array<AssemblyAI::Transcripts::TranscriptWord>]
37
+ # @param speaker [String] The speaker of the sentence if [Speaker
38
+ # Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is
39
+ # enabled, else null
17
40
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
18
- # @return [Transcripts::TranscriptParagraph]
19
- def initialize(text:, start:, end_:, confidence:, words:, speaker: nil, additional_properties: nil)
20
- # @type [String]
41
+ # @return [AssemblyAI::Transcripts::TranscriptParagraph]
42
+ def initialize(text:, start:, end_:, confidence:, words:, speaker: OMIT, additional_properties: nil)
21
43
  @text = text
22
- # @type [Integer]
23
44
  @start = start
24
- # @type [Integer]
25
45
  @end_ = end_
26
- # @type [Float]
27
46
  @confidence = confidence
28
- # @type [Array<Transcripts::TranscriptWord>]
29
47
  @words = words
30
- # @type [String] The speaker of the sentence if [Speaker Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null
31
- @speaker = speaker
32
- # @type [OpenStruct] Additional properties unmapped to the current class definition
48
+ @speaker = speaker if speaker != OMIT
33
49
  @additional_properties = additional_properties
50
+ @_field_set = {
51
+ "text": text,
52
+ "start": start,
53
+ "end": end_,
54
+ "confidence": confidence,
55
+ "words": words,
56
+ "speaker": speaker
57
+ }.reject do |_k, v|
58
+ v == OMIT
59
+ end
34
60
  end
35
61
 
36
62
  # Deserialize a JSON object to an instance of TranscriptParagraph
37
63
  #
38
- # @param json_object [JSON]
39
- # @return [Transcripts::TranscriptParagraph]
64
+ # @param json_object [String]
65
+ # @return [AssemblyAI::Transcripts::TranscriptParagraph]
40
66
  def self.from_json(json_object:)
41
67
  struct = JSON.parse(json_object, object_class: OpenStruct)
42
68
  parsed_json = JSON.parse(json_object)
43
- text = struct.text
44
- start = struct.start
45
- end_ = struct.end
46
- confidence = struct.confidence
69
+ text = struct["text"]
70
+ start = struct["start"]
71
+ end_ = struct["end"]
72
+ confidence = struct["confidence"]
47
73
  words = parsed_json["words"]&.map do |v|
48
74
  v = v.to_json
49
- Transcripts::TranscriptWord.from_json(json_object: v)
75
+ AssemblyAI::Transcripts::TranscriptWord.from_json(json_object: v)
50
76
  end
51
- speaker = struct.speaker
52
- new(text: text, start: start, end_: end_, confidence: confidence, words: words, speaker: speaker,
53
- additional_properties: struct)
77
+ speaker = struct["speaker"]
78
+ new(
79
+ text: text,
80
+ start: start,
81
+ end_: end_,
82
+ confidence: confidence,
83
+ words: words,
84
+ speaker: speaker,
85
+ additional_properties: struct
86
+ )
54
87
  end
55
88
 
56
89
  # Serialize an instance of TranscriptParagraph to a JSON object
57
90
  #
58
- # @return [JSON]
91
+ # @return [String]
59
92
  def to_json(*_args)
60
- {
61
- "text": @text,
62
- "start": @start,
63
- "end": @end_,
64
- "confidence": @confidence,
65
- "words": @words,
66
- "speaker": @speaker
67
- }.to_json
93
+ @_field_set&.to_json
68
94
  end
69
95
 
70
- # 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.
96
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
97
+ # hash and check each fields type against the current object's property
98
+ # definitions.
71
99
  #
72
100
  # @param obj [Object]
73
101
  # @return [Void]
@@ -1,53 +1,67 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "transcript_ready_status"
4
+ require "ostruct"
4
5
  require "json"
5
6
 
6
7
  module AssemblyAI
7
8
  class Transcripts
8
9
  # The notification when the transcript status is completed or error.
9
10
  class TranscriptReadyNotification
10
- attr_reader :transcript_id, :status, :additional_properties
11
+ # @return [String] The ID of the transcript
12
+ attr_reader :transcript_id
13
+ # @return [AssemblyAI::Transcripts::TranscriptReadyStatus] The status of the transcript. Either completed or error.
14
+ attr_reader :status
15
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
16
+ attr_reader :additional_properties
17
+ # @return [Object]
18
+ attr_reader :_field_set
19
+ protected :_field_set
20
+
21
+ OMIT = Object.new
11
22
 
12
23
  # @param transcript_id [String] The ID of the transcript
13
- # @param status [Transcripts::TranscriptReadyStatus] The status of the transcript. Either completed or error.
24
+ # @param status [AssemblyAI::Transcripts::TranscriptReadyStatus] The status of the transcript. Either completed or error.
14
25
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
15
- # @return [Transcripts::TranscriptReadyNotification]
26
+ # @return [AssemblyAI::Transcripts::TranscriptReadyNotification]
16
27
  def initialize(transcript_id:, status:, additional_properties: nil)
17
- # @type [String] The ID of the transcript
18
28
  @transcript_id = transcript_id
19
- # @type [Transcripts::TranscriptReadyStatus] The status of the transcript. Either completed or error.
20
29
  @status = status
21
- # @type [OpenStruct] Additional properties unmapped to the current class definition
22
30
  @additional_properties = additional_properties
31
+ @_field_set = { "transcript_id": transcript_id, "status": status }
23
32
  end
24
33
 
25
34
  # Deserialize a JSON object to an instance of TranscriptReadyNotification
26
35
  #
27
- # @param json_object [JSON]
28
- # @return [Transcripts::TranscriptReadyNotification]
36
+ # @param json_object [String]
37
+ # @return [AssemblyAI::Transcripts::TranscriptReadyNotification]
29
38
  def self.from_json(json_object:)
30
39
  struct = JSON.parse(json_object, object_class: OpenStruct)
31
- JSON.parse(json_object)
32
- transcript_id = struct.transcript_id
33
- status = struct.status
34
- new(transcript_id: transcript_id, status: status, additional_properties: struct)
40
+ transcript_id = struct["transcript_id"]
41
+ status = struct["status"]
42
+ new(
43
+ transcript_id: transcript_id,
44
+ status: status,
45
+ additional_properties: struct
46
+ )
35
47
  end
36
48
 
37
49
  # Serialize an instance of TranscriptReadyNotification to a JSON object
38
50
  #
39
- # @return [JSON]
51
+ # @return [String]
40
52
  def to_json(*_args)
41
- { "transcript_id": @transcript_id, "status": @status }.to_json
53
+ @_field_set&.to_json
42
54
  end
43
55
 
44
- # 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.
56
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
57
+ # hash and check each fields type against the current object's property
58
+ # definitions.
45
59
  #
46
60
  # @param obj [Object]
47
61
  # @return [Void]
48
62
  def self.validate_raw(obj:)
49
63
  obj.transcript_id.is_a?(String) != false || raise("Passed value for field obj.transcript_id is not the expected type, validation failed.")
50
- obj.status.is_a?(Transcripts::TranscriptReadyStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
64
+ obj.status.is_a?(AssemblyAI::Transcripts::TranscriptReadyStatus) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
51
65
  end
52
66
  end
53
67
  end
@@ -1,73 +1,101 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "transcript_word"
4
+ require "ostruct"
4
5
  require "json"
5
6
 
6
7
  module AssemblyAI
7
8
  class Transcripts
8
9
  class TranscriptSentence
9
- attr_reader :text, :start, :end_, :confidence, :words, :speaker, :additional_properties
10
+ # @return [String]
11
+ attr_reader :text
12
+ # @return [Integer]
13
+ attr_reader :start
14
+ # @return [Integer]
15
+ attr_reader :end_
16
+ # @return [Float]
17
+ attr_reader :confidence
18
+ # @return [Array<AssemblyAI::Transcripts::TranscriptWord>]
19
+ attr_reader :words
20
+ # @return [String] The speaker of the sentence if [Speaker
21
+ # Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is
22
+ # enabled, else null
23
+ attr_reader :speaker
24
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
25
+ attr_reader :additional_properties
26
+ # @return [Object]
27
+ attr_reader :_field_set
28
+ protected :_field_set
29
+
30
+ OMIT = Object.new
10
31
 
11
32
  # @param text [String]
12
33
  # @param start [Integer]
13
34
  # @param end_ [Integer]
14
35
  # @param confidence [Float]
15
- # @param words [Array<Transcripts::TranscriptWord>]
16
- # @param speaker [String] The speaker of the sentence if [Speaker Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null
36
+ # @param words [Array<AssemblyAI::Transcripts::TranscriptWord>]
37
+ # @param speaker [String] The speaker of the sentence if [Speaker
38
+ # Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is
39
+ # enabled, else null
17
40
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
18
- # @return [Transcripts::TranscriptSentence]
19
- def initialize(text:, start:, end_:, confidence:, words:, speaker: nil, additional_properties: nil)
20
- # @type [String]
41
+ # @return [AssemblyAI::Transcripts::TranscriptSentence]
42
+ def initialize(text:, start:, end_:, confidence:, words:, speaker: OMIT, additional_properties: nil)
21
43
  @text = text
22
- # @type [Integer]
23
44
  @start = start
24
- # @type [Integer]
25
45
  @end_ = end_
26
- # @type [Float]
27
46
  @confidence = confidence
28
- # @type [Array<Transcripts::TranscriptWord>]
29
47
  @words = words
30
- # @type [String] The speaker of the sentence if [Speaker Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null
31
- @speaker = speaker
32
- # @type [OpenStruct] Additional properties unmapped to the current class definition
48
+ @speaker = speaker if speaker != OMIT
33
49
  @additional_properties = additional_properties
50
+ @_field_set = {
51
+ "text": text,
52
+ "start": start,
53
+ "end": end_,
54
+ "confidence": confidence,
55
+ "words": words,
56
+ "speaker": speaker
57
+ }.reject do |_k, v|
58
+ v == OMIT
59
+ end
34
60
  end
35
61
 
36
62
  # Deserialize a JSON object to an instance of TranscriptSentence
37
63
  #
38
- # @param json_object [JSON]
39
- # @return [Transcripts::TranscriptSentence]
64
+ # @param json_object [String]
65
+ # @return [AssemblyAI::Transcripts::TranscriptSentence]
40
66
  def self.from_json(json_object:)
41
67
  struct = JSON.parse(json_object, object_class: OpenStruct)
42
68
  parsed_json = JSON.parse(json_object)
43
- text = struct.text
44
- start = struct.start
45
- end_ = struct.end
46
- confidence = struct.confidence
69
+ text = struct["text"]
70
+ start = struct["start"]
71
+ end_ = struct["end"]
72
+ confidence = struct["confidence"]
47
73
  words = parsed_json["words"]&.map do |v|
48
74
  v = v.to_json
49
- Transcripts::TranscriptWord.from_json(json_object: v)
75
+ AssemblyAI::Transcripts::TranscriptWord.from_json(json_object: v)
50
76
  end
51
- speaker = struct.speaker
52
- new(text: text, start: start, end_: end_, confidence: confidence, words: words, speaker: speaker,
53
- additional_properties: struct)
77
+ speaker = struct["speaker"]
78
+ new(
79
+ text: text,
80
+ start: start,
81
+ end_: end_,
82
+ confidence: confidence,
83
+ words: words,
84
+ speaker: speaker,
85
+ additional_properties: struct
86
+ )
54
87
  end
55
88
 
56
89
  # Serialize an instance of TranscriptSentence to a JSON object
57
90
  #
58
- # @return [JSON]
91
+ # @return [String]
59
92
  def to_json(*_args)
60
- {
61
- "text": @text,
62
- "start": @start,
63
- "end": @end_,
64
- "confidence": @confidence,
65
- "words": @words,
66
- "speaker": @speaker
67
- }.to_json
93
+ @_field_set&.to_json
68
94
  end
69
95
 
70
- # 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.
96
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
97
+ # hash and check each fields type against the current object's property
98
+ # definitions.
71
99
  #
72
100
  # @param obj [Object]
73
101
  # @return [Void]
@@ -2,7 +2,8 @@
2
2
 
3
3
  module AssemblyAI
4
4
  class Transcripts
5
- # The status of your transcript. Possible values are queued, processing, completed, or error.
5
+ # The status of your transcript. Possible values are queued, processing,
6
+ # completed, or error.
6
7
  class TranscriptStatus
7
8
  QUEUED = "queued"
8
9
  PROCESSING = "processing"
@@ -1,73 +1,97 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "transcript_word"
4
+ require "ostruct"
4
5
  require "json"
5
6
 
6
7
  module AssemblyAI
7
8
  class Transcripts
8
9
  class TranscriptUtterance
9
- attr_reader :confidence, :start, :end_, :text, :words, :speaker, :additional_properties
10
+ # @return [Float] The confidence score for the transcript of this utterance
11
+ attr_reader :confidence
12
+ # @return [Integer] The starting time, in milliseconds, of the utterance in the audio file
13
+ attr_reader :start
14
+ # @return [Integer] The ending time, in milliseconds, of the utterance in the audio file
15
+ attr_reader :end_
16
+ # @return [String] The text for this utterance
17
+ attr_reader :text
18
+ # @return [Array<AssemblyAI::Transcripts::TranscriptWord>] The words in the utterance.
19
+ attr_reader :words
20
+ # @return [String] The speaker of this utterance, where each speaker is assigned a sequential
21
+ # capital letter - e.g. "A" for Speaker A, "B" for Speaker B, etc.
22
+ attr_reader :speaker
23
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
24
+ attr_reader :additional_properties
25
+ # @return [Object]
26
+ attr_reader :_field_set
27
+ protected :_field_set
28
+
29
+ OMIT = Object.new
10
30
 
11
31
  # @param confidence [Float] The confidence score for the transcript of this utterance
12
32
  # @param start [Integer] The starting time, in milliseconds, of the utterance in the audio file
13
33
  # @param end_ [Integer] The ending time, in milliseconds, of the utterance in the audio file
14
34
  # @param text [String] The text for this utterance
15
- # @param words [Array<Transcripts::TranscriptWord>] The words in the utterance.
16
- # @param speaker [String] The speaker of this utterance, where each speaker is assigned a sequential capital letter - e.g. "A" for Speaker A, "B" for Speaker B, etc.
35
+ # @param words [Array<AssemblyAI::Transcripts::TranscriptWord>] The words in the utterance.
36
+ # @param speaker [String] The speaker of this utterance, where each speaker is assigned a sequential
37
+ # capital letter - e.g. "A" for Speaker A, "B" for Speaker B, etc.
17
38
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
18
- # @return [Transcripts::TranscriptUtterance]
39
+ # @return [AssemblyAI::Transcripts::TranscriptUtterance]
19
40
  def initialize(confidence:, start:, end_:, text:, words:, speaker:, additional_properties: nil)
20
- # @type [Float] The confidence score for the transcript of this utterance
21
41
  @confidence = confidence
22
- # @type [Integer] The starting time, in milliseconds, of the utterance in the audio file
23
42
  @start = start
24
- # @type [Integer] The ending time, in milliseconds, of the utterance in the audio file
25
43
  @end_ = end_
26
- # @type [String] The text for this utterance
27
44
  @text = text
28
- # @type [Array<Transcripts::TranscriptWord>] The words in the utterance.
29
45
  @words = words
30
- # @type [String] The speaker of this utterance, where each speaker is assigned a sequential capital letter - e.g. "A" for Speaker A, "B" for Speaker B, etc.
31
46
  @speaker = speaker
32
- # @type [OpenStruct] Additional properties unmapped to the current class definition
33
47
  @additional_properties = additional_properties
48
+ @_field_set = {
49
+ "confidence": confidence,
50
+ "start": start,
51
+ "end": end_,
52
+ "text": text,
53
+ "words": words,
54
+ "speaker": speaker
55
+ }
34
56
  end
35
57
 
36
58
  # Deserialize a JSON object to an instance of TranscriptUtterance
37
59
  #
38
- # @param json_object [JSON]
39
- # @return [Transcripts::TranscriptUtterance]
60
+ # @param json_object [String]
61
+ # @return [AssemblyAI::Transcripts::TranscriptUtterance]
40
62
  def self.from_json(json_object:)
41
63
  struct = JSON.parse(json_object, object_class: OpenStruct)
42
64
  parsed_json = JSON.parse(json_object)
43
- confidence = struct.confidence
44
- start = struct.start
45
- end_ = struct.end
46
- text = struct.text
65
+ confidence = struct["confidence"]
66
+ start = struct["start"]
67
+ end_ = struct["end"]
68
+ text = struct["text"]
47
69
  words = parsed_json["words"]&.map do |v|
48
70
  v = v.to_json
49
- Transcripts::TranscriptWord.from_json(json_object: v)
71
+ AssemblyAI::Transcripts::TranscriptWord.from_json(json_object: v)
50
72
  end
51
- speaker = struct.speaker
52
- new(confidence: confidence, start: start, end_: end_, text: text, words: words, speaker: speaker,
53
- additional_properties: struct)
73
+ speaker = struct["speaker"]
74
+ new(
75
+ confidence: confidence,
76
+ start: start,
77
+ end_: end_,
78
+ text: text,
79
+ words: words,
80
+ speaker: speaker,
81
+ additional_properties: struct
82
+ )
54
83
  end
55
84
 
56
85
  # Serialize an instance of TranscriptUtterance to a JSON object
57
86
  #
58
- # @return [JSON]
87
+ # @return [String]
59
88
  def to_json(*_args)
60
- {
61
- "confidence": @confidence,
62
- "start": @start,
63
- "end": @end_,
64
- "text": @text,
65
- "words": @words,
66
- "speaker": @speaker
67
- }.to_json
89
+ @_field_set&.to_json
68
90
  end
69
91
 
70
- # 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.
92
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
93
+ # hash and check each fields type against the current object's property
94
+ # definitions.
71
95
  #
72
96
  # @param obj [Object]
73
97
  # @return [Void]
@@ -1,58 +1,89 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ostruct"
3
4
  require "json"
4
5
 
5
6
  module AssemblyAI
6
7
  class Transcripts
7
8
  class TranscriptWord
8
- attr_reader :confidence, :start, :end_, :text, :speaker, :additional_properties
9
+ # @return [Float]
10
+ attr_reader :confidence
11
+ # @return [Integer]
12
+ attr_reader :start
13
+ # @return [Integer]
14
+ attr_reader :end_
15
+ # @return [String]
16
+ attr_reader :text
17
+ # @return [String] The speaker of the sentence if [Speaker
18
+ # Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is
19
+ # enabled, else null
20
+ attr_reader :speaker
21
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
22
+ attr_reader :additional_properties
23
+ # @return [Object]
24
+ attr_reader :_field_set
25
+ protected :_field_set
26
+
27
+ OMIT = Object.new
9
28
 
10
29
  # @param confidence [Float]
11
30
  # @param start [Integer]
12
31
  # @param end_ [Integer]
13
32
  # @param text [String]
14
- # @param speaker [String] The speaker of the sentence if [Speaker Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null
33
+ # @param speaker [String] The speaker of the sentence if [Speaker
34
+ # Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is
35
+ # enabled, else null
15
36
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
16
- # @return [Transcripts::TranscriptWord]
17
- def initialize(confidence:, start:, end_:, text:, speaker: nil, additional_properties: nil)
18
- # @type [Float]
37
+ # @return [AssemblyAI::Transcripts::TranscriptWord]
38
+ def initialize(confidence:, start:, end_:, text:, speaker: OMIT, additional_properties: nil)
19
39
  @confidence = confidence
20
- # @type [Integer]
21
40
  @start = start
22
- # @type [Integer]
23
41
  @end_ = end_
24
- # @type [String]
25
42
  @text = text
26
- # @type [String] The speaker of the sentence if [Speaker Diarization](https://www.assemblyai.com/docs/models/speaker-diarization) is enabled, else null
27
- @speaker = speaker
28
- # @type [OpenStruct] Additional properties unmapped to the current class definition
43
+ @speaker = speaker if speaker != OMIT
29
44
  @additional_properties = additional_properties
45
+ @_field_set = {
46
+ "confidence": confidence,
47
+ "start": start,
48
+ "end": end_,
49
+ "text": text,
50
+ "speaker": speaker
51
+ }.reject do |_k, v|
52
+ v == OMIT
53
+ end
30
54
  end
31
55
 
32
56
  # Deserialize a JSON object to an instance of TranscriptWord
33
57
  #
34
- # @param json_object [JSON]
35
- # @return [Transcripts::TranscriptWord]
58
+ # @param json_object [String]
59
+ # @return [AssemblyAI::Transcripts::TranscriptWord]
36
60
  def self.from_json(json_object:)
37
61
  struct = JSON.parse(json_object, object_class: OpenStruct)
38
- JSON.parse(json_object)
39
- confidence = struct.confidence
40
- start = struct.start
41
- end_ = struct.end
42
- text = struct.text
43
- speaker = struct.speaker
44
- new(confidence: confidence, start: start, end_: end_, text: text, speaker: speaker,
45
- additional_properties: struct)
62
+ confidence = struct["confidence"]
63
+ start = struct["start"]
64
+ end_ = struct["end"]
65
+ text = struct["text"]
66
+ speaker = struct["speaker"]
67
+ new(
68
+ confidence: confidence,
69
+ start: start,
70
+ end_: end_,
71
+ text: text,
72
+ speaker: speaker,
73
+ additional_properties: struct
74
+ )
46
75
  end
47
76
 
48
77
  # Serialize an instance of TranscriptWord to a JSON object
49
78
  #
50
- # @return [JSON]
79
+ # @return [String]
51
80
  def to_json(*_args)
52
- { "confidence": @confidence, "start": @start, "end": @end_, "text": @text, "speaker": @speaker }.to_json
81
+ @_field_set&.to_json
53
82
  end
54
83
 
55
- # 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.
84
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
85
+ # hash and check each fields type against the current object's property
86
+ # definitions.
56
87
  #
57
88
  # @param obj [Object]
58
89
  # @return [Void]