voicevox.rb 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/.rubocop.yml +21 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +19 -0
- data/LICENSE +21 -0
- data/README.md +46 -0
- data/Rakefile +7 -0
- data/Steepfile +29 -0
- data/examples/cli.rb +48 -0
- data/examples/outputs/.gitkeep +0 -0
- data/examples/repl_core.rb +48 -0
- data/examples/repl_wrapper.rb +33 -0
- data/lib/voicevox/core.rb +448 -0
- data/lib/voicevox/error.rb +79 -0
- data/lib/voicevox/version.rb +6 -0
- data/lib/voicevox/wrapper/audio_query.rb +213 -0
- data/lib/voicevox/wrapper/info.rb +113 -0
- data/lib/voicevox/wrapper/manager.rb +137 -0
- data/lib/voicevox/wrapper/utils.rb +45 -0
- data/lib/voicevox.rb +15 -0
- data/rbs_collection.lock.yaml +100 -0
- data/rbs_collection.yaml +15 -0
- data/sig/ffi.rbs +16 -0
- data/sig/voicevox/core.rbs +126 -0
- data/sig/voicevox/error.rbs +53 -0
- data/sig/voicevox/wrapper/info.rbs +26 -0
- data/sig/voicevox/wrapper/manager.rbs +31 -0
- data/sig/voicevox/wrapper/utils.rbs +9 -0
- data/sig/voicevox.rbs +3 -0
- data/voicevox.gemspec +42 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: beca96000321395577fc6ab362a35309610a60eb7e6a2bd7e0094174b4a2921d
|
4
|
+
data.tar.gz: '075786986b2cc5336cbc43407fe4e852b6a74c16abd976cade9fddbe3e6cc77c'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 060e0e6ad52f99d7d29c5beee3bee7a46e0dd76013b2c51f0358790a03b485c39cec120ab0b0eeac319826ce0089467ebaa0a0f733fb5c08a197f334ddaeb3df
|
7
|
+
data.tar.gz: 92882c7e0804167fc28e945f34a22f2f22cb8ae89422b9449a780c2becb95ed2463df1af8c585a8df186e705c40853bc784d80b0b61a505ade43d1795a2c3f5a
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
inherit_gem:
|
2
|
+
syntax_tree: config/rubocop.yml
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
NewCops: enable
|
6
|
+
TargetRubyVersion: 3.0
|
7
|
+
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Lint/ScriptPermission:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Metrics:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/GuardClause:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Naming/MethodParameterName:
|
21
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in voicevox.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rubocop", "~> 1.35"
|
11
|
+
|
12
|
+
gem "steep", "~> 1.1"
|
13
|
+
|
14
|
+
gem "reline", "~> 0.3.1"
|
15
|
+
|
16
|
+
gem "syntax_tree", "~> 5.2"
|
17
|
+
gem "syntax_tree-rbs", "~> 0.5.1"
|
18
|
+
|
19
|
+
gem "rspec", "~> 3.11"
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Nanashi. <https://sevenc7c.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# voicevox.rb / voicevox_coreの非公式ラッパー
|
2
|
+
|
3
|
+
voicevox.rbは[VOICEVOX/voicevox_core](https://github.com/VOICEVOX/voicevox_core)の非公式ラッパーです。
|
4
|
+
|
5
|
+
```rb
|
6
|
+
dict_path = ENV["OPENJTALK_DICT_PATH"]
|
7
|
+
vv = Voicevox.new(dict_path, load_all_models: false)
|
8
|
+
character = Voicevox.characters[0].styles[0]
|
9
|
+
character.load
|
10
|
+
print "> "
|
11
|
+
text = gets.chomp
|
12
|
+
data = vv.tts(text, character)
|
13
|
+
|
14
|
+
File.write("#{__dir__}/outputs/#{Process.pid}_#{i}.wav", data, mode: "wb")
|
15
|
+
```
|
16
|
+
|
17
|
+
## 使い方
|
18
|
+
|
19
|
+
環境に合ったvoicevox_coreのライブラリをダウンロードし、Rubyから参照できるようにしてください。
|
20
|
+
|
21
|
+
Windows環境の場合は、[RubyInstaller2のwiki](https://github.com/oneclick/rubyinstaller2/wiki/For-gem-developers#-dll-loading)を参照してください。
|
22
|
+
|
23
|
+
### 高レベルAPI
|
24
|
+
|
25
|
+
Voicevoxクラスには高レベルなAPIがあります。
|
26
|
+
|
27
|
+
サンプル:[examples/repl_wrapper.rb](./examples/repl_wrapper.rb)
|
28
|
+
|
29
|
+
### 低レベルAPI
|
30
|
+
|
31
|
+
Voicevox::Coreに[ffi/ffi](https://github.com/ffi/ffi)で包んだだけのAPIがあります。
|
32
|
+
型情報は[sig/voicevox/core.rbs](./sig/voicevox/core.rbs)を参照してください。
|
33
|
+
|
34
|
+
サンプル:[examples/repl_core.rb](./examples/repl_core.rb)
|
35
|
+
|
36
|
+
## インストール
|
37
|
+
|
38
|
+
```
|
39
|
+
gem install voicevox.rb
|
40
|
+
|
41
|
+
bundle add voicevox.rb
|
42
|
+
```
|
43
|
+
|
44
|
+
## ライセンス
|
45
|
+
|
46
|
+
MITライセンスが適用されています。[LICENSE](./LICENSE)を参照してください。
|
data/Rakefile
ADDED
data/Steepfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
D = Steep::Diagnostic
|
4
|
+
|
5
|
+
target :lib do
|
6
|
+
signature "sig"
|
7
|
+
|
8
|
+
check "lib" # Directory name
|
9
|
+
# check "Gemfile" # File name
|
10
|
+
# check "app/models/**/*.rb" # Glob
|
11
|
+
# ignore "lib/templates/*.rb"
|
12
|
+
|
13
|
+
# library "pathname", "set" # Standard libraries
|
14
|
+
# library "strong_json" # Gems
|
15
|
+
|
16
|
+
# configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
|
17
|
+
configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
|
18
|
+
# configure_code_diagnostics do |hash| # You can setup everything yourself
|
19
|
+
# hash[D::Ruby::NoMethod] = :information
|
20
|
+
# end
|
21
|
+
end
|
22
|
+
|
23
|
+
# target :test do
|
24
|
+
# signature "sig", "sig-private"
|
25
|
+
#
|
26
|
+
# check "test"
|
27
|
+
#
|
28
|
+
# # library "pathname", "set" # Standard libraries
|
29
|
+
# end
|
data/examples/cli.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ref: https://github.com/VOICEVOX/voicevox_core/blob/main/example/python/run.py
|
4
|
+
|
5
|
+
require "voicevox"
|
6
|
+
require "optparse"
|
7
|
+
|
8
|
+
def main(use_gpu:, text:, speaker_id:, cpu_num_threads:, openjtalk_dict:)
|
9
|
+
# コアの初期化
|
10
|
+
vv = Voicevox.new(openjtalk_dict, use_gpu: use_gpu, threads: cpu_num_threads, load_all_models: false)
|
11
|
+
|
12
|
+
# 話者のロード
|
13
|
+
vv.load_model(speaker_id)
|
14
|
+
|
15
|
+
# 音声合成
|
16
|
+
wavefmt = vv.tts(text, speaker_id)
|
17
|
+
|
18
|
+
# 保存
|
19
|
+
File.write("#{text}-#{speaker_id}.wav", wavefmt, mode: "wb")
|
20
|
+
|
21
|
+
vv.finalize
|
22
|
+
end
|
23
|
+
|
24
|
+
if __FILE__ == $PROGRAM_NAME
|
25
|
+
options = {
|
26
|
+
use_gpu: false,
|
27
|
+
text: nil,
|
28
|
+
speaker_id: nil,
|
29
|
+
cpu_num_threads: 0,
|
30
|
+
openjtalk_dict: "open_jtalk_dic_utf_8-1.11"
|
31
|
+
}
|
32
|
+
parser = OptionParser.new
|
33
|
+
parser.on("--[no-]use_gpu") { |v| options[:use_gpu] = v }
|
34
|
+
parser.on("--text [TEXT]", String) { |v| options[:text] = v }
|
35
|
+
parser.on("--speaker_id [ID]", Integer) { |v| options[:speaker_id] = v }
|
36
|
+
parser.on("--cpu_num_threads [THREADS]", Integer) do |v|
|
37
|
+
options[:cpu_num_threads] = v if v
|
38
|
+
end
|
39
|
+
parser.on("--openjtalk_dict [PATH]", String) do |v|
|
40
|
+
options[:openjtalk_dict] = v if v
|
41
|
+
end
|
42
|
+
parser.parse!
|
43
|
+
if options.values.any?(&:nil?)
|
44
|
+
raise OptParse::MissingArgument,
|
45
|
+
options.filter { |_k, v| v.nil? }.keys.join(", ")
|
46
|
+
end
|
47
|
+
main(**options)
|
48
|
+
end
|
File without changes
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "voicevox"
|
4
|
+
require "reline"
|
5
|
+
|
6
|
+
dict_path =
|
7
|
+
ENV.fetch("OPENJTALK_DICT") do
|
8
|
+
raise("OPENJTALK_DICTを設定してください。") unless Voicevox.voicevox_path
|
9
|
+
|
10
|
+
"#{Voicevox.voicevox_path}/pyopenjtalk/open_jtalk_dic_utf_8-1.11"
|
11
|
+
end
|
12
|
+
print "== 初期化中... "
|
13
|
+
options = Voicevox::Core.voicevox_make_default_initialize_options
|
14
|
+
options[:openjtalk_dict_path] = FFI::MemoryPointer.from_string(dict_path)
|
15
|
+
Voicevox::Core.voicevox_initialize(options)
|
16
|
+
Voicevox::Core.voicevox_load_model(0)
|
17
|
+
|
18
|
+
puts "完了"
|
19
|
+
i = 0
|
20
|
+
loop do
|
21
|
+
text = Reline.readline("> ")
|
22
|
+
break unless text
|
23
|
+
|
24
|
+
print "生成中... "
|
25
|
+
|
26
|
+
size_ptr = FFI::MemoryPointer.new(:int)
|
27
|
+
return_ptr = FFI::MemoryPointer.new(:pointer)
|
28
|
+
Voicevox::Core.voicevox_tts(
|
29
|
+
text,
|
30
|
+
0,
|
31
|
+
Voicevox::Core.voicevox_make_default_tts_options,
|
32
|
+
size_ptr,
|
33
|
+
return_ptr
|
34
|
+
)
|
35
|
+
print "完了:#{size_ptr.read_int}バイト、アドレス:#{return_ptr.read_pointer.address.to_s(16)}"
|
36
|
+
data_ptr = return_ptr.read_pointer
|
37
|
+
data = data_ptr.read_string(size_ptr.read_int)
|
38
|
+
|
39
|
+
size_ptr.free
|
40
|
+
Voicevox::Core.voicevox_wav_free(data_ptr)
|
41
|
+
|
42
|
+
i += 1
|
43
|
+
File.write("#{__dir__}/outputs/#{Process.pid}_#{i}.wav", data, mode: "wb")
|
44
|
+
puts "、#{Process.pid}_#{i}.wav"
|
45
|
+
end
|
46
|
+
print "\nファイナライズ中... "
|
47
|
+
Voicevox::Core.voicevox_finalize
|
48
|
+
puts "完了"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "voicevox"
|
4
|
+
require "reline"
|
5
|
+
|
6
|
+
dict_path =
|
7
|
+
ENV.fetch("OPENJTALK_DICT") do
|
8
|
+
raise "OPENJTALK_DICTを設定してください。" unless Voicevox.voicevox_path
|
9
|
+
"#{Voicevox.voicevox_path}/pyopenjtalk/open_jtalk_dic_utf_8-1.11"
|
10
|
+
end
|
11
|
+
print "== 初期化中... "
|
12
|
+
vv = Voicevox.new(dict_path, load_all_models: false)
|
13
|
+
character = Voicevox.characters[0].styles[0]
|
14
|
+
character.load
|
15
|
+
|
16
|
+
puts "完了:#{vv.gpu? ? "GPU" : "CPU"}モード"
|
17
|
+
i = 0
|
18
|
+
loop do
|
19
|
+
text = Reline.readline("> ")
|
20
|
+
break unless text
|
21
|
+
|
22
|
+
print "生成中... "
|
23
|
+
|
24
|
+
data = vv.tts(text, character)
|
25
|
+
print "完了:#{data.bytesize}バイト"
|
26
|
+
|
27
|
+
i += 1
|
28
|
+
File.write("#{__dir__}/outputs/#{Process.pid}_#{i}.wav", data, mode: "wb")
|
29
|
+
puts "、#{Process.pid}_#{i}.wav"
|
30
|
+
end
|
31
|
+
print "\nファイナライズ中... "
|
32
|
+
vv.finalize
|
33
|
+
puts "完了"
|