voicer 0.1.0

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.
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Voicer
4
+ class Mora < RestApi::Mora
5
+ class << self
6
+ def silent(length)
7
+ new(
8
+ text: "",
9
+ consonant: nil,
10
+ consonant_length: nil,
11
+ vowel: "pau",
12
+ vowel_length: length,
13
+ pitch: 0.0
14
+ )
15
+ end
16
+ end
17
+
18
+ # text
19
+ # consonant
20
+ # consonant_length
21
+ # vowel
22
+ # vowel_length
23
+ # pitch
24
+
25
+ def to_json(*) = to_h.to_json(*)
26
+
27
+ def to_s = "#{vowel}#{consonant}"
28
+ end
29
+
30
+ class AccentPhrase < RestApi::AccentPhrase
31
+ # moras
32
+ # accent
33
+ # pause_mora
34
+ # is_interrogative
35
+ def initialize(moras:, pause_mora: nil, **)
36
+ super(
37
+ moras: moras.map { |obj| obj.is_a?(Mora) ? obj : Mora.new(**obj) },
38
+ pause_mora: pause_mora &&
39
+ (pause_mora.is_a?(Mora) ? pause_mora : Mora.new(**pause_mora)),
40
+ **
41
+ )
42
+ end
43
+
44
+ alias interrogative? is_interrogative
45
+
46
+ def to_json(*) = to_h.to_json(*)
47
+
48
+ def to_s = moras.map(&:to_s).join(" ")
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require_relative "voicevox_api"
5
+
6
+ module Voicer
7
+ class Client < Net::HTTP
8
+ include VoicevoxApi
9
+ end
10
+ end
@@ -0,0 +1,428 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+ require "uri"
6
+ require_relative "rest_api_helper"
7
+
8
+ module Voicer
9
+ module RestApi
10
+ include RestApiHelper
11
+
12
+ VERSION = "0.20.0"
13
+
14
+ AccentPhrase = Data.define(
15
+ :moras,
16
+ :accent,
17
+ :pause_mora,
18
+ :is_interrogative
19
+ )
20
+
21
+ AudioQuery = Data.define(
22
+ :accent_phrases,
23
+ :speedScale,
24
+ :pitchScale,
25
+ :intonationScale,
26
+ :volumeScale,
27
+ :prePhonemeLength,
28
+ :postPhonemeLength,
29
+ :pauseLength,
30
+ :pauseLengthScale,
31
+ :outputSamplingRate,
32
+ :outputStereo,
33
+ :kana
34
+ )
35
+
36
+ Body_setting_post_setting_post = Data.define(
37
+ :cors_policy_mode,
38
+ :allow_origin
39
+ )
40
+
41
+ Body_sing_frame_volume_sing_frame_volume_post = Data.define(
42
+ :score,
43
+ :frame_audio_query
44
+ )
45
+
46
+ CorsPolicyMode = %w[all localapps].freeze
47
+
48
+ DownloadableLibraryInfo = Data.define(
49
+ :name,
50
+ :uuid,
51
+ :version,
52
+ :download_url,
53
+ :bytes,
54
+ :speakers
55
+ )
56
+
57
+ EngineManifest = Data.define(
58
+ :manifest_version,
59
+ :name,
60
+ :brand_name,
61
+ :uuid,
62
+ :url,
63
+ :icon,
64
+ :default_sampling_rate,
65
+ :frame_rate,
66
+ :terms_of_service,
67
+ :update_infos,
68
+ :dependency_licenses,
69
+ :supported_vvlib_manifest_version,
70
+ :supported_features
71
+ )
72
+
73
+ FrameAudioQuery = Data.define(
74
+ :f0,
75
+ :volume,
76
+ :phonemes,
77
+ :volumeScale,
78
+ :outputSamplingRate,
79
+ :outputStereo
80
+ )
81
+
82
+ FramePhoneme = Data.define(
83
+ :phoneme,
84
+ :frame_length
85
+ )
86
+
87
+ HTTPValidationError = Data.define(
88
+ :detail
89
+ )
90
+
91
+ InstalledLibraryInfo = Data.define(
92
+ :name,
93
+ :uuid,
94
+ :version,
95
+ :download_url,
96
+ :bytes,
97
+ :speakers,
98
+ :uninstallable
99
+ )
100
+
101
+ LibrarySpeaker = Data.define(
102
+ :speaker,
103
+ :speaker_info
104
+ )
105
+
106
+ LicenseInfo = Data.define(
107
+ :name,
108
+ :version,
109
+ :license,
110
+ :text
111
+ )
112
+
113
+ Mora = Data.define(
114
+ :text,
115
+ :consonant,
116
+ :consonant_length,
117
+ :vowel,
118
+ :vowel_length,
119
+ :pitch
120
+ )
121
+
122
+ MorphableTargetInfo = Data.define(
123
+ :is_morphable
124
+ )
125
+
126
+ Note = Data.define(
127
+ :key,
128
+ :frame_length,
129
+ :lyric
130
+ )
131
+
132
+ ParseKanaBadRequest = Data.define(
133
+ :text,
134
+ :error_name,
135
+ :error_args
136
+ )
137
+
138
+ Preset = Data.define(
139
+ :id,
140
+ :name,
141
+ :speaker_uuid,
142
+ :style_id,
143
+ :speedScale,
144
+ :pitchScale,
145
+ :intonationScale,
146
+ :volumeScale,
147
+ :prePhonemeLength,
148
+ :postPhonemeLength,
149
+ :pauseLength,
150
+ :pauseLengthScale
151
+ )
152
+
153
+ Score = Data.define(
154
+ :notes
155
+ )
156
+
157
+ Speaker = Data.define(
158
+ :name,
159
+ :speaker_uuid,
160
+ :styles,
161
+ :version,
162
+ :supported_features
163
+ )
164
+
165
+ SpeakerInfo = Data.define(
166
+ :policy,
167
+ :portrait,
168
+ :style_infos
169
+ )
170
+
171
+ SpeakerStyle = Data.define(
172
+ :name,
173
+ :id,
174
+ :type
175
+ )
176
+
177
+ SpeakerSupportedFeatures = Data.define(
178
+ :permitted_synthesis_morphing
179
+ )
180
+
181
+ StyleInfo = Data.define(
182
+ :id,
183
+ :icon,
184
+ :portrait,
185
+ :voice_samples
186
+ )
187
+
188
+ SupportedDevicesInfo = Data.define(
189
+ :cpu,
190
+ :cuda,
191
+ :dml
192
+ )
193
+
194
+ SupportedFeatures = Data.define(
195
+ :adjust_mora_pitch,
196
+ :adjust_phoneme_length,
197
+ :adjust_speed_scale,
198
+ :adjust_pitch_scale,
199
+ :adjust_intonation_scale,
200
+ :adjust_volume_scale,
201
+ :adjust_pause_length,
202
+ :interrogative_upspeak,
203
+ :synthesis_morphing,
204
+ :sing,
205
+ :manage_library,
206
+ :return_resource_url
207
+ )
208
+
209
+ UpdateInfo = Data.define(
210
+ :version,
211
+ :descriptions,
212
+ :contributors
213
+ )
214
+
215
+ UserDictWord = Data.define(
216
+ :surface,
217
+ :priority,
218
+ :context_id,
219
+ :part_of_speech,
220
+ :part_of_speech_detail_1,
221
+ :part_of_speech_detail_2,
222
+ :part_of_speech_detail_3,
223
+ :inflectional_type,
224
+ :inflectional_form,
225
+ :stem,
226
+ :yomi,
227
+ :pronunciation,
228
+ :accent_type,
229
+ :mora_count,
230
+ :accent_associative_rule
231
+ )
232
+
233
+ ValidationError = Data.define(
234
+ :loc,
235
+ :msg,
236
+ :type
237
+ )
238
+
239
+ WordTypes = %w[PROPER_NOUN COMMON_NOUN VERB ADJECTIVE SUFFIX].freeze
240
+
241
+ BaseLibraryInfo = Data.define(
242
+ :name,
243
+ :uuid,
244
+ :version,
245
+ :download_url,
246
+ :bytes,
247
+ :speakers
248
+ )
249
+
250
+ VvlibManifest = Data.define(
251
+ :manifest_version,
252
+ :name,
253
+ :version,
254
+ :uuid,
255
+ :brand_name,
256
+ :engine_name,
257
+ :engine_uuid
258
+ )
259
+
260
+ def post_audio_query(*, **)
261
+ verify_response_code post(build_uri("/audio_query", **), *)
262
+ end
263
+
264
+ def post_audio_query_from_preset(*, **)
265
+ verify_response_code post(build_uri("/audio_query_from_preset", **), *)
266
+ end
267
+
268
+ def post_accent_phrases(*, **)
269
+ verify_response_code post(build_uri("/accent_phrases", **), *)
270
+ end
271
+
272
+ def post_mora_data(*, **)
273
+ verify_response_code post(build_uri("/mora_data", **), *)
274
+ end
275
+
276
+ def post_mora_length(*, **)
277
+ verify_response_code post(build_uri("/mora_length", **), *)
278
+ end
279
+
280
+ def post_mora_pitch(*, **)
281
+ verify_response_code post(build_uri("/mora_pitch", **), *)
282
+ end
283
+
284
+ def post_synthesis(*, **)
285
+ verify_response_code post(build_uri("/synthesis", **), *)
286
+ end
287
+
288
+ def post_cancellable_synthesis(*, **)
289
+ verify_response_code post(build_uri("/cancellable_synthesis", **), *)
290
+ end
291
+
292
+ def post_multi_synthesis(*, **)
293
+ verify_response_code post(build_uri("/multi_synthesis", **), *)
294
+ end
295
+ #########
296
+ def post_sing_frame_audio_query(*, **)
297
+ verify_response_code post(build_uri("/sing_frame_audio_query", **), *)
298
+ end
299
+
300
+ def post_sing_frame_volume(*, **)
301
+ verify_response_code post(build_uri("/sing_frame_volume", **), *)
302
+ end
303
+
304
+ def post_frame_synthesis(*, **)
305
+ verify_response_code post(build_uri("/frame_synthesis", **), *)
306
+ end
307
+
308
+ def post_connect_waves(*, **)
309
+ verify_response_code post(build_uri("/connect_waves", **), *)
310
+ end
311
+
312
+ def post_validate_kana(*, **)
313
+ verify_response_code post(build_uri("/validate_kana", **), *)
314
+ end
315
+
316
+ def post_initialize_speaker(*, **)
317
+ verify_response_code post(build_uri("/initialize_speaker", **), *)
318
+ end
319
+
320
+ def get_is_initialized_speaker(*, **)
321
+ verify_response_code get(build_uri("/is_initialized_speaker", **), *)
322
+ end
323
+
324
+ def get_supported_devices(*, **)
325
+ verify_response_code get(build_uri("/supported_devices", **), *)
326
+ end
327
+
328
+ def post_morphable_targets(*, **)
329
+ verify_response_code post(build_uri("/morphable_targets", **), *)
330
+ end
331
+
332
+ def post_synthesis_morphing(*, **)
333
+ verify_response_code post(build_uri("/synthesis_morphing", **), *)
334
+ end
335
+
336
+ def get_presets(*, **)
337
+ verify_response_code get(build_uri("/presets", **), *)
338
+ end
339
+
340
+ def post_add_preset(*, **)
341
+ verify_response_code post(build_uri("/add_preset", **), *)
342
+ end
343
+
344
+ def post_update_preset(*, **)
345
+ verify_response_code post(build_uri("/update_preset", **), *)
346
+ end
347
+
348
+ def post_delete_preset(*, **)
349
+ verify_response_code post(build_uri("/delete_preset", **), *)
350
+ end
351
+
352
+ def get_speakers(*, **)
353
+ verify_response_code get(build_uri("/speakers", **), *)
354
+ end
355
+
356
+ def get_speaker_info(*, **)
357
+ verify_response_code get(build_uri("/speaker_info", **), *)
358
+ end
359
+
360
+ def get_singers(*, **)
361
+ verify_response_code get(build_uri("/singers", **), *)
362
+ end
363
+
364
+ def get_singer_info(*, **)
365
+ verify_response_code get(build_uri("/singer_info", **), *)
366
+ end
367
+
368
+ def get_downloadable_libraries(*, **)
369
+ verify_response_code get(build_uri("/downloadable_libraries", **), *)
370
+ end
371
+
372
+ def get_installed_libraries(*, **)
373
+ verify_response_code get(build_uri("/installed_libraries", **), *)
374
+ end
375
+
376
+ def post_install_library__library_uuid(library_uuid, *, **)
377
+ verify_response_code post(build_uri("/install_library/#{library_uuid}", **), *)
378
+ end
379
+
380
+ def post_uninstall_library__library_uuid(library_uuid, *, **)
381
+ verify_response_code post(build_uri("/uninstall_library/#{library_uuid}", **), *)
382
+ end
383
+
384
+ def get_user_dict(*, **)
385
+ verify_response_code get(build_uri("/user_dict", **), *)
386
+ end
387
+
388
+ def post_user_dict_word(*, **)
389
+ verify_response_code post(build_uri("/user_dict_word", **), *)
390
+ end
391
+
392
+ def put_user_dict_word__word_uuid(word_uuid, *, **)
393
+ verify_response_code put(build_uri("/user_dict_word/#{word_uuid}", **), *)
394
+ end
395
+
396
+ def delete_user_dict_word__word_uuid(word_uuid, *, **)
397
+ verify_response_code delete(build_uri("/user_dict_word/#{word_uuid}", **), *)
398
+ end
399
+
400
+ def post_import_user_dict(*, **)
401
+ verify_response_code post(build_uri("/import_user_dict", **), *)
402
+ end
403
+
404
+ def get_version(*, **)
405
+ verify_response_code get(build_uri("/version", **), *)
406
+ end
407
+
408
+ def get_core_versions(*, **)
409
+ verify_response_code get(build_uri("/core_versions", **), *)
410
+ end
411
+
412
+ def get_engine_manifest(*, **)
413
+ verify_response_code get(build_uri("/engine_manifest", **), *)
414
+ end
415
+
416
+ def get_setting(*, **)
417
+ verify_response_code get(build_uri("/setting", **), *)
418
+ end
419
+
420
+ def post_setting(*, **)
421
+ verify_response_code post(build_uri("/setting", **), *)
422
+ end
423
+
424
+ def get_portal_page(*, **)
425
+ verify_response_code get(build_uri("/", **), *)
426
+ end
427
+ end
428
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+
6
+ module Voicer
7
+ class ParseKanaBadRequest < Net::HTTPClientException; end
8
+
9
+ class HTTPValidationError < Net::HTTPClientException; end
10
+
11
+ module RestApiHelper
12
+ def build_uri(path, **query)
13
+ uri = URI(path)
14
+ uri.query = URI.encode_www_form(query) unless query.empty?
15
+ uri.to_s
16
+ end
17
+ private :build_uri
18
+
19
+ def verify_response_code(response)
20
+ case response.code
21
+ when "400"
22
+ raise ParseKanaBadRequest.new(response.body, response)
23
+ when "422"
24
+ raise HTTPValidationError.new(response.body, response)
25
+ else
26
+ response.value
27
+ end
28
+ response
29
+ end
30
+ private :verify_response_code
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Voicer
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+ require_relative "rest_api"
5
+
6
+ module Voicer
7
+ class Character < RestApi::Speaker
8
+ include RestApi
9
+
10
+ # name
11
+ # speaker_uuid
12
+ # styles
13
+ # version
14
+ # supported_features
15
+ def initialize(styles: nil, supported_features:, **)
16
+ super(
17
+ styles: nil,
18
+ supported_features: SpeakerSupportedFeatures.new(supported_features),
19
+ **
20
+ )
21
+ end
22
+
23
+ extend Forwardable
24
+ def_delegators :supported_features, *SpeakerSupportedFeatures.members
25
+
26
+ undef styles
27
+
28
+ alias core_version version
29
+ alias uuid speaker_uuid
30
+ alias to_s name
31
+ end
32
+
33
+ class Voice < RestApi::SpeakerStyle
34
+ include RestApi
35
+
36
+ attr_reader :character
37
+
38
+ # name
39
+ # id
40
+ # type
41
+ def initialize(character:, **)
42
+ @character = character
43
+ super(**)
44
+ end
45
+
46
+ extend Forwardable
47
+
48
+ def_delegators :character, *(Speaker.members - [:name, :styles])
49
+ def_delegators :character, :version, :core_version
50
+ def_delegators :character, *SpeakerSupportedFeatures.members
51
+
52
+ def character_name = character.name
53
+
54
+ alias style_name name
55
+
56
+ def name = "#{character_name} (#{style_name})"
57
+
58
+ alias to_s name
59
+
60
+ def speaker? = type == "talk"
61
+
62
+ def singer? = !speaker?
63
+
64
+ alias to_i id
65
+ end
66
+ end