Skip to content

Commit

Permalink
Windows c++サンプル修正 (VOICEVOX#420)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroshiba <[email protected]>
Co-authored-by: shigobu <[email protected]>
Co-authored-by: kasamatsu <[email protected]>
  • Loading branch information
4 people authored Feb 12, 2023
1 parent 9592bae commit aad2dcf
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 52 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,43 @@ jobs:
cmake -S . -B build
cmake --build build
build-windows-cpp-example:
strategy:
fail-fast: false
runs-on: windows-latest
env:
# Path to the solution file relative to the root of the project.
SOLUTION_FILE_PATH: example\cpp\windows\windows_example.sln
# Configuration type to build.
BUILD_CONFIGURATION: Debug

steps:
- uses: actions/checkout@v3
- name: Set up Rust
uses: ./.github/actions/rust-toolchain-from-file
- name: Install cargo-binstall
uses: taiki-e/install-action@cargo-binstall
- name: Install cbindgen
uses: ./.github/actions/cargo-binstall-cbindgen
- name: build voicevox_core_c_api
run: cargo build -p voicevox_core_c_api -vv
- name: voicevox_core.hを生成
run: cbindgen --crate voicevox_core_c_api -o ./example/cpp/windows/simple_tts/voicevox_core.h
- name: 必要なfileをexampleのディレクトリに移動させる
run: |
mkdir example/cpp/windows/simple_tts/lib/x64
cp target/debug/voicevox_core.dll.lib example/cpp/windows/simple_tts/lib/x64/voicevox_core.lib
- name: Add MSBuild to PATH
uses: microsoft/[email protected]
- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore ${{env.SOLUTION_FILE_PATH}}

- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}

build-python-api:
strategy:
fail-fast: false
Expand Down
67 changes: 35 additions & 32 deletions example/cpp/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,56 @@ Visual Studio Installerを使用しインストールしてください。

出力フォルダを作成するために、一度ビルドします。「windows_example.sln」をVisual Studioで開き、メニューの「ビルド」→「ソリューションのビルド」を押します。
この段階では、ビルドは失敗します。「bin」フォルダと「lib」フォルダが生成されていればOKです。
Releasesから「voicevox_core-windows-x64-cpu-{バージョン名}.zip」をダウンロードし、展開します。
展開してできたファイルをそれぞれ下記のフォルダへ配置します
[Releases](https://github.com/VOICEVOX/voicevox_core/releases/latest)から「voicevox_core-windows-x64-cpu-{バージョン名}.zip」をダウンロードし、展開します[ダウンローダー](https://github.com/VOICEVOX/voicevox_core/blob/main/docs/downloads/download.md)を使うと便利です
展開してできたファイル・フォルダをそれぞれ下記のフォルダへ配置します

- simple_tts に配置
- core.h
- voicevox_core.h

- simple_tts\bin\x64\Debug に配置
- core.dll
- voicevox_core.dll
- onnxruntime.dll
- onnxruntime_providers_shared.dll
- modelフォルダ

- simple_tts\lib\x64 に配置
- core.lib
- voicevox_core.lib

もう一度ビルドします。今度は成功するはずです。失敗した場合は、「core.lib」の場所を確認してください。
もう一度ビルドします。今度は成功するはずです。失敗した場合は、「voicevox_core.lib」の場所を確認してください。

続いて、「Open JTalk辞書フォルダ」を配置します。
http://open-jtalk.sourceforge.net/ を開き、Dictionary for Open JTalk 欄の Binary Package (UTF-8)をクリックして「open_jtalk_dic_utf_8-1.11.tar.gz」をダウンロードします。
続いて、「Open JTalk辞書フォルダ」を配置します。
ダウンローダーを使用した場合、展開されたフォルダに含まれています。
ダウンローダーを使用していない場合は、http://open-jtalk.sourceforge.net/ を開き、Dictionary for Open JTalk 欄の Binary Package (UTF-8)をクリックして「open_jtalk_dic_utf_8-1.11.tar.gz」をダウンロードします。

展開してできた「open_jtalk_dic_utf_8-1.11」フォルダをフォルダごと「simple_tts\bin\x64\Debug」に配置します。

最終的には以下のようなフォルダ構成になっているはずです
最終的に、以下のようなフォルダ構成になっているはずです
```
simple_tts
│ core.h
│ simple_tts.cpp
│ simple_tts.h
│ simple_tts.vcxproj
│ simple_tts.vcxproj.filters
│ simple_tts.vcxproj.user
├─bin
│ └─x64
│ └─Debug
│ │ core.dll
│ │ onnxruntime.dll
│ │ onnxruntime_providers_shared.dll
│ │ simple_tts.exe
│ │ simple_tts.pdb
│ │
│ └─open_jtalk_dic_utf_8-1.11
└─lib
└─x64
│ core.lib
└─Debug
│ simple_tts.cpp
│ simple_tts.h
│ simple_tts.vcxproj
│ simple_tts.vcxproj.filters
│ simple_tts.vcxproj.user
│ voicevox_core.h
├─bin
│ └─x64
│ └─Debug
│ │ onnxruntime.dll
│ │ onnxruntime_providers_shared.dll
│ │ simple_tts.exe
│ │ simple_tts.pdb
│ │ voicevox_core.dll
│ │
│ ├─model
│ └─open_jtalk_dic_utf_8-1.11
└─lib
└─x64
│ voicevox_core.lib
└─Debug
```

### 実行
Expand Down
32 changes: 17 additions & 15 deletions example/cpp/windows/simple_tts/simple_tts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <vector>
#include <fstream>

#include "core.h"
#include "voicevox_core.h"

#define OPENJTALK_DICT_NAME L"open_jtalk_dic_utf_8-1.11"

Expand All @@ -28,26 +28,26 @@ int main() {
std::wcin >> speak_words;

std::wcout << L"coreの初期化中" << std::endl;
if (!initialize(false, 0, true)) {
std::wcout << L"coreの初期化に失敗しました" << std::endl;
return 0;
}

VoicevoxResultCode result = VoicevoxResultCode::VOICEVOX_RESULT_SUCCEED;

std::wcout << L"openjtalk辞書の読み込み" << std::endl;
result = voicevox_load_openjtalk_dict(GetOpenJTalkDict().c_str());
if (result != VoicevoxResultCode::VOICEVOX_RESULT_SUCCEED) {
VoicevoxInitializeOptions initializeOptions = voicevox_make_default_initialize_options();
std::string dict = GetOpenJTalkDict();
initializeOptions.open_jtalk_dict_dir = dict.c_str();
initializeOptions.load_all_models = true;

VoicevoxResultCode result = VoicevoxResultCode::VOICEVOX_RESULT_OK;
result = voicevox_initialize(initializeOptions);
if (result != VoicevoxResultCode::VOICEVOX_RESULT_OK) {
OutErrorMessage(result);
return 0;
}

std::wcout << L"音声生成中" << std::endl;
int64_t speaker_id = 0;
int output_binary_size = 0;
int32_t speaker_id = 0;
uintptr_t output_binary_size = 0;
uint8_t* output_wav = nullptr;
result = voicevox_tts(wide_to_utf8_cppapi(speak_words).c_str(), speaker_id, &output_binary_size, &output_wav);
if (result != VoicevoxResultCode::VOICEVOX_RESULT_SUCCEED) {
VoicevoxTtsOptions ttsOptions = voicevox_make_default_tts_options();

result = voicevox_tts(wide_to_utf8_cppapi(speak_words).c_str(), speaker_id, ttsOptions, &output_binary_size, &output_wav);
if (result != VoicevoxResultCode::VOICEVOX_RESULT_OK) {
OutErrorMessage(result);
return 0;
}
Expand All @@ -65,6 +65,8 @@ int main() {
std::wcout << L"音声データの開放" << std::endl;
voicevox_wav_free(output_wav);

voicevox_finalize();

}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion example/cpp/windows/simple_tts/simple_tts.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <iostream>
#include "core.h"
#include "voicevox_core.h"

std::string GetOpenJTalkDict();
std::wstring GetWaveFileName();
Expand Down
8 changes: 4 additions & 4 deletions example/cpp/windows/simple_tts/simple_tts.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Shlwapi.lib;Pathcch.lib;Winmm.lib;core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Shlwapi.lib;Pathcch.lib;Winmm.lib;voicevox_core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)lib\$(Platform)\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -120,7 +120,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Shlwapi.lib;Pathcch.lib;Winmm.lib;core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Shlwapi.lib;Pathcch.lib;Winmm.lib;voicevox_core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)lib\$(Platform)\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -135,7 +135,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Shlwapi.lib;Pathcch.lib;Winmm.lib;core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Shlwapi.lib;Pathcch.lib;Winmm.lib;voicevox_core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)lib\$(Platform)\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -154,7 +154,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Shlwapi.lib;Pathcch.lib;Winmm.lib;core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Shlwapi.lib;Pathcch.lib;Winmm.lib;voicevox_core.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)lib\$(Platform)\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand Down

0 comments on commit aad2dcf

Please sign in to comment.