Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

localディレクトリに配置するようにしたので、cliのサンプルプロジェクトで使えるように #89

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ publish/aot/osx-arm64:
validate/memory/osx-arm64: RESULT=result.txt
validate/memory/osx-arm64:
leaks --atExit -- ./bin/Release/net8.0/osx-arm64/publish/cli Hello > $(RESULT)

run/.local: TEXT=
run/.local:
dotnet run "$(TEXT)" --resource=../../.local/voicevox_core -p CoreBasePath=../../.local/voicevox_core
12 changes: 8 additions & 4 deletions examples/cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
const string OutputWavName = "audio.wav";
const uint StyleId = 0;

static int RunTts(string text)
static int RunTts(string text, string? resourcePath = "voicevox_core")
{
var openJTalkDictPath = "voicevox_core/open_jtalk_dic_utf_8-1.11";
var openJTalkDictPath = $"{resourcePath}/open_jtalk_dic_utf_8-1.11";

Console.WriteLine("coreの初期化中");

Expand All @@ -35,7 +35,7 @@ static int RunTts(string text)
var matcher = new Matcher();
matcher.AddIncludePatterns(new[] { "*.vvm" });

foreach (var path in matcher.GetResultsInFullPath("./voicevox_core/model"))
foreach (var path in matcher.GetResultsInFullPath($"{resourcePath}/model"))
{
result = VoiceModel.New(path, out var voiceModel);
if (result != ResultCode.RESULT_OK)
Expand Down Expand Up @@ -82,10 +82,14 @@ static int RunTts(string text)
{
text
};

var resourcePath = new Option<string>("--resource", "リソースディレクトリパス");
command.AddOption(resourcePath);
command.SetHandler((context) =>
{
var textValue = context.ParseResult.GetValueForArgument(text);
returnCode = RunTts(textValue);
var resourceValue = context.ParseResult.GetValueForOption(resourcePath);
returnCode = RunTts(textValue, resourceValue);
});
returnCode = command.Invoke(args);

Expand Down
16 changes: 10 additions & 6 deletions examples/cli/cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<StripSymbols>false</StripSymbols> -->
</PropertyGroup>

<PropertyGroup>
<CoreBasePath>voicevox_core</CoreBasePath>
</PropertyGroup>

<Choose>
<When Condition="$([MSBuild]::IsOsPlatform('OSX')) And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">
<PropertyGroup>
Expand Down Expand Up @@ -72,14 +76,14 @@
see: https://learn.microsoft.com/en-us/dotnet/core/compatibility/deployment/8.0/rid-asset-list
-->
<ItemGroup Label="Copy libvoicevox_core">
<Content Include="voicevox_core\libvoicevox_core.dylib" TargetPath="libvoicevox_core.dylib" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('OSX'))" />
<Content Include="voicevox_core\libvoicevox_core.so" TargetPath="libvoicevox_core.so" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('Linux'))" />
<Content Include="voicevox_core\voicevox_core.dll" TargetPath="voicevox_core.dll" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('Windows'))" />
<Content Include="$(CoreBasePath)\libvoicevox_core.dylib" TargetPath="libvoicevox_core.dylib" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('OSX'))" />
<Content Include="$(CoreBasePath)\libvoicevox_core.so" TargetPath="libvoicevox_core.so" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('Linux'))" />
<Content Include="$(CoreBasePath)\voicevox_core.dll" TargetPath="voicevox_core.dll" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('Windows'))" />
</ItemGroup>
<ItemGroup Label="Copy own libonnxruntime" Condition="$(UseNugetOnnxRuntime) != 'true'">
<Content Include="voicevox_core\libonnxruntime.$(VoicevoxOnnxRuntimeVersion).dylib" TargetPath="libonnxruntime.$(VoicevoxOnnxRuntimeVersion).dylib" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('OSX'))" />
<Content Include="voicevox_core\libonnxruntime.so.$(VoicevoxOnnxRuntimeVersion)" TargetPath="libonnxruntime.so.$(VoicevoxOnnxRuntimeVersion)" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('Linux'))" />
<Content Include="onnxruntime.$(VoicevoxOnnxRuntimeVersion).dll" TargetPath="onnxruntime.$(VoicevoxOnnxRuntimeVersion).dll" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('Windows'))" />
<Content Include="$(CoreBasePath)\libonnxruntime.$(VoicevoxOnnxRuntimeVersion).dylib" TargetPath="libonnxruntime.$(VoicevoxOnnxRuntimeVersion).dylib" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('OSX'))" />
<Content Include="$(CoreBasePath)\libonnxruntime.so.$(VoicevoxOnnxRuntimeVersion)" TargetPath="libonnxruntime.so.$(VoicevoxOnnxRuntimeVersion)" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('Linux'))" />
<Content Include="$(CoreBasePath)\onnxruntime.$(VoicevoxOnnxRuntimeVersion).dll" TargetPath="onnxruntime.$(VoicevoxOnnxRuntimeVersion).dll" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('Windows'))" />
</ItemGroup>
<ItemGroup Label="Copy Nuget provided libonnxruntime" Condition="$(UseNugetOnnxRuntime) == 'true'">
<Content Include="$(OutputPath)runtimes\$(_MyRuntimeIdentifier)\native\libonnxruntime.dylib" TargetPath="libonnxruntime.$(VoicevoxOnnxRuntimeVersion).dylib" Visible="false" CopyToOutputDirectory="PreserveNewest" Condition="$([MSBuild]::IsOsPlatform('OSX'))" />
Expand Down
Loading