Skip to content

Commit 771c3b0

Browse files
authored
Update submodule (#299)
* Update submodule * make generateのhash replaceが一部状態で動かない状態なので修正 * make generate * 新しいシグネチャに合わせてコードとサンプル、テストの書き換え * fix sample code
1 parent 7af3a57 commit 771c3b0

18 files changed

Lines changed: 283 additions & 20 deletions

File tree

binding/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ generate:
55
$(MAKE) replace-hash
66

77
replace-hash:
8-
$(eval VERSION := $(shell cat ../.git/modules/binding/voicevox_core/HEAD))
9-
$(shell sed -i.bak 's/<VoicevoxCoreCommitHash>.*<\/VoicevoxCoreCommitHash>/<VoicevoxCoreCommitHash>$(VERSION)<\/VoicevoxCoreCommitHash>/' ../src/VoicevoxCoreSharp.Core/VoicevoxCoreSharp.Core.Metas.props)
8+
$(eval VERSION := $(shell git -C voicevox_core rev-parse HEAD))
9+
$(shell sed -i.bak 's|<VoicevoxCoreCommitHash>.*</VoicevoxCoreCommitHash>|<VoicevoxCoreCommitHash>$(VERSION)</VoicevoxCoreCommitHash>|' ../src/VoicevoxCoreSharp.Core/VoicevoxCoreSharp.Core.Metas.props)
1010

1111
build/dev-library:
1212
cd voicevox_core; cargo build --release -p voicevox_core_c_api --features load-onnxruntime -F voicevox_core/buildtime-download-onnxruntime

binding/voicevox_core

Submodule voicevox_core updated 48 files

examples/UnitySample/Assets/SampleVoicevoxCoreSharpScript.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.IO;
@@ -50,7 +50,7 @@ void Start()
5050
return;
5151
}
5252

53-
result = synthesizer.LoadVoiceModel(voiceModel);
53+
result = synthesizer.LoadVoiceModel(voiceModel, LoadVoiceModelOptions.Default());
5454
if (result != ResultCode.RESULT_OK)
5555
{
5656
Debug.LogError(result.ToMessage());

examples/cli/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System.CommandLine;
22
using System.CommandLine.Parsing;
33
using Microsoft.Extensions.FileSystemGlobbing;
4-
54
using VoicevoxCoreSharp.Core;
6-
using VoicevoxCoreSharp.Core.Struct;
75
using VoicevoxCoreSharp.Core.Enum;
6+
using VoicevoxCoreSharp.Core.Struct;
87

98
const string OutputWavName = "audio.wav";
109
const uint StyleId = 0;
@@ -50,7 +49,7 @@ static int RunTts(string text, string? resourcePath = "voicevox_core")
5049
return 1;
5150
}
5251

53-
result = synthesizer.LoadVoiceModel(voiceModel);
52+
result = synthesizer.LoadVoiceModel(voiceModel, LoadVoiceModelOptions.Default());
5453
if (result != ResultCode.RESULT_OK)
5554
{
5655
Console.Error.WriteLine(result.ToMessage());
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using VoicevoxCoreSharp.Core.Native;
3+
4+
namespace VoicevoxCoreSharp.Core.Enum
5+
{
6+
/// <summary>
7+
/// ::voicevox_synthesizer_load_voice_model の実行時に、同じIDの ::VoicevoxVoiceModelFile が既に読み込まれていたときのふるまい。
8+
/// </summary>
9+
public enum OnExistingVoiceModelId : int
10+
{
11+
/// <summary>
12+
/// エラーにする。デフォルトのふるまい
13+
/// </summary>
14+
VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_ERROR = 0,
15+
/// <summary>
16+
/// 再読み込みする。VOICEVOX COREでは、長文のテキストを一度に音声合成するとCPU/GPUメモリが大量に占有されたままになる。再読み込みを行うとメモリの使用量が元に戻る
17+
/// </summary>
18+
VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_RELOAD = 1,
19+
/// <summary>
20+
/// 何もしない
21+
/// </summary>
22+
VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_SKIP = 2,
23+
}
24+
25+
internal static class OnExistingVoiceModelIdExt
26+
{
27+
public static OnExistingVoiceModelId FromNative(this VoicevoxOnExistingVoiceModelId mode)
28+
{
29+
#pragma warning disable CS8524
30+
return mode switch
31+
{
32+
VoicevoxOnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_ERROR => OnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_ERROR,
33+
VoicevoxOnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_RELOAD => OnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_RELOAD,
34+
VoicevoxOnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_SKIP => OnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_SKIP,
35+
};
36+
#pragma warning restore CS8524
37+
}
38+
39+
public static VoicevoxOnExistingVoiceModelId ToNative(this OnExistingVoiceModelId mode)
40+
{
41+
#pragma warning disable CS8524
42+
return mode switch
43+
{
44+
OnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_ERROR => VoicevoxOnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_ERROR,
45+
OnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_RELOAD => VoicevoxOnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_RELOAD,
46+
OnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_SKIP => VoicevoxOnExistingVoiceModelId.VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_SKIP,
47+
};
48+
#pragma warning restore CS8524
49+
}
50+
}
51+
}

src/VoicevoxCoreSharp.Core.Unity/Runtime/Script/Enum/OnExistingVoiceModelId.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/VoicevoxCoreSharp.Core.Unity/Runtime/Script/Native/CoreUnsafe.g.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,18 +535,28 @@ internal static unsafe partial class CoreUnsafe
535535
[DllImport(__DllName, EntryPoint = "voicevox_synthesizer_delete", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
536536
internal static extern void voicevox_synthesizer_delete(VoicevoxSynthesizer* synthesizer);
537537

538+
/// <summary>
539+
/// デフォルトの `voicevox_synthesizer_load_voice_model` のオプションを生成する
540+
/// @return デフォルト値が設定された `voicevox_synthesizer_load_voice_model` のオプション
541+
///
542+
/// \no-orig-impl{voicevox_make_default_load_voice_model_options}
543+
/// </summary>
544+
[DllImport(__DllName, EntryPoint = "voicevox_make_default_load_voice_model_options", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
545+
internal static extern VoicevoxLoadVoiceModelOptions voicevox_make_default_load_voice_model_options();
546+
538547
/// <summary>
539548
/// 音声モデルを読み込む。
540549
///
541550
/// @param [in] synthesizer 音声シンセサイザ
542551
/// @param [in] model 音声モデル
552+
/// @param [in] options オプション
543553
///
544554
/// @returns 結果コード
545555
///
546556
/// \orig-impl{voicevox_synthesizer_load_voice_model}
547557
/// </summary>
548558
[DllImport(__DllName, EntryPoint = "voicevox_synthesizer_load_voice_model", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
549-
internal static extern VoicevoxResultCode voicevox_synthesizer_load_voice_model(VoicevoxSynthesizer* synthesizer, VoicevoxVoiceModelFile* model);
559+
internal static extern VoicevoxResultCode voicevox_synthesizer_load_voice_model(VoicevoxSynthesizer* synthesizer, VoicevoxVoiceModelFile* model, VoicevoxLoadVoiceModelOptions options);
550560

551561
/// <summary>
552562
/// 音声モデルの読み込みを解除する。
@@ -1374,6 +1384,12 @@ internal unsafe partial struct VoicevoxSynthesizer
13741384
{
13751385
}
13761386

1387+
[StructLayout(LayoutKind.Sequential)]
1388+
internal unsafe partial struct VoicevoxLoadVoiceModelOptions
1389+
{
1390+
public VoicevoxOnExistingVoiceModelId on_existing;
1391+
}
1392+
13771393
[StructLayout(LayoutKind.Sequential)]
13781394
internal unsafe partial struct VoicevoxSynthesisOptions
13791395
{
@@ -1437,6 +1453,13 @@ internal enum VoicevoxResultCode : int
14371453
VOICEVOX_RESULT_INCOMPATIBLE_QUERIES_ERROR = 35,
14381454
}
14391455

1456+
internal enum VoicevoxOnExistingVoiceModelId : int
1457+
{
1458+
VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_ERROR = 0,
1459+
VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_RELOAD = 1,
1460+
VOICEVOX_ON_EXISTING_VOICE_MODEL_ID_SKIP = 2,
1461+
}
1462+
14401463
internal enum VoicevoxAccelerationMode : int
14411464
{
14421465
VOICEVOX_ACCELERATION_MODE_AUTO = 0,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using VoicevoxCoreSharp.Core.Enum;
3+
using VoicevoxCoreSharp.Core.Native;
4+
5+
namespace VoicevoxCoreSharp.Core.Struct
6+
{
7+
/// <summary>
8+
/// ::voicevox_synthesizer_load_voice_model のオプション。
9+
/// </summary>
10+
public struct LoadVoiceModelOptions
11+
{
12+
/// <summary>
13+
/// 同じIDの ::VoicevoxVoiceModelFile が既に読み込まれていたときのふるまい
14+
/// </summary>
15+
public OnExistingVoiceModelId OnExisting { get; set; }
16+
17+
public static LoadVoiceModelOptions Default()
18+
{
19+
return LoadVoiceModelOptionsDefault.Value;
20+
}
21+
}
22+
23+
internal static class LoadVoiceModelOptionsDefault
24+
{
25+
public static readonly LoadVoiceModelOptions Value = CoreUnsafe.voicevox_make_default_load_voice_model_options().FromNative();
26+
}
27+
28+
internal static class LoadVoiceModelOptionsExt
29+
{
30+
internal static VoicevoxLoadVoiceModelOptions ToNative(this LoadVoiceModelOptions loadVoiceModelOptions)
31+
{
32+
return new VoicevoxLoadVoiceModelOptions
33+
{
34+
on_existing = loadVoiceModelOptions.OnExisting.ToNative()
35+
};
36+
}
37+
38+
internal static LoadVoiceModelOptions FromNative(this VoicevoxLoadVoiceModelOptions loadVoiceModelOptions)
39+
{
40+
return new LoadVoiceModelOptions
41+
{
42+
OnExisting = loadVoiceModelOptions.on_existing.FromNative()
43+
};
44+
}
45+
}
46+
}

src/VoicevoxCoreSharp.Core.Unity/Runtime/Script/Struct/LoadVoiceModelOptions.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/VoicevoxCoreSharp.Core.Unity/Runtime/Script/Synthesizer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ public static ResultCode New(Onnxruntime onnxruntime, OpenJtalk openJtalk, Initi
6060
}
6161
}
6262

63-
public ResultCode LoadVoiceModel(VoiceModelFile voiceModel)
63+
public ResultCode LoadVoiceModel(VoiceModelFile voiceModel, LoadVoiceModelOptions options)
6464
{
6565
unsafe
6666
{
67-
return CoreUnsafe.voicevox_synthesizer_load_voice_model((VoicevoxSynthesizer*)Handle, (VoicevoxVoiceModelFile*)voiceModel.Handle).FromNative();
67+
var loadVoiceModelOptions = options.ToNative();
68+
return CoreUnsafe.voicevox_synthesizer_load_voice_model((VoicevoxSynthesizer*)Handle, (VoicevoxVoiceModelFile*)voiceModel.Handle, loadVoiceModelOptions).FromNative();
6869
}
6970
}
7071

0 commit comments

Comments
 (0)