Skip to content

Commit 2cfb826

Browse files
authored
Update submodule(voicevox_core 0.16.4対応) (#264)
* Update submodule * make generate * 追加されたenumの対応 * Add impl * Asyncサポートも対応 * Add sing test * 不要なパラメータがargsにあった
1 parent 98a19f2 commit 2cfb826

12 files changed

Lines changed: 1051 additions & 42 deletions

File tree

binding/voicevox_core

Submodule voicevox_core updated 47 files

src/VoicevoxCoreSharp.Core.Unity/Runtime/Script/Enum/ResultCode.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ public enum ResultCode : int
113113
/// </summary>
114114
RESULT_INVALID_MORA_ERROR = 30,
115115
/// <summary>
116+
/// 無効な楽譜
117+
/// </summary>
118+
RESULT_INVALID_SCORE_ERROR = 31,
119+
/// <summary>
120+
/// 無効なノート
121+
/// </summary>
122+
RESULT_INVALID_NOTE_ERROR = 32,
123+
/// <summary>
124+
/// 無効なFrameAudioQuery
125+
/// </summary>
126+
RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR = 33,
127+
/// <summary>
128+
/// 無効なFramePhoneme
129+
/// </summary>
130+
RESULT_INVALID_FRAME_PHONEME_ERROR = 34,
131+
/// <summary>
116132
/// 楽譜とFrameAudioQueryの組み合わせが不正
117133
/// </summary>
118134
RESULT_INCOMPATIBLE_QUERIES_ERROR = 35,
@@ -151,6 +167,10 @@ internal static ResultCode FromNative(this VoicevoxResultCode code)
151167
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR => ResultCode.RESULT_INVALID_USER_DICT_WORD_ERROR,
152168
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_UUID_ERROR => ResultCode.RESULT_INVALID_UUID_ERROR,
153169
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_MORA_ERROR => ResultCode.RESULT_INVALID_MORA_ERROR,
170+
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_SCORE_ERROR => ResultCode.RESULT_INVALID_SCORE_ERROR,
171+
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_NOTE_ERROR => ResultCode.RESULT_INVALID_NOTE_ERROR,
172+
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR => ResultCode.RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR,
173+
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_FRAME_PHONEME_ERROR => ResultCode.RESULT_INVALID_FRAME_PHONEME_ERROR,
154174
VoicevoxResultCode.VOICEVOX_RESULT_INCOMPATIBLE_QUERIES_ERROR => ResultCode.RESULT_INCOMPATIBLE_QUERIES_ERROR,
155175
};
156176
#pragma warning restore CS8524
@@ -187,6 +207,10 @@ internal static VoicevoxResultCode ToNative(this ResultCode code)
187207
ResultCode.RESULT_INVALID_USER_DICT_WORD_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR,
188208
ResultCode.RESULT_INVALID_UUID_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_UUID_ERROR,
189209
ResultCode.RESULT_INVALID_MORA_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_MORA_ERROR,
210+
ResultCode.RESULT_INVALID_SCORE_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_SCORE_ERROR,
211+
ResultCode.RESULT_INVALID_NOTE_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_NOTE_ERROR,
212+
ResultCode.RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR,
213+
ResultCode.RESULT_INVALID_FRAME_PHONEME_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_FRAME_PHONEME_ERROR,
190214
ResultCode.RESULT_INCOMPATIBLE_QUERIES_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INCOMPATIBLE_QUERIES_ERROR,
191215
};
192216
#pragma warning restore CS8524

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

Lines changed: 279 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 124 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -360,34 +360,138 @@ public ResultCode TtsFromKana(string kana, uint styleId, TtsOptions options, out
360360
unsafe
361361
{
362362
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(kana))
363+
fixed (nuint* ptr2 = &outputWavLength)
363364
{
364-
fixed (nuint* ptr2 = &outputWavLength)
365-
{
366-
var nativeOptions = options.ToNative();
367-
byte* resultWavPtr;
365+
var nativeOptions = options.ToNative();
366+
byte* resultWavPtr;
368367

369-
var result = CoreUnsafe.voicevox_synthesizer_tts_from_kana((VoicevoxSynthesizer*)Handle, ptr, styleId, nativeOptions, ptr2, &resultWavPtr);
370-
if (result == VoicevoxResultCode.VOICEVOX_RESULT_OK)
368+
var result = CoreUnsafe.voicevox_synthesizer_tts_from_kana((VoicevoxSynthesizer*)Handle, ptr, styleId, nativeOptions, ptr2, &resultWavPtr);
369+
if (result == VoicevoxResultCode.VOICEVOX_RESULT_OK)
370+
{
371+
var i = 0;
372+
var outputWavLengthInt = (int)outputWavLength;
373+
var outputWavTmp = new byte[outputWavLength];
374+
while (i < outputWavLengthInt)
371375
{
372-
var i = 0;
373-
var outputWavLengthInt = (int)outputWavLength;
374-
var outputWavTmp = new byte[outputWavLength];
375-
while (i < outputWavLengthInt)
376-
{
377-
outputWavTmp[i] = resultWavPtr[i];
378-
i++;
379-
}
380-
outputWav = outputWavTmp;
381-
CoreUnsafe.voicevox_wav_free(resultWavPtr);
376+
outputWavTmp[i] = resultWavPtr[i];
377+
i++;
382378
}
383-
else
379+
outputWav = outputWavTmp;
380+
CoreUnsafe.voicevox_wav_free(resultWavPtr);
381+
}
382+
else
383+
{
384+
outputWav = null;
385+
}
386+
387+
return result.FromNative();
388+
}
389+
}
390+
}
391+
392+
public ResultCode CreateSingFrameAudioQuery(string scoreJson, uint styleId, out string? frameAudioQueryJson)
393+
{
394+
unsafe
395+
{
396+
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(scoreJson))
397+
{
398+
byte* resultJsonPtr;
399+
400+
var result = CoreUnsafe.voicevox_synthesizer_create_sing_frame_audio_query((VoicevoxSynthesizer*)Handle, ptr, styleId, &resultJsonPtr).FromNative();
401+
if (result == ResultCode.RESULT_OK)
402+
{
403+
frameAudioQueryJson = StringConvertCompat.ToUTF8String(resultJsonPtr);
404+
CoreUnsafe.voicevox_json_free(resultJsonPtr);
405+
}
406+
else
407+
{
408+
frameAudioQueryJson = null;
409+
}
410+
411+
return result;
412+
}
413+
}
414+
}
415+
416+
public ResultCode CreateSingFrameF0(string scoreJson, string frameAudioQueryJson, uint styleId, out string? f0Json)
417+
{
418+
unsafe
419+
{
420+
fixed (byte* scoreJsonPtr = System.Text.Encoding.UTF8.GetBytes(scoreJson))
421+
fixed (byte* frameAudioQueryJsonPtr = System.Text.Encoding.UTF8.GetBytes(frameAudioQueryJson))
422+
{
423+
byte* resultJsonPtr;
424+
425+
var result = CoreUnsafe.voicevox_synthesizer_create_sing_frame_f0((VoicevoxSynthesizer*)Handle, scoreJsonPtr, frameAudioQueryJsonPtr, styleId, &resultJsonPtr).FromNative();
426+
if (result == ResultCode.RESULT_OK)
427+
{
428+
f0Json = StringConvertCompat.ToUTF8String(resultJsonPtr);
429+
CoreUnsafe.voicevox_json_free(resultJsonPtr);
430+
}
431+
else
432+
{
433+
f0Json = null;
434+
}
435+
436+
return result;
437+
}
438+
}
439+
}
440+
441+
public ResultCode CreateSingFrameVolume(string scoreJson, string frameAudioQueryJson, uint styleId, out string? volumeJson)
442+
{
443+
unsafe
444+
{
445+
fixed (byte* scoreJsonPtr = System.Text.Encoding.UTF8.GetBytes(scoreJson))
446+
fixed (byte* frameAudioQueryJsonPtr = System.Text.Encoding.UTF8.GetBytes(frameAudioQueryJson))
447+
{
448+
byte* resultJsonPtr;
449+
450+
var result = CoreUnsafe.voicevox_synthesizer_create_sing_frame_volume((VoicevoxSynthesizer*)Handle, scoreJsonPtr, frameAudioQueryJsonPtr, styleId, &resultJsonPtr).FromNative();
451+
if (result == ResultCode.RESULT_OK)
452+
{
453+
volumeJson = StringConvertCompat.ToUTF8String(resultJsonPtr);
454+
CoreUnsafe.voicevox_json_free(resultJsonPtr);
455+
}
456+
else
457+
{
458+
volumeJson = null;
459+
}
460+
461+
return result;
462+
}
463+
}
464+
}
465+
466+
public ResultCode FrameSynthesis(string frameAudioQueryJson, uint styleId, out nuint outputWavLength, out byte[]? outputWav)
467+
{
468+
unsafe
469+
{
470+
fixed (byte* frameAudioQueryJsonPtr = System.Text.Encoding.UTF8.GetBytes(frameAudioQueryJson))
471+
fixed (nuint* ptr2 = &outputWavLength)
472+
{
473+
byte* resultWavPtr;
474+
475+
var result = CoreUnsafe.voicevox_synthesizer_frame_synthesis((VoicevoxSynthesizer*)Handle, frameAudioQueryJsonPtr, styleId, ptr2, &resultWavPtr);
476+
if (result == VoicevoxResultCode.VOICEVOX_RESULT_OK)
477+
{
478+
var i = 0;
479+
var outputWavLengthInt = (int)outputWavLength;
480+
var outputWavTmp = new byte[outputWavLengthInt];
481+
while (i < outputWavLengthInt)
384482
{
385-
outputWav = null;
483+
outputWavTmp[i] = resultWavPtr[i];
484+
i++;
386485
}
387-
388-
return result.FromNative();
486+
outputWav = outputWavTmp;
487+
CoreUnsafe.voicevox_wav_free(resultWavPtr);
488+
}
489+
else
490+
{
491+
outputWav = null;
389492
}
390493

494+
return result.FromNative();
391495
}
392496
}
393497
}

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,76 @@ public static ResultCode ValidateMora(string moraJson)
9999
}
100100
}
101101
}
102+
103+
/// <returns>
104+
/// <see cref="ResultCode.RESULT_OK"/> または <see cref="ResultCode.RESULT_INVALID_SCORE_ERROR"/>
105+
/// </returns>
106+
public static ResultCode ValidateScore(string scoreJson)
107+
{
108+
unsafe
109+
{
110+
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(scoreJson))
111+
{
112+
return CoreUnsafe.voicevox_score_validate(ptr).FromNative();
113+
}
114+
}
115+
}
116+
117+
/// <returns>
118+
/// <see cref="ResultCode.RESULT_OK"/> または <see cref="ResultCode.RESULT_INVALID_NOTE_ERROR"/>
119+
/// </returns>
120+
public static ResultCode ValidateNote(string noteJson)
121+
{
122+
unsafe
123+
{
124+
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(noteJson))
125+
{
126+
return CoreUnsafe.voicevox_note_validate(ptr).FromNative();
127+
}
128+
}
129+
}
130+
131+
/// <returns>
132+
/// <see cref="ResultCode.RESULT_OK"/> または <see cref="ResultCode.RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR"/>
133+
/// </returns>
134+
public static ResultCode ValidateFrameAudioQuery(string frameAudioQueryJson)
135+
{
136+
unsafe
137+
{
138+
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(frameAudioQueryJson))
139+
{
140+
return CoreUnsafe.voicevox_frame_audio_query_validate(ptr).FromNative();
141+
}
142+
}
143+
}
144+
145+
/// <returns>
146+
/// <see cref="ResultCode.RESULT_OK"/> または <see cref="ResultCode.RESULT_INVALID_FRAME_PHONEME_ERROR"/>
147+
/// </returns>
148+
public static ResultCode ValidateFramePhoneme(string framePhonemeJson)
149+
{
150+
unsafe
151+
{
152+
fixed (byte* ptr = System.Text.Encoding.UTF8.GetBytes(framePhonemeJson))
153+
{
154+
return CoreUnsafe.voicevox_frame_phoneme_validate(ptr).FromNative();
155+
}
156+
}
157+
}
158+
159+
/// <returns>
160+
/// <see cref="ResultCode.RESULT_OK"/> または <see cref="ResultCode.RESULT_INVALID_SCORE_ERROR"/>, <see cref="ResultCode.RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR"/>, <see cref="ResultCode.RESULT_INCOMPATIBLE_QUERIES_ERROR"/>
161+
/// </returns>
162+
public static ResultCode EnsureCompatible(string scoreJson, string frameAudioQueryJson)
163+
{
164+
unsafe
165+
{
166+
fixed (byte* scorePtr = System.Text.Encoding.UTF8.GetBytes(scoreJson))
167+
fixed (byte* frameAudioQueryPtr = System.Text.Encoding.UTF8.GetBytes(frameAudioQueryJson))
168+
{
169+
return CoreUnsafe.voicevox_ensure_compatible(scorePtr, frameAudioQueryPtr).FromNative();
170+
}
171+
}
172+
}
102173
}
103174
}

src/VoicevoxCoreSharp.Core/Enum/ResultCode.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ public enum ResultCode : int
113113
/// </summary>
114114
RESULT_INVALID_MORA_ERROR = 30,
115115
/// <summary>
116+
/// 無効な楽譜
117+
/// </summary>
118+
RESULT_INVALID_SCORE_ERROR = 31,
119+
/// <summary>
120+
/// 無効なノート
121+
/// </summary>
122+
RESULT_INVALID_NOTE_ERROR = 32,
123+
/// <summary>
124+
/// 無効なFrameAudioQuery
125+
/// </summary>
126+
RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR = 33,
127+
/// <summary>
128+
/// 無効なFramePhoneme
129+
/// </summary>
130+
RESULT_INVALID_FRAME_PHONEME_ERROR = 34,
131+
/// <summary>
116132
/// 楽譜とFrameAudioQueryの組み合わせが不正
117133
/// </summary>
118134
RESULT_INCOMPATIBLE_QUERIES_ERROR = 35,
@@ -151,6 +167,10 @@ internal static ResultCode FromNative(this VoicevoxResultCode code)
151167
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR => ResultCode.RESULT_INVALID_USER_DICT_WORD_ERROR,
152168
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_UUID_ERROR => ResultCode.RESULT_INVALID_UUID_ERROR,
153169
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_MORA_ERROR => ResultCode.RESULT_INVALID_MORA_ERROR,
170+
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_SCORE_ERROR => ResultCode.RESULT_INVALID_SCORE_ERROR,
171+
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_NOTE_ERROR => ResultCode.RESULT_INVALID_NOTE_ERROR,
172+
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR => ResultCode.RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR,
173+
VoicevoxResultCode.VOICEVOX_RESULT_INVALID_FRAME_PHONEME_ERROR => ResultCode.RESULT_INVALID_FRAME_PHONEME_ERROR,
154174
VoicevoxResultCode.VOICEVOX_RESULT_INCOMPATIBLE_QUERIES_ERROR => ResultCode.RESULT_INCOMPATIBLE_QUERIES_ERROR,
155175
};
156176
#pragma warning restore CS8524
@@ -187,6 +207,10 @@ internal static VoicevoxResultCode ToNative(this ResultCode code)
187207
ResultCode.RESULT_INVALID_USER_DICT_WORD_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_USER_DICT_WORD_ERROR,
188208
ResultCode.RESULT_INVALID_UUID_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_UUID_ERROR,
189209
ResultCode.RESULT_INVALID_MORA_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_MORA_ERROR,
210+
ResultCode.RESULT_INVALID_SCORE_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_SCORE_ERROR,
211+
ResultCode.RESULT_INVALID_NOTE_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_NOTE_ERROR,
212+
ResultCode.RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_FRAME_AUDIO_QUERY_ERROR,
213+
ResultCode.RESULT_INVALID_FRAME_PHONEME_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INVALID_FRAME_PHONEME_ERROR,
190214
ResultCode.RESULT_INCOMPATIBLE_QUERIES_ERROR => VoicevoxResultCode.VOICEVOX_RESULT_INCOMPATIBLE_QUERIES_ERROR,
191215
};
192216
#pragma warning restore CS8524

0 commit comments

Comments
 (0)