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

Fix up cmake builds and workflow for windows including required sourc… #9

Open
wants to merge 1 commit into
base: workflow
Choose a base branch
from
Open
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
56 changes: 50 additions & 6 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Windows

on:
workflow_dispatch:
inputs:
debugArchive:
type: boolean
description: Get a full debug archive even if failed.
push:
branches: [ master ]
pull_request:
Expand All @@ -27,17 +31,57 @@ jobs:
repository: rhasspy/espeak-ng
path: espeak-ng
- name: configure-espeak
run: cd espeak-ng && cmake -Bbuild -DUSE_ASYNC:BOOL=OFF -DBUILD_SHARED_LIBS:BOOL=${{ matrix.shlib }} -A ${{ matrix.arch }} -DUSE_MBROLA:BOOL=OFF -DUSE_LIBSONIC:BOOL=OFF -DUSE_LIBPCAUDIO:BOOL=OFF -DUSE_KLATT:BOOL=OFF -DUSE_SPEECHPLAYER:BOOL=OFF -DEXTRA_cmn:BOOL=ON -DEXTRA_ru:BOOL=ON
run: |
cd espeak-ng &&
cmake -Bbuild -DUSE_ASYNC:BOOL=OFF -DBUILD_SHARED_LIBS:BOOL=${{ matrix.shlib }} -A ${{ matrix.arch }} -DUSE_MBROLA:BOOL=OFF -DUSE_LIBSONIC:BOOL=OFF -DUSE_LIBPCAUDIO:BOOL=OFF -DUSE_KLATT:BOOL=OFF -DUSE_SPEECHPLAYER:BOOL=OFF -DEXTRA_cmn:BOOL=ON -DEXTRA_ru:BOOL=ON
- name: make-espeak
run: cd espeak-ng && cmake --build build --config ${{ matrix.config }}
run: |
cd espeak-ng
cmake --build build --config ${{ matrix.config }}
- name: install-espeak
run: cd espeak-ng && cmake --install build --prefix "$PWD"
run: |
cd espeak-ng
cmake --install build --prefix "${{ github.workspace }}/espeak-ng-install"
- uses: actions/checkout@v3
with:
path: piper-phonemize
- name: prepare-onnxruntime
run: curl -L -o onnxruntime.zip 'https://github.com/microsoft/onnxruntime/releases/download/v1.14.1/onnxruntime-win-x64-1.14.1.zip' && unzip onnxruntime.zip && mkdir -p piper-phonemize/lib/Windows-x86_64 && mv onnxruntime-* piper-phonemize/lib/Windows-x86_64/onnxruntime
run: |
cd piper-phonemize
curl -L -o onnxruntime.zip 'https://github.com/microsoft/onnxruntime/releases/download/v1.14.1/onnxruntime-win-x64-1.14.1.zip'
unzip onnxruntime.zip
mkdir -p lib/Windows-AMD64
mv onnxruntime-* lib/Windows-AMD64/onnxruntime
- name: configure-piper
run: cd piper-phonemize && env:PKG_CONFIG_PATH="${PWD}/espeak-ng/lib/pkgconfig" && cmake -Bbuild
run: |
cd piper-phonemize
$env:ESPEAK_PREFIX_DIR = "${{ github.workspace }}/espeak-ng-install"
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=lib/Windows-AMD64
- name: make-piper
run: cd piper-phonemize && cmake --build build --config ${{ matrix.config }}
run: |
cd piper-phonemize
cmake --build build --config ${{ matrix.config }}
- name: bundle-library
run: |
cd piper-phonemize
$env:CMAKE_INSTALL_BINDIR = "lib/Windows-AMD64/"
cmake --install build
- name: bundle
run: |
cd piper-phonemize
mkdir -p lib/Windows-AMD64/espeak-ng/build
mv ${{ github.workspace }}/espeak-ng-install/lib lib/Windows-AMD64/espeak-ng/build
cp ${{ github.workspace }}/espeak-ng-install/bin/* lib/Windows-AMD64/espeak-ng/build/lib/
rm -r -fo build
rm -r -fo onnxruntime.zip
- name: Archive Files
uses: actions/upload-artifact@v2
with:
name: readyforwheel
path: piper-phonemize/
- name: Debug Archive
uses: actions/upload-artifact@v2
if: always() && github.event.inputs.debugArchive == 'true'
with:
name: debug
path: ./
23 changes: 17 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,27 @@ project(
LANGUAGES CXX
)

string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")
if(MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true)
string(APPEND CMAKE_CXX_FLAGS " /W4 /utf-8")
string(APPEND CMAKE_C_FLAGS " /W4 /utf-8")

find_library(ESPEAK_NG_LIBRARIES espeak-ng HINTS "$ENV{ESPEAK_PREFIX_DIR}/lib")
find_path(ESPEAK_NG_LIBRARY_DIRS NAMES espeak-ng.lib PATH_SUFFIXES lib HINTS "$ENV{ESPEAK_PREFIX_DIR}")
find_path(ESPEAK_NG_INCLUDE_DIRS NAMES espeak-ng/espeak_ng.h PATH_SUFFIXES include HINTS "$ENV{ESPEAK_PREFIX_DIR}")
else()
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")

find_package(PkgConfig)
pkg_check_modules(ESPEAK_NG REQUIRED espeak-ng<2)
endif()

# lib/Linux-x86_64
# lib/Linux-aarch64
set(ONNXRUNTIME_ROOTDIR ${CMAKE_CURRENT_LIST_DIR}/lib/${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}/onnxruntime)

# ---- espeak-ng ---

find_package(PkgConfig)
pkg_check_modules(ESPEAK_NG REQUIRED espeak-ng<2)

# ---- Declare library ----

Expand Down Expand Up @@ -76,7 +86,8 @@ target_include_directories(

target_link_directories(
piper_phonemize_exe PUBLIC
${ESPEAK_NG_LIBRARY_DIRS}
piper_phonemize
${ESPEAK_NG_LIBRARY_DIRS}
)

target_link_libraries(piper_phonemize_exe PUBLIC
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

_DIR = Path(__file__).parent
_ESPEAK_DIR = _DIR / "espeak-ng" / "build"
_LIB_DIR = _DIR / "lib" / f"Linux-{platform.machine()}"
_LIB_DIR = _DIR / "lib" / f"{platform.system()}-{platform.machine()}"
_ONNXRUNTIME_DIR = _LIB_DIR / "onnxruntime"
_PHONEMIZE_WIN_BUILD = _LIB_DIR / "piper_phonemize""

__version__ = "1.2.0"

Expand All @@ -22,9 +23,9 @@
"src/tashkeel.cpp",
],
define_macros=[("VERSION_INFO", __version__)],
include_dirs=[str(_ESPEAK_DIR / "include"), str(_ONNXRUNTIME_DIR / "include")],
library_dirs=[str(_ESPEAK_DIR / "lib"), str(_ONNXRUNTIME_DIR / "lib")],
libraries=["espeak-ng", "onnxruntime"],
include_dirs=[str(_ESPEAK_DIR / "include"), str(_ONNXRUNTIME_DIR / "include"), str(_PHONEMIZE_WIN_BUILD, "include")],
library_dirs=[str(_ESPEAK_DIR / "lib"), str(_ONNXRUNTIME_DIR / "lib"), str(_PHONEMIZE_WIN_BUILD, "lib"), str(_PHONEMIZE_WIN_BUILD, "bin")],
libraries=["espeak-ng", "onnxruntime", "piper_phonemize"],
),
]

Expand Down
18 changes: 15 additions & 3 deletions src/phoneme_ids.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

#include "phonemize.hpp"

// Basically cmake export all symbols in windows still requires
// explicit export of data symbols
#if defined(_WIN32)
#ifdef piper_phonemize_EXPORTS
#define API_DATA __declspec(dllexport)
#else
#define API_DATA __declspec(dllimport)
#endif
#else
#define API
#endif

namespace piper {

typedef int64_t PhonemeId;
Expand All @@ -31,9 +43,9 @@ struct PhonemeIdConfig {
std::shared_ptr<PhonemeIdMap> phonemeIdMap;
};

extern const size_t MAX_PHONEMES;
extern PhonemeIdMap DEFAULT_PHONEME_ID_MAP;
extern std::map<std::string, PhonemeIdMap> DEFAULT_ALPHABET;
extern API_DATA const size_t MAX_PHONEMES;
extern API_DATA PhonemeIdMap DEFAULT_PHONEME_ID_MAP;
extern API_DATA std::map<std::string, PhonemeIdMap> DEFAULT_ALPHABET;

void phonemes_to_ids(const std::vector<Phoneme> &phonemes,
PhonemeIdConfig &config,
Expand Down
9 changes: 8 additions & 1 deletion src/tashkeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ void tashkeel_load(std::string modelPath, State &state) {
instanceName.c_str());
state.env.DisableTelemetryEvents();
state.options.SetExecutionMode(ExecutionMode::ORT_PARALLEL);
state.onnx = Ort::Session(state.env, modelPath.c_str(), state.options);
#ifdef _WIN32 // This is defined for Windows
std::wstring wModelPath(modelPath.begin(), modelPath.end());
state.onnx = Ort::Session(state.env, wModelPath.c_str(), state.options);
#else // This is for Linux
state.onnx = Ort::Session(state.env, modelPath.c_str(), state.options);
#endif


}

std::string tashkeel_run(std::string text, State &state) {
Expand Down