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.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +8 -0
- data/doc/openapi.json +3442 -0
- data/lib/voicer/accent_phrase.rb +50 -0
- data/lib/voicer/client.rb +10 -0
- data/lib/voicer/rest_api.rb +428 -0
- data/lib/voicer/rest_api_helper.rb +32 -0
- data/lib/voicer/version.rb +5 -0
- data/lib/voicer/voice.rb +66 -0
- data/lib/voicer/voicevox_api.rb +144 -0
- data/lib/voicer.rb +10 -0
- data/sig/voicer.rbs +4 -0
- metadata +60 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "rest_api"
|
|
4
|
+
require_relative "voice"
|
|
5
|
+
require_relative "accent_phrase"
|
|
6
|
+
|
|
7
|
+
module Voicer
|
|
8
|
+
module VoicevoxApi
|
|
9
|
+
include RestApi
|
|
10
|
+
|
|
11
|
+
CONTENT_TYPE_JSON = { "Content-Type" => "application/json" }.freeze
|
|
12
|
+
|
|
13
|
+
def parse_json(json)
|
|
14
|
+
JSON.parse(json, symbolize_names: true)
|
|
15
|
+
end
|
|
16
|
+
private :parse_json
|
|
17
|
+
|
|
18
|
+
# option: core_version: String
|
|
19
|
+
def voices(**)
|
|
20
|
+
speakers = parse_json(get_speakers(**).body)
|
|
21
|
+
singers = parse_json(get_singers(**).body)
|
|
22
|
+
|
|
23
|
+
(speakers + singers).flat_map do |obj|
|
|
24
|
+
obj in { styles:, **speaker }
|
|
25
|
+
character = Character.new(**speaker)
|
|
26
|
+
styles.map { |style| Voice.new(character: character, **style) }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# option: skip_reinit: Bool
|
|
31
|
+
# option: core_version: String
|
|
32
|
+
def initialize_voice(id, **)
|
|
33
|
+
post_initialize_speaker(nil, speaker: id, **).body
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# option: core_version: String
|
|
37
|
+
def initialized_voice?(id, **)
|
|
38
|
+
parse_json(get_is_initialized_speaker(speaker: id, **).body)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# option: is_kana: Bool
|
|
42
|
+
# option: core_version: String
|
|
43
|
+
def fetch_accent_phrases(text, id, **)
|
|
44
|
+
obj = post_accent_phrases(nil, text: text, speaker: id, **).body
|
|
45
|
+
parse_json(obj).map { |h| AccentPhrase.new(**h) }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def build_audio_query(
|
|
49
|
+
accent_phrases,
|
|
50
|
+
speed_scale: 1.0,
|
|
51
|
+
pitch_scale: 0.0,
|
|
52
|
+
intonation_scale: 1.0,
|
|
53
|
+
volume_scale: 1.0,
|
|
54
|
+
pre_phoneme_length: 0.1,
|
|
55
|
+
post_phoneme_length: 0.1,
|
|
56
|
+
pause_length: nil,
|
|
57
|
+
pause_length_scale: 1.0,
|
|
58
|
+
output_sampling_rate: 24000,
|
|
59
|
+
output_stereo: false
|
|
60
|
+
)
|
|
61
|
+
{
|
|
62
|
+
accent_phrases: accent_phrases,
|
|
63
|
+
speedScale: speed_scale,
|
|
64
|
+
pitchScale: pitch_scale,
|
|
65
|
+
intonationScale: intonation_scale,
|
|
66
|
+
volumeScale: volume_scale,
|
|
67
|
+
prePhonemeLength: pre_phoneme_length,
|
|
68
|
+
postPhonemeLength: post_phoneme_length,
|
|
69
|
+
pauseLength: pause_length,
|
|
70
|
+
pauseLengthScale: pause_length_scale,
|
|
71
|
+
outputSamplingRate: output_sampling_rate,
|
|
72
|
+
outputStereo: output_stereo,
|
|
73
|
+
}
|
|
74
|
+
end
|
|
75
|
+
private :build_audio_query
|
|
76
|
+
|
|
77
|
+
def synthesis(accent_phrases, id, core_version: nil, **)
|
|
78
|
+
post_synthesis(
|
|
79
|
+
build_audio_query(accent_phrases, **).to_json,
|
|
80
|
+
CONTENT_TYPE_JSON,
|
|
81
|
+
speaker: id,
|
|
82
|
+
core_version: core_version
|
|
83
|
+
)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def synthesis_morphing(accent_phrases, base_speaker, target_speaker, morph_rate,
|
|
87
|
+
core_version: nil, **)
|
|
88
|
+
post_synthesis_morphing(
|
|
89
|
+
build_audio_query(accent_phrases, **).to_json,
|
|
90
|
+
CONTENT_TYPE_JSON,
|
|
91
|
+
base_speaker: base_speaker,
|
|
92
|
+
target_speaker: target_speaker,
|
|
93
|
+
morph_rate: morph_rate,
|
|
94
|
+
core_version: core_version
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def text_to_voice(text, id, core_version: nil, **)
|
|
99
|
+
synthesis(
|
|
100
|
+
fetch_accent_phrases(text, id, core_version: core_version),
|
|
101
|
+
id,
|
|
102
|
+
core_version: core_version,
|
|
103
|
+
**
|
|
104
|
+
).body
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# option: core_version: String
|
|
108
|
+
def supported_devices(**)
|
|
109
|
+
parse_json(get_supported_devices(**).body)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def version
|
|
113
|
+
parse_json(get_version.body)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def core_versions
|
|
117
|
+
parse_json(get_core_versions.body)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def export_user_dict
|
|
121
|
+
parse_json(get_user_dict.body)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def import_user_dict(dict, override: true)
|
|
125
|
+
post_import_user_dict(
|
|
126
|
+
dict.to_json,
|
|
127
|
+
override: override
|
|
128
|
+
).body
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# word_type: "PROPER_NOUN" | "COMMON_NOUN" | "VERB" | "ADJECTIVE" | "SUFFIX"
|
|
132
|
+
def add_user_dict_word(surface:, pronunciation:, accent_type:, word_type: nil, priority: nil)
|
|
133
|
+
obj = post_user_dict_word(
|
|
134
|
+
nil,
|
|
135
|
+
surface: surface,
|
|
136
|
+
pronunciation: pronunciation,
|
|
137
|
+
accent_type: accent_type,
|
|
138
|
+
word_type: word_type,
|
|
139
|
+
priority: priority
|
|
140
|
+
).body
|
|
141
|
+
parse_json(obj)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
data/lib/voicer.rb
ADDED
data/sig/voicer.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: voicer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- shinokaro
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-09-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: VOICEVOXエンジンから音声を取得する。
|
|
14
|
+
email:
|
|
15
|
+
- shinokaro@hotmail.co.jp
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE.txt
|
|
21
|
+
- README.md
|
|
22
|
+
- Rakefile
|
|
23
|
+
- doc/openapi.json
|
|
24
|
+
- lib/voicer.rb
|
|
25
|
+
- lib/voicer/accent_phrase.rb
|
|
26
|
+
- lib/voicer/client.rb
|
|
27
|
+
- lib/voicer/rest_api.rb
|
|
28
|
+
- lib/voicer/rest_api_helper.rb
|
|
29
|
+
- lib/voicer/version.rb
|
|
30
|
+
- lib/voicer/voice.rb
|
|
31
|
+
- lib/voicer/voicevox_api.rb
|
|
32
|
+
- sig/voicer.rbs
|
|
33
|
+
homepage: https://github.com/shinokaro/voicer
|
|
34
|
+
licenses:
|
|
35
|
+
- MIT
|
|
36
|
+
metadata:
|
|
37
|
+
allowed_push_host: https://rubygems.org
|
|
38
|
+
homepage_uri: https://github.com/shinokaro/voicer
|
|
39
|
+
source_code_uri: https://github.com/shinokaro/voicer
|
|
40
|
+
changelog_uri: https://github.com/shinokaro/voicer
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 3.2.0
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubygems_version: 3.5.18
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 4
|
|
59
|
+
summary: VOICEVOXエンジンから音声を取得する。
|
|
60
|
+
test_files: []
|