typecast-ruby 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf92bf9b490bc438e8010ef8f63654578d039befb968944a8a59575b343cc35a
4
- data.tar.gz: fd2171c71bce32f412c0a6086b748fbea7dd3a9cd6a56df4b50ede4e27fd0808
3
+ metadata.gz: eca399615eb6a742c1a08ee80bf61ad3c03a30a2225b895275da6bac9f6398ea
4
+ data.tar.gz: 62fce2fe688c24b6e9b0860123db60e624a35aacc01ac6763a20ba507325e822
5
5
  SHA512:
6
- metadata.gz: d8568e3440fa9f20fc192e81840bdcc469fc2f7acded1b42f03ef1e0890ff56797d3bbc166cb3c279faaa04f4a14151e2b06f829d6a435305af522e114185b76
7
- data.tar.gz: c8ebc687c0b9908cd58b1ced71a76422ab0a204fa49c444b6212f88aa89c9bbbe171c4fb904715d490911e491b162ad437614e4943ceb99a9db9e96dc55dce33
6
+ metadata.gz: 7c19aa000d956bc9022cb4099ecc9d7d11c9b70a3197c95eccc46f38aadf0817c31d2425175b933c1c8b169c1c797e014e9216829a2d0c32e11d718e70351526
7
+ data.tar.gz: 5760fc399813e6241439aa5b48c272b9210d5e19d388a48d323d04f282f4cdbfb537b7d7e2ad12381d99c38e3034f75a1bd56f027f6abc0f4cd496fb7208f64d
@@ -102,6 +102,15 @@ module Typecast
102
102
  voices.first
103
103
  end
104
104
 
105
+ def get_voices_v3(filter = nil)
106
+ query = filter.respond_to?(:to_h) ? filter.to_h : filter
107
+ JSON.parse(request_json(:get, "/v3/voices", nil, query).body).map { |item| Models::VoiceV3.from_h(item) }
108
+ end
109
+
110
+ def get_voice_v3(voice_id)
111
+ Models::VoiceV3.from_h(JSON.parse(request_json(:get, "/v3/voices/#{path_segment(voice_id)}").body))
112
+ end
113
+
105
114
  # Recommends voices from a text description.
106
115
  #
107
116
  # Results only include voice_id, voice_name, and score. Use get_voice_v2 or
@@ -116,15 +125,31 @@ module Typecast
116
125
 
117
126
  def clone_voice(audio:, filename:, name:, model:)
118
127
  validate_clone_inputs(audio, name)
119
- response = request_multipart("/v1/voices/clone", audio: audio, filename: filename, fields: { name: name, model: model })
128
+ response = request_multipart("/v1/custom-voices/instant-clone", audio: audio, filename: filename, fields: { name: name, model: model })
120
129
  Models::CustomVoice.from_h(JSON.parse(response.body))
121
130
  end
122
131
 
123
132
  def delete_voice(voice_id)
124
- request_raw(:delete, "/v1/voices/#{path_segment(voice_id)}")
133
+ request_raw(:delete, "/v1/custom-voices/#{path_segment(voice_id)}")
125
134
  nil
126
135
  end
127
136
 
137
+ # Starts an asynchronous professional custom-voice clone. Poll
138
+ # get_custom_voice until status is "completed" or "failed".
139
+ def create_professional_voice(audio:, filename:, name:, language:, model:)
140
+ validate_clone_inputs(audio, name)
141
+ response = request_multipart("/v1/custom-voices/professional-clone", audio: audio, filename: filename, fields: { name: name, language: language, model: model }, file_field: "files")
142
+ Models::CustomVoice.from_h(JSON.parse(response.body))
143
+ end
144
+
145
+ def get_custom_voices
146
+ JSON.parse(request_json(:get, "/v1/custom-voices").body).map { |item| Models::CustomVoice.from_h(item) }
147
+ end
148
+
149
+ def get_custom_voice(voice_id)
150
+ Models::CustomVoice.from_h(JSON.parse(request_json(:get, "/v1/custom-voices/#{path_segment(voice_id)}").body))
151
+ end
152
+
128
153
  private
129
154
 
130
155
  def inferred_output(path)
@@ -154,7 +179,7 @@ module Typecast
154
179
  response
155
180
  end
156
181
 
157
- def request_multipart(path, audio:, filename:, fields:)
182
+ def request_multipart(path, audio:, filename:, fields:, file_field: "file")
158
183
  boundary = "typecast-ruby-#{SecureRandom.hex(8)}"
159
184
  body = +""
160
185
  fields.each do |name, value|
@@ -166,7 +191,7 @@ module Typecast
166
191
  end
167
192
  safe_filename = disposition_value(filename)
168
193
  body << "--#{boundary}\r\n"
169
- body << "Content-Disposition: form-data; name=\"file\"; filename=\"#{safe_filename}\"\r\n"
194
+ body << "Content-Disposition: form-data; name=\"#{disposition_value(file_field)}\"; filename=\"#{safe_filename}\"\r\n"
170
195
  body << "Content-Type: application/octet-stream\r\n\r\n"
171
196
  body << audio
172
197
  body << "\r\n--#{boundary}--\r\n"
@@ -13,9 +13,13 @@ module Typecast
13
13
  ].freeze
14
14
 
15
15
  class Output
16
- attr_reader :volume, :target_lufs, :audio_pitch, :audio_tempo, :audio_format
16
+ attr_reader :volume, :target_lufs, :audio_pitch, :audio_tempo, :audio_format, :remove_silence_ms
17
17
 
18
- def initialize(volume: nil, target_lufs: nil, audio_pitch: nil, audio_tempo: nil, audio_format: nil)
18
+ def initialize(volume: nil, target_lufs: nil, audio_pitch: nil, audio_tempo: nil, audio_format: nil, remove_silence_ms: nil)
19
+ unless remove_silence_ms.nil? || (remove_silence_ms.is_a?(Integer) && (0..1000).cover?(remove_silence_ms))
20
+ raise ArgumentError, "remove_silence_ms must be an integer between 0 and 1000"
21
+ end
22
+ @remove_silence_ms = remove_silence_ms
19
23
  @volume = volume
20
24
  @target_lufs = target_lufs
21
25
  @audio_pitch = audio_pitch
@@ -26,6 +30,7 @@ module Typecast
26
30
  def to_h
27
31
  Models.compact(
28
32
  volume: volume,
33
+ remove_silence_ms: remove_silence_ms,
29
34
  target_lufs: target_lufs,
30
35
  audio_pitch: audio_pitch,
31
36
  audio_tempo: audio_tempo,
@@ -35,9 +40,13 @@ module Typecast
35
40
  end
36
41
 
37
42
  class OutputStream
38
- attr_reader :audio_pitch, :audio_tempo, :audio_format, :target_lufs
43
+ attr_reader :audio_pitch, :audio_tempo, :audio_format, :target_lufs, :remove_silence_ms
39
44
 
40
- def initialize(audio_pitch: nil, audio_tempo: nil, audio_format: nil, target_lufs: nil)
45
+ def initialize(audio_pitch: nil, audio_tempo: nil, audio_format: nil, target_lufs: nil, remove_silence_ms: nil)
46
+ unless remove_silence_ms.nil? || (remove_silence_ms.is_a?(Integer) && (0..1000).cover?(remove_silence_ms))
47
+ raise ArgumentError, "remove_silence_ms must be an integer between 0 and 1000"
48
+ end
49
+ @remove_silence_ms = remove_silence_ms
41
50
  @audio_pitch = audio_pitch
42
51
  @audio_tempo = audio_tempo
43
52
  @audio_format = audio_format
@@ -49,7 +58,8 @@ module Typecast
49
58
  audio_pitch: audio_pitch,
50
59
  audio_tempo: audio_tempo,
51
60
  audio_format: audio_format,
52
- target_lufs: target_lufs
61
+ target_lufs: target_lufs,
62
+ remove_silence_ms: remove_silence_ms
53
63
  )
54
64
  end
55
65
  end
@@ -179,6 +189,17 @@ module Typecast
179
189
  end
180
190
  end
181
191
 
192
+ class VoiceV3
193
+ attr_reader :voice_id, :voice_name, :models, :voice_type, :gender, :age, :use_cases, :preview_url
194
+ def self.from_h(hash)
195
+ new(voice_id: hash.fetch("voice_id", ""), voice_name: hash.fetch("voice_name", { "eng" => "", "kor" => "" }), models: hash.fetch("models", []), voice_type: hash.fetch("voice_type", ""), gender: hash["gender"], age: hash["age"], use_cases: hash.fetch("use_cases", []), preview_url: hash["preview_url"])
196
+ end
197
+ def initialize(voice_id:, voice_name:, models:, voice_type:, gender: nil, age: nil, use_cases: [], preview_url: nil)
198
+ @voice_id, @voice_name, @models, @voice_type = voice_id, voice_name, models, voice_type
199
+ @gender, @age, @use_cases, @preview_url = gender, age, use_cases, preview_url
200
+ end
201
+ end
202
+
182
203
  class RecommendedVoice
183
204
  attr_reader :voice_id, :voice_name, :score
184
205
 
@@ -216,16 +237,20 @@ module Typecast
216
237
  end
217
238
 
218
239
  class CustomVoice
219
- attr_reader :voice_id, :name, :model
240
+ attr_reader :voice_id, :name, :model, :source, :status, :error, :created_at
220
241
 
221
242
  def self.from_h(hash)
222
- new(voice_id: hash.fetch("voice_id", ""), name: hash.fetch("name", ""), model: hash["model"])
243
+ new(voice_id: hash.fetch("voice_id", ""), name: hash.fetch("name", ""), model: hash["model"], source: hash["source"], status: hash["status"], error: hash["error"], created_at: hash["created_at"])
223
244
  end
224
245
 
225
- def initialize(voice_id:, name:, model: nil)
246
+ def initialize(voice_id:, name:, model: nil, source: nil, status: nil, error: nil, created_at: nil)
226
247
  @voice_id = voice_id
227
248
  @name = name
228
249
  @model = model
250
+ @source = source
251
+ @status = status
252
+ @error = error
253
+ @created_at = created_at
229
254
  end
230
255
  end
231
256
 
@@ -1,3 +1,3 @@
1
1
  module Typecast
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.11"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typecast-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neosapience