assemblyai 1.0.0.pre.beta.6 → 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 (79) 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 +32 -16
  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 +21 -12
  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 +21 -12
  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/streaming/types/send_message.rb +86 -0
  35. data/lib/assemblyai/streaming/types/streaming.rb +11 -0
  36. data/lib/assemblyai/transcripts/client.rb +54 -20
  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 +60 -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 +2 -0
  54. data/lib/assemblyai/transcripts/types/substitution_policy.rb +4 -2
  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 -16
  63. data/lib/assemblyai/transcripts/types/transcript_list_item.rb +63 -30
  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 +9 -8
  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
  79. data/lib/assemblyai/realtime/types/send_message.rb +0 -74
@@ -4,30 +4,37 @@ require "json"
4
4
 
5
5
  module AssemblyAI
6
6
  class Lemur
7
- # Any context about the transcripts you wish to provide. This can be a string or any object.
7
+ # Any context about the transcripts you wish to provide. This can be a string or
8
+ # any object.
8
9
  class LemurQuestionContext
9
10
  # Deserialize a JSON object to an instance of LemurQuestionContext
10
11
  #
11
- # @param json_object [JSON]
12
- # @return [Lemur::LemurQuestionContext]
12
+ # @param json_object [String]
13
+ # @return [AssemblyAI::Lemur::LemurQuestionContext]
13
14
  def self.from_json(json_object:)
14
15
  struct = JSON.parse(json_object, object_class: OpenStruct)
15
16
  begin
16
17
  struct.is_a?(String) != false || raise("Passed value for field struct is not the expected type, validation failed.")
17
- return json_object
18
+ return json_object unless json_object.nil?
19
+
20
+ return nil
18
21
  rescue StandardError
19
22
  # noop
20
23
  end
21
24
  begin
22
25
  struct.is_a?(Hash) != false || raise("Passed value for field struct is not the expected type, validation failed.")
23
- return json_object
26
+ return json_object unless json_object.nil?
27
+
28
+ return nil
24
29
  rescue StandardError
25
30
  # noop
26
31
  end
27
32
  struct
28
33
  end
29
34
 
30
- # 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.
35
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
36
+ # hash and check each fields type against the current object's property
37
+ # definitions.
31
38
  #
32
39
  # @param obj [Object]
33
40
  # @return [Void]
@@ -1,45 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ostruct"
3
4
  require "json"
4
5
 
5
6
  module AssemblyAI
6
7
  class Lemur
7
8
  class LemurSummaryResponse
8
- attr_reader :response, :request_id, :additional_properties
9
+ # @return [String] The response generated by LeMUR
10
+ attr_reader :response
11
+ # @return [String] The ID of the LeMUR request
12
+ attr_reader :request_id
13
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
14
+ attr_reader :additional_properties
15
+ # @return [Object]
16
+ attr_reader :_field_set
17
+ protected :_field_set
18
+
19
+ OMIT = Object.new
9
20
 
10
21
  # @param response [String] The response generated by LeMUR
11
22
  # @param request_id [String] The ID of the LeMUR request
12
23
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
13
- # @return [Lemur::LemurSummaryResponse]
24
+ # @return [AssemblyAI::Lemur::LemurSummaryResponse]
14
25
  def initialize(response:, request_id:, additional_properties: nil)
15
- # @type [String] The response generated by LeMUR
16
26
  @response = response
17
- # @type [String] The ID of the LeMUR request
18
27
  @request_id = request_id
19
- # @type [OpenStruct] Additional properties unmapped to the current class definition
20
28
  @additional_properties = additional_properties
29
+ @_field_set = { "response": response, "request_id": request_id }
21
30
  end
22
31
 
23
32
  # Deserialize a JSON object to an instance of LemurSummaryResponse
24
33
  #
25
- # @param json_object [JSON]
26
- # @return [Lemur::LemurSummaryResponse]
34
+ # @param json_object [String]
35
+ # @return [AssemblyAI::Lemur::LemurSummaryResponse]
27
36
  def self.from_json(json_object:)
28
37
  struct = JSON.parse(json_object, object_class: OpenStruct)
29
- JSON.parse(json_object)
30
- response = struct.response
31
- request_id = struct.request_id
32
- new(response: response, request_id: request_id, additional_properties: struct)
38
+ response = struct["response"]
39
+ request_id = struct["request_id"]
40
+ new(
41
+ response: response,
42
+ request_id: request_id,
43
+ additional_properties: struct
44
+ )
33
45
  end
34
46
 
35
47
  # Serialize an instance of LemurSummaryResponse to a JSON object
36
48
  #
37
- # @return [JSON]
49
+ # @return [String]
38
50
  def to_json(*_args)
39
- { "response": @response, "request_id": @request_id }.to_json
51
+ @_field_set&.to_json
40
52
  end
41
53
 
42
- # 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.
54
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
55
+ # hash and check each fields type against the current object's property
56
+ # definitions.
43
57
  #
44
58
  # @param obj [Object]
45
59
  # @return [Void]
@@ -1,45 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ostruct"
3
4
  require "json"
4
5
 
5
6
  module AssemblyAI
6
7
  class Lemur
7
8
  class LemurTaskResponse
8
- attr_reader :response, :request_id, :additional_properties
9
+ # @return [String] The response generated by LeMUR.
10
+ attr_reader :response
11
+ # @return [String] The ID of the LeMUR request
12
+ attr_reader :request_id
13
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
14
+ attr_reader :additional_properties
15
+ # @return [Object]
16
+ attr_reader :_field_set
17
+ protected :_field_set
18
+
19
+ OMIT = Object.new
9
20
 
10
21
  # @param response [String] The response generated by LeMUR.
11
22
  # @param request_id [String] The ID of the LeMUR request
12
23
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
13
- # @return [Lemur::LemurTaskResponse]
24
+ # @return [AssemblyAI::Lemur::LemurTaskResponse]
14
25
  def initialize(response:, request_id:, additional_properties: nil)
15
- # @type [String] The response generated by LeMUR.
16
26
  @response = response
17
- # @type [String] The ID of the LeMUR request
18
27
  @request_id = request_id
19
- # @type [OpenStruct] Additional properties unmapped to the current class definition
20
28
  @additional_properties = additional_properties
29
+ @_field_set = { "response": response, "request_id": request_id }
21
30
  end
22
31
 
23
32
  # Deserialize a JSON object to an instance of LemurTaskResponse
24
33
  #
25
- # @param json_object [JSON]
26
- # @return [Lemur::LemurTaskResponse]
34
+ # @param json_object [String]
35
+ # @return [AssemblyAI::Lemur::LemurTaskResponse]
27
36
  def self.from_json(json_object:)
28
37
  struct = JSON.parse(json_object, object_class: OpenStruct)
29
- JSON.parse(json_object)
30
- response = struct.response
31
- request_id = struct.request_id
32
- new(response: response, request_id: request_id, additional_properties: struct)
38
+ response = struct["response"]
39
+ request_id = struct["request_id"]
40
+ new(
41
+ response: response,
42
+ request_id: request_id,
43
+ additional_properties: struct
44
+ )
33
45
  end
34
46
 
35
47
  # Serialize an instance of LemurTaskResponse to a JSON object
36
48
  #
37
- # @return [JSON]
49
+ # @return [String]
38
50
  def to_json(*_args)
39
- { "response": @response, "request_id": @request_id }.to_json
51
+ @_field_set&.to_json
40
52
  end
41
53
 
42
- # 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.
54
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
55
+ # hash and check each fields type against the current object's property
56
+ # definitions.
43
57
  #
44
58
  # @param obj [Object]
45
59
  # @return [Void]
@@ -1,50 +1,65 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ostruct"
3
4
  require "json"
4
5
 
5
6
  module AssemblyAI
6
7
  class Lemur
7
8
  class PurgeLemurRequestDataResponse
8
- attr_reader :request_id, :request_id_to_purge, :deleted, :additional_properties
9
+ # @return [String] The ID of the deletion request of the LeMUR request
10
+ attr_reader :request_id
11
+ # @return [String] The ID of the LeMUR request to purge the data for
12
+ attr_reader :request_id_to_purge
13
+ # @return [Boolean] Whether the request data was deleted
14
+ attr_reader :deleted
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
9
22
 
10
23
  # @param request_id [String] The ID of the deletion request of the LeMUR request
11
24
  # @param request_id_to_purge [String] The ID of the LeMUR request to purge the data for
12
25
  # @param deleted [Boolean] Whether the request data was deleted
13
26
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
14
- # @return [Lemur::PurgeLemurRequestDataResponse]
27
+ # @return [AssemblyAI::Lemur::PurgeLemurRequestDataResponse]
15
28
  def initialize(request_id:, request_id_to_purge:, deleted:, additional_properties: nil)
16
- # @type [String] The ID of the deletion request of the LeMUR request
17
29
  @request_id = request_id
18
- # @type [String] The ID of the LeMUR request to purge the data for
19
30
  @request_id_to_purge = request_id_to_purge
20
- # @type [Boolean] Whether the request data was deleted
21
31
  @deleted = deleted
22
- # @type [OpenStruct] Additional properties unmapped to the current class definition
23
32
  @additional_properties = additional_properties
33
+ @_field_set = { "request_id": request_id, "request_id_to_purge": request_id_to_purge, "deleted": deleted }
24
34
  end
25
35
 
26
36
  # Deserialize a JSON object to an instance of PurgeLemurRequestDataResponse
27
37
  #
28
- # @param json_object [JSON]
29
- # @return [Lemur::PurgeLemurRequestDataResponse]
38
+ # @param json_object [String]
39
+ # @return [AssemblyAI::Lemur::PurgeLemurRequestDataResponse]
30
40
  def self.from_json(json_object:)
31
41
  struct = JSON.parse(json_object, object_class: OpenStruct)
32
- JSON.parse(json_object)
33
- request_id = struct.request_id
34
- request_id_to_purge = struct.request_id_to_purge
35
- deleted = struct.deleted
36
- new(request_id: request_id, request_id_to_purge: request_id_to_purge, deleted: deleted,
37
- additional_properties: struct)
42
+ request_id = struct["request_id"]
43
+ request_id_to_purge = struct["request_id_to_purge"]
44
+ deleted = struct["deleted"]
45
+ new(
46
+ request_id: request_id,
47
+ request_id_to_purge: request_id_to_purge,
48
+ deleted: deleted,
49
+ additional_properties: struct
50
+ )
38
51
  end
39
52
 
40
53
  # Serialize an instance of PurgeLemurRequestDataResponse to a JSON object
41
54
  #
42
- # @return [JSON]
55
+ # @return [String]
43
56
  def to_json(*_args)
44
- { "request_id": @request_id, "request_id_to_purge": @request_id_to_purge, "deleted": @deleted }.to_json
57
+ @_field_set&.to_json
45
58
  end
46
59
 
47
- # 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.
60
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
61
+ # hash and check each fields type against the current object's property
62
+ # definitions.
48
63
  #
49
64
  # @param obj [Object]
50
65
  # @return [Void]
@@ -6,55 +6,71 @@ require "async"
6
6
 
7
7
  module AssemblyAI
8
8
  class RealtimeClient
9
+ # @return [AssemblyAI::RequestClient]
9
10
  attr_reader :request_client
10
11
 
11
- # @param request_client [RequestClient]
12
- # @return [RealtimeClient]
12
+ # @param request_client [AssemblyAI::RequestClient]
13
+ # @return [AssemblyAI::RealtimeClient]
13
14
  def initialize(request_client:)
14
- # @type [RequestClient]
15
15
  @request_client = request_client
16
16
  end
17
17
 
18
- # Create a temporary authentication token for real-time transcription
18
+ # Create a temporary authentication token for Streaming Speech-to-Text
19
19
  #
20
20
  # @param expires_in [Integer] The amount of time until the token expires in seconds
21
- # @param request_options [RequestOptions]
22
- # @return [Realtime::RealtimeTemporaryTokenResponse]
21
+ # @param request_options [AssemblyAI::RequestOptions]
22
+ # @return [AssemblyAI::Realtime::RealtimeTemporaryTokenResponse]
23
+ # @example
24
+ # api = AssemblyAI::Client.new(
25
+ # environment: Environment::DEFAULT,
26
+ # base_url: "https://api.example.com",
27
+ # api_key: "YOUR_API_KEY"
28
+ # )
29
+ # api.create_temporary_token(expires_in: 480)
23
30
  def create_temporary_token(expires_in:, request_options: nil)
24
- response = @request_client.conn.post("/v2/realtime/token") do |req|
31
+ response = @request_client.conn.post do |req|
25
32
  req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
26
33
  req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
27
34
  req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
28
35
  req.body = { **(request_options&.additional_body_parameters || {}), expires_in: expires_in }.compact
36
+ req.url "#{@request_client.get_url(request_options: request_options)}/v2/realtime/token"
29
37
  end
30
- Realtime::RealtimeTemporaryTokenResponse.from_json(json_object: response.body)
38
+ AssemblyAI::Realtime::RealtimeTemporaryTokenResponse.from_json(json_object: response.body)
31
39
  end
32
40
  end
33
41
 
34
42
  class AsyncRealtimeClient
43
+ # @return [AssemblyAI::AsyncRequestClient]
35
44
  attr_reader :request_client
36
45
 
37
- # @param request_client [AsyncRequestClient]
38
- # @return [AsyncRealtimeClient]
46
+ # @param request_client [AssemblyAI::AsyncRequestClient]
47
+ # @return [AssemblyAI::AsyncRealtimeClient]
39
48
  def initialize(request_client:)
40
- # @type [AsyncRequestClient]
41
49
  @request_client = request_client
42
50
  end
43
51
 
44
- # Create a temporary authentication token for real-time transcription
52
+ # Create a temporary authentication token for Streaming Speech-to-Text
45
53
  #
46
54
  # @param expires_in [Integer] The amount of time until the token expires in seconds
47
- # @param request_options [RequestOptions]
48
- # @return [Realtime::RealtimeTemporaryTokenResponse]
55
+ # @param request_options [AssemblyAI::RequestOptions]
56
+ # @return [AssemblyAI::Realtime::RealtimeTemporaryTokenResponse]
57
+ # @example
58
+ # api = AssemblyAI::Client.new(
59
+ # environment: Environment::DEFAULT,
60
+ # base_url: "https://api.example.com",
61
+ # api_key: "YOUR_API_KEY"
62
+ # )
63
+ # api.create_temporary_token(expires_in: 480)
49
64
  def create_temporary_token(expires_in:, request_options: nil)
50
65
  Async do
51
- response = @request_client.conn.post("/v2/realtime/token") do |req|
66
+ response = @request_client.conn.post do |req|
52
67
  req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
53
68
  req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
54
69
  req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
55
70
  req.body = { **(request_options&.additional_body_parameters || {}), expires_in: expires_in }.compact
71
+ req.url "#{@request_client.get_url(request_options: request_options)}/v2/realtime/token"
56
72
  end
57
- Realtime::RealtimeTemporaryTokenResponse.from_json(json_object: response.body)
73
+ AssemblyAI::Realtime::RealtimeTemporaryTokenResponse.from_json(json_object: response.body)
58
74
  end
59
75
  end
60
76
  end
@@ -1,42 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ostruct"
3
4
  require "json"
4
5
 
5
6
  module AssemblyAI
6
7
  class Realtime
7
- # Configure the threshold for how long to wait before ending an utterance. Default is 700ms.
8
+ # Configure the threshold for how long to wait before ending an utterance. Default
9
+ # is 700ms.
8
10
  class ConfigureEndUtteranceSilenceThreshold
9
- attr_reader :end_utterance_silence_threshold, :additional_properties
11
+ # @return [Integer] The duration threshold in milliseconds
12
+ attr_reader :end_utterance_silence_threshold
13
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
14
+ attr_reader :additional_properties
15
+ # @return [Object]
16
+ attr_reader :_field_set
17
+ protected :_field_set
18
+
19
+ OMIT = Object.new
10
20
 
11
21
  # @param end_utterance_silence_threshold [Integer] The duration threshold in milliseconds
12
22
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
13
- # @return [Realtime::ConfigureEndUtteranceSilenceThreshold]
23
+ # @return [AssemblyAI::Realtime::ConfigureEndUtteranceSilenceThreshold]
14
24
  def initialize(end_utterance_silence_threshold:, additional_properties: nil)
15
- # @type [Integer] The duration threshold in milliseconds
16
25
  @end_utterance_silence_threshold = end_utterance_silence_threshold
17
- # @type [OpenStruct] Additional properties unmapped to the current class definition
18
26
  @additional_properties = additional_properties
27
+ @_field_set = { "end_utterance_silence_threshold": end_utterance_silence_threshold }
19
28
  end
20
29
 
21
- # Deserialize a JSON object to an instance of ConfigureEndUtteranceSilenceThreshold
30
+ # Deserialize a JSON object to an instance of
31
+ # ConfigureEndUtteranceSilenceThreshold
22
32
  #
23
- # @param json_object [JSON]
24
- # @return [Realtime::ConfigureEndUtteranceSilenceThreshold]
33
+ # @param json_object [String]
34
+ # @return [AssemblyAI::Realtime::ConfigureEndUtteranceSilenceThreshold]
25
35
  def self.from_json(json_object:)
26
36
  struct = JSON.parse(json_object, object_class: OpenStruct)
27
- JSON.parse(json_object)
28
- end_utterance_silence_threshold = struct.end_utterance_silence_threshold
37
+ end_utterance_silence_threshold = struct["end_utterance_silence_threshold"]
29
38
  new(end_utterance_silence_threshold: end_utterance_silence_threshold, additional_properties: struct)
30
39
  end
31
40
 
32
41
  # Serialize an instance of ConfigureEndUtteranceSilenceThreshold to a JSON object
33
42
  #
34
- # @return [JSON]
43
+ # @return [String]
35
44
  def to_json(*_args)
36
- { "end_utterance_silence_threshold": @end_utterance_silence_threshold }.to_json
45
+ @_field_set&.to_json
37
46
  end
38
47
 
39
- # 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.
48
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
49
+ # hash and check each fields type against the current object's property
50
+ # definitions.
40
51
  #
41
52
  # @param obj [Object]
42
53
  # @return [Void]
@@ -2,13 +2,40 @@
2
2
 
3
3
  require_relative "word"
4
4
  require "date"
5
+ require "ostruct"
5
6
  require "json"
6
7
 
7
8
  module AssemblyAI
8
9
  class Realtime
9
10
  class FinalTranscript
10
- attr_reader :message_type, :punctuated, :text_formatted, :audio_start, :audio_end, :confidence, :text, :words,
11
- :created, :additional_properties
11
+ # @return [String]
12
+ attr_reader :message_type
13
+ # @return [Boolean] Whether the text is punctuated and cased
14
+ attr_reader :punctuated
15
+ # @return [Boolean] Whether the text is formatted, for example Dollar -> $
16
+ attr_reader :text_formatted
17
+ # @return [Integer] Start time of audio sample relative to session start, in milliseconds
18
+ attr_reader :audio_start
19
+ # @return [Integer] End time of audio sample relative to session start, in milliseconds
20
+ attr_reader :audio_end
21
+ # @return [Float] The confidence score of the entire transcription, between 0 and 1
22
+ attr_reader :confidence
23
+ # @return [String] The partial transcript for your audio
24
+ attr_reader :text
25
+ # @return [Array<AssemblyAI::Realtime::Word>] An array of objects, with the information for each word in the transcription
26
+ # text.
27
+ # Includes the start and end time of the word in milliseconds, the confidence
28
+ # score of the word, and the text, which is the word itself.
29
+ attr_reader :words
30
+ # @return [DateTime] The timestamp for the partial transcript
31
+ attr_reader :created
32
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
33
+ attr_reader :additional_properties
34
+ # @return [Object]
35
+ attr_reader :_field_set
36
+ protected :_field_set
37
+
38
+ OMIT = Object.new
12
39
 
13
40
  # @param message_type [String]
14
41
  # @param punctuated [Boolean] Whether the text is punctuated and cased
@@ -17,77 +44,81 @@ module AssemblyAI
17
44
  # @param audio_end [Integer] End time of audio sample relative to session start, in milliseconds
18
45
  # @param confidence [Float] The confidence score of the entire transcription, between 0 and 1
19
46
  # @param text [String] The partial transcript for your audio
20
- # @param words [Array<Realtime::Word>] An array of objects, with the information for each word in the transcription text.
21
- # 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.
47
+ # @param words [Array<AssemblyAI::Realtime::Word>] An array of objects, with the information for each word in the transcription
48
+ # text.
49
+ # Includes the start and end time of the word in milliseconds, the confidence
50
+ # score of the word, and the text, which is the word itself.
22
51
  # @param created [DateTime] The timestamp for the partial transcript
23
52
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
24
- # @return [Realtime::FinalTranscript]
53
+ # @return [AssemblyAI::Realtime::FinalTranscript]
25
54
  def initialize(message_type:, punctuated:, text_formatted:, audio_start:, audio_end:, confidence:, text:, words:,
26
55
  created:, additional_properties: nil)
27
- # @type [String]
28
56
  @message_type = message_type
29
- # @type [Boolean] Whether the text is punctuated and cased
30
57
  @punctuated = punctuated
31
- # @type [Boolean] Whether the text is formatted, for example Dollar -> $
32
58
  @text_formatted = text_formatted
33
- # @type [Integer] Start time of audio sample relative to session start, in milliseconds
34
59
  @audio_start = audio_start
35
- # @type [Integer] End time of audio sample relative to session start, in milliseconds
36
60
  @audio_end = audio_end
37
- # @type [Float] The confidence score of the entire transcription, between 0 and 1
38
61
  @confidence = confidence
39
- # @type [String] The partial transcript for your audio
40
62
  @text = text
41
- # @type [Array<Realtime::Word>] An array of objects, with the information for each word in the transcription text.
42
- # 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.
43
63
  @words = words
44
- # @type [DateTime] The timestamp for the partial transcript
45
64
  @created = created
46
- # @type [OpenStruct] Additional properties unmapped to the current class definition
47
65
  @additional_properties = additional_properties
66
+ @_field_set = {
67
+ "message_type": message_type,
68
+ "punctuated": punctuated,
69
+ "text_formatted": text_formatted,
70
+ "audio_start": audio_start,
71
+ "audio_end": audio_end,
72
+ "confidence": confidence,
73
+ "text": text,
74
+ "words": words,
75
+ "created": created
76
+ }
48
77
  end
49
78
 
50
79
  # Deserialize a JSON object to an instance of FinalTranscript
51
80
  #
52
- # @param json_object [JSON]
53
- # @return [Realtime::FinalTranscript]
81
+ # @param json_object [String]
82
+ # @return [AssemblyAI::Realtime::FinalTranscript]
54
83
  def self.from_json(json_object:)
55
84
  struct = JSON.parse(json_object, object_class: OpenStruct)
56
85
  parsed_json = JSON.parse(json_object)
57
- message_type = struct.message_type
58
- punctuated = struct.punctuated
59
- text_formatted = struct.text_formatted
60
- audio_start = struct.audio_start
61
- audio_end = struct.audio_end
62
- confidence = struct.confidence
63
- text = struct.text
86
+ message_type = struct["message_type"]
87
+ punctuated = struct["punctuated"]
88
+ text_formatted = struct["text_formatted"]
89
+ audio_start = struct["audio_start"]
90
+ audio_end = struct["audio_end"]
91
+ confidence = struct["confidence"]
92
+ text = struct["text"]
64
93
  words = parsed_json["words"]&.map do |v|
65
94
  v = v.to_json
66
- Realtime::Word.from_json(json_object: v)
95
+ AssemblyAI::Realtime::Word.from_json(json_object: v)
67
96
  end
68
97
  created = (DateTime.parse(parsed_json["created"]) unless parsed_json["created"].nil?)
69
- new(message_type: message_type, punctuated: punctuated, text_formatted: text_formatted,
70
- audio_start: audio_start, audio_end: audio_end, confidence: confidence, text: text, words: words, created: created, additional_properties: struct)
98
+ new(
99
+ message_type: message_type,
100
+ punctuated: punctuated,
101
+ text_formatted: text_formatted,
102
+ audio_start: audio_start,
103
+ audio_end: audio_end,
104
+ confidence: confidence,
105
+ text: text,
106
+ words: words,
107
+ created: created,
108
+ additional_properties: struct
109
+ )
71
110
  end
72
111
 
73
112
  # Serialize an instance of FinalTranscript to a JSON object
74
113
  #
75
- # @return [JSON]
114
+ # @return [String]
76
115
  def to_json(*_args)
77
- {
78
- "message_type": @message_type,
79
- "punctuated": @punctuated,
80
- "text_formatted": @text_formatted,
81
- "audio_start": @audio_start,
82
- "audio_end": @audio_end,
83
- "confidence": @confidence,
84
- "text": @text,
85
- "words": @words,
86
- "created": @created
87
- }.to_json
116
+ @_field_set&.to_json
88
117
  end
89
118
 
90
- # 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.
119
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
120
+ # hash and check each fields type against the current object's property
121
+ # definitions.
91
122
  #
92
123
  # @param obj [Object]
93
124
  # @return [Void]
@@ -1,42 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ostruct"
3
4
  require "json"
4
5
 
5
6
  module AssemblyAI
6
7
  class Realtime
7
8
  # Manually end an utterance
8
9
  class ForceEndUtterance
9
- attr_reader :force_end_utterance, :additional_properties
10
+ # @return [Boolean] A boolean value to communicate that you wish to force the end of the utterance
11
+ attr_reader :force_end_utterance
12
+ # @return [OpenStruct] Additional properties unmapped to the current class definition
13
+ attr_reader :additional_properties
14
+ # @return [Object]
15
+ attr_reader :_field_set
16
+ protected :_field_set
17
+
18
+ OMIT = Object.new
10
19
 
11
20
  # @param force_end_utterance [Boolean] A boolean value to communicate that you wish to force the end of the utterance
12
21
  # @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
13
- # @return [Realtime::ForceEndUtterance]
22
+ # @return [AssemblyAI::Realtime::ForceEndUtterance]
14
23
  def initialize(force_end_utterance:, additional_properties: nil)
15
- # @type [Boolean] A boolean value to communicate that you wish to force the end of the utterance
16
24
  @force_end_utterance = force_end_utterance
17
- # @type [OpenStruct] Additional properties unmapped to the current class definition
18
25
  @additional_properties = additional_properties
26
+ @_field_set = { "force_end_utterance": force_end_utterance }
19
27
  end
20
28
 
21
29
  # Deserialize a JSON object to an instance of ForceEndUtterance
22
30
  #
23
- # @param json_object [JSON]
24
- # @return [Realtime::ForceEndUtterance]
31
+ # @param json_object [String]
32
+ # @return [AssemblyAI::Realtime::ForceEndUtterance]
25
33
  def self.from_json(json_object:)
26
34
  struct = JSON.parse(json_object, object_class: OpenStruct)
27
- JSON.parse(json_object)
28
- force_end_utterance = struct.force_end_utterance
35
+ force_end_utterance = struct["force_end_utterance"]
29
36
  new(force_end_utterance: force_end_utterance, additional_properties: struct)
30
37
  end
31
38
 
32
39
  # Serialize an instance of ForceEndUtterance to a JSON object
33
40
  #
34
- # @return [JSON]
41
+ # @return [String]
35
42
  def to_json(*_args)
36
- { "force_end_utterance": @force_end_utterance }.to_json
43
+ @_field_set&.to_json
37
44
  end
38
45
 
39
- # 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.
46
+ # Leveraged for Union-type generation, validate_raw attempts to parse the given
47
+ # hash and check each fields type against the current object's property
48
+ # definitions.
40
49
  #
41
50
  # @param obj [Object]
42
51
  # @return [Void]