Skip to content

Commit a310360

Browse files
authored
UTF-8文字列と勘違いしていたため、VoiceModelIdが壊れていた (#204)
uuidみたいに他の人が扱っていなければinterface上変わりないのでbreakingにはならない…はず…
1 parent 2ef1128 commit a310360

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public ResultCode UnloadVoiceModel(string modelId)
7272
{
7373
unsafe
7474
{
75-
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(modelId))
75+
fixed (byte* ptr = NativeUuid.ToUUIDv4ByteArray(modelId))
7676
{
7777
return CoreUnsafe.voicevox_synthesizer_unload_voice_model((VoicevoxSynthesizer*)Handle, ptr).FromNative();
7878
}
@@ -94,7 +94,7 @@ public bool IsLoadedVoiceModel(string modelId)
9494
{
9595
unsafe
9696
{
97-
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(modelId))
97+
fixed (byte* ptr = NativeUuid.ToUUIDv4ByteArray(modelId))
9898
{
9999
return CoreUnsafe.voicevox_synthesizer_is_loaded_voice_model((VoicevoxSynthesizer*)Handle, ptr);
100100
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public string Id
7575
{
7676
byte* ptr = stackalloc byte[16];
7777
CoreUnsafe.voicevox_voice_model_file_id((VoicevoxVoiceModelFile*)Handle, ptr);
78-
return StringConvertCompat.ToUTF8String(ptr);
78+
return NativeUuid.ToUUIDv4(ptr);
7979
}
8080
}
8181
}

src/VoicevoxCoreSharp.Core/Synthesizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public ResultCode UnloadVoiceModel(string modelId)
7272
{
7373
unsafe
7474
{
75-
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(modelId))
75+
fixed (byte* ptr = NativeUuid.ToUUIDv4ByteArray(modelId))
7676
{
7777
return CoreUnsafe.voicevox_synthesizer_unload_voice_model((VoicevoxSynthesizer*)Handle, ptr).FromNative();
7878
}
@@ -94,7 +94,7 @@ public bool IsLoadedVoiceModel(string modelId)
9494
{
9595
unsafe
9696
{
97-
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(modelId))
97+
fixed (byte* ptr = NativeUuid.ToUUIDv4ByteArray(modelId))
9898
{
9999
return CoreUnsafe.voicevox_synthesizer_is_loaded_voice_model((VoicevoxSynthesizer*)Handle, ptr);
100100
}

src/VoicevoxCoreSharp.Core/VoiceModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public string Id
7575
{
7676
byte* ptr = stackalloc byte[16];
7777
CoreUnsafe.voicevox_voice_model_file_id((VoicevoxVoiceModelFile*)Handle, ptr);
78-
return StringConvertCompat.ToUTF8String(ptr);
78+
return NativeUuid.ToUUIDv4(ptr);
7979
}
8080
}
8181
}

tests/VoicevoxCoreSharp.Core.Tests/SynthesizerTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,25 @@ public void Tts()
3333
Assert.True(wavLength > 0);
3434
Assert.NotNull(wav);
3535
}
36+
37+
[Fact]
38+
public void VoiceModelLoaded()
39+
{
40+
OpenJtalk.New(Consts.OpenJTalkDictDir, out var openJtalk);
41+
var initializeOptions = InitializeOptions.Default();
42+
var onnxruntimeOptions = new LoadOnnxruntimeOptions(Path.Join(AppContext.BaseDirectory, Helper.GetOnnxruntimeAssemblyName()));
43+
if (Onnxruntime.LoadOnce(onnxruntimeOptions, out var onnruntime) != ResultCode.RESULT_OK)
44+
{
45+
Assert.Fail("Failed to initialize onnxruntime");
46+
}
47+
Synthesizer.New(onnruntime, openJtalk, initializeOptions, out var synthesizer);
48+
49+
VoiceModelFile.Open(Consts.SampleVoiceModel, out var voiceModel);
50+
synthesizer.LoadVoiceModel(voiceModel);
51+
52+
Assert.True(synthesizer.IsLoadedVoiceModel(voiceModel.Id));
53+
synthesizer.UnloadVoiceModel(voiceModel.Id);
54+
Assert.False(synthesizer.IsLoadedVoiceModel(voiceModel.Id));
55+
}
3656
}
3757
}

0 commit comments

Comments
 (0)