audio/piper: Fast and local text to speech system

Pull Request:	https://github.com/freebsd/freebsd-ports/pull/406
Co-authored-by:	Gleb Popov <arrowd@FreeBSD.org>
This commit is contained in:
Kenneth Raplee
2025-06-17 10:27:55 +03:00
committed by Gleb Popov
parent 945407e8ec
commit dd0a412dfa
6 changed files with 233 additions and 0 deletions
+1
View File
@@ -594,6 +594,7 @@
SUBDIR += pianod2
SUBDIR += picard
SUBDIR += picard-plugins
SUBDIR += piper
SUBDIR += piper-phonemize
SUBDIR += pipewire-module-xrdp
SUBDIR += pipewire-spa-oss
+27
View File
@@ -0,0 +1,27 @@
PORTNAME= piper
DISTVERSION= 2023.11.14
DISTVERSIONSUFFIX= -2
CATEGORIES= audio
MAINTAINER= kenrap@kennethraplee.com
COMMENT= Fast, local text to speech system
WWW= https://rhasspy.github.io/piper-samples/
LICENSE= MIT
LICENSE_FILE= ${WRKSRC}/LICENSE.md
LIB_DEPENDS= libespeak-ng.so:audio/espeak-ng \
libfmt.so:devel/libfmt \
libonnxruntime.so:misc/onnxruntime \
libpiper_phonemize.so:audio/piper-phonemize \
libspdlog.so:devel/spdlog
USES= compiler:c++17-lang cmake localbase pkgconfig tar:xz xorg
USE_XORG= x11
USE_GITHUB= yes
GH_ACCOUNT= rhasspy
PLIST_FILES= bin/piper
.include <bsd.port.mk>
+3
View File
@@ -0,0 +1,3 @@
TIMESTAMP = 1750142677
SHA256 (rhasspy-piper-2023.11.14-2_GH0.tar.gz) = 8b684e102cfe23af097830db9555a8641f17735725853c531a1daeb34b6ed1a8
SIZE (rhasspy-piper-2023.11.14-2_GH0.tar.gz) = 25602353
+139
View File
@@ -0,0 +1,139 @@
--- CMakeLists.txt.orig 2023-11-14 17:55:22 UTC
+++ CMakeLists.txt
@@ -13,7 +13,7 @@ if(MSVC)
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
elseif(NOT APPLE)
# Linux flags
- string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
+ string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")
endif()
@@ -25,7 +25,7 @@ add_executable(test_piper src/cpp/test.cpp src/cpp/piper.cpp)
# ---- fmt ---
-if(NOT DEFINED FMT_DIR)
+if(FALSE)
set(FMT_VERSION "10.0.0")
set(FMT_DIR "${CMAKE_CURRENT_BINARY_DIR}/fi")
@@ -43,7 +43,7 @@ endif()
# ---- spdlog ---
-if(NOT DEFINED SPDLOG_DIR)
+if(FALSE)
set(SPDLOG_DIR "${CMAKE_CURRENT_BINARY_DIR}/si")
set(SPDLOG_VERSION "1.12.0")
ExternalProject_Add(
@@ -58,7 +58,13 @@ endif()
# ---- piper-phonemize ---
-if(NOT DEFINED PIPER_PHONEMIZE_DIR)
+find_package(PkgConfig)
+pkg_check_modules(FMT REQUIRED fmt)
+pkg_check_modules(ONNXRUNTIME REQUIRED libonnxruntime)
+pkg_check_modules(PIPER_PHONEMIZE REQUIRED piper_phonemize)
+pkg_check_modules(SPDLOG REQUIRED spdlog)
+
+if(FALSE)
set(PIPER_PHONEMIZE_DIR "${CMAKE_CURRENT_BINARY_DIR}/pi")
ExternalProject_Add(
piper_phonemize_external
@@ -74,9 +80,8 @@ endif()
if((NOT MSVC) AND (NOT APPLE))
# Linux flags
- string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
+ string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")
- target_link_libraries(piper -static-libgcc -static-libstdc++)
set(PIPER_EXTRA_LIBRARIES "pthread")
endif()
@@ -91,18 +96,18 @@ target_link_libraries(piper
)
target_link_directories(piper PUBLIC
- ${FMT_DIR}/lib
- ${SPDLOG_DIR}/lib
- ${PIPER_PHONEMIZE_DIR}/lib
+ ${FMT_LIBRARY_DIRS}
+ ${SPDLOG_LIBRARY_DIRS}
+ ${ONNXRUNTIME_LIBRARY_DIRS}
)
target_include_directories(piper PUBLIC
- ${FMT_DIR}/include
- ${SPDLOG_DIR}/include
- ${PIPER_PHONEMIZE_DIR}/include
+ ${FMT_INCLUDE_DIRS}
+ ${SPDLOG_INCLUDE_DIRS}
+ ${ONNXRUNTIME_INCLUDE_DIRS}
)
-target_compile_definitions(piper PUBLIC _PIPER_VERSION=${piper_version})
+target_compile_definitions(piper PUBLIC _PIPER_VERSION="${piper_version}")
# ---- Declare test ----
include(CTest)
@@ -116,16 +121,16 @@ target_compile_features(test_piper PUBLIC cxx_std_17)
target_include_directories(
test_piper PUBLIC
- ${FMT_DIR}/include
- ${SPDLOG_DIR}/include
- ${PIPER_PHONEMIZE_DIR}/include
+ ${FMT_INCLUDE_DIRS}
+ ${SPDLOG_INCLUDE_DIRS}
+ ${ONNXRUNTIME_INCLUDE_DIRS}
)
target_link_directories(
test_piper PUBLIC
- ${FMT_DIR}/lib
- ${SPDLOG_DIR}/lib
- ${PIPER_PHONEMIZE_DIR}/lib
+ ${FMT_LIBRARY_DIRS}
+ ${SPDLOG_LIBRARY_DIRS}
+ ${ONNXRUNTIME_LIBRARY_DIRS}
)
target_link_libraries(test_piper PUBLIC
@@ -140,33 +145,5 @@ target_link_libraries(test_piper PUBLIC
install(
TARGETS piper
- DESTINATION ${CMAKE_INSTALL_PREFIX})
-
-# Dependencies
-install(
- DIRECTORY ${PIPER_PHONEMIZE_DIR}/bin/
- DESTINATION ${CMAKE_INSTALL_PREFIX}
- USE_SOURCE_PERMISSIONS # keep +x
- FILES_MATCHING
- PATTERN "piper_phonemize"
- PATTERN "espeak-ng"
- PATTERN "*.dll"
-)
-
-install(
- DIRECTORY ${PIPER_PHONEMIZE_DIR}/lib/
- DESTINATION ${CMAKE_INSTALL_PREFIX}
- FILES_MATCHING
- PATTERN "*.dll"
- PATTERN "*.so*"
-)
-
-install(
- DIRECTORY ${PIPER_PHONEMIZE_DIR}/share/espeak-ng-data
- DESTINATION ${CMAKE_INSTALL_PREFIX}
-)
-
-install(
- FILES ${PIPER_PHONEMIZE_DIR}/share/libtashkeel_model.ort
- DESTINATION ${CMAKE_INSTALL_PREFIX}
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)
+61
View File
@@ -0,0 +1,61 @@
--- src/cpp/piper.cpp.orig
+++ src/cpp/piper.cpp
@@ -6,7 +6,7 @@
#include <stdexcept>
#include <espeak-ng/speak_lib.h>
-#include <onnxruntime_cxx_api.h>
+#include <onnxruntime/onnxruntime_cxx_api.h>
#include <spdlog/spdlog.h>
#include "json.hpp"
@@ -229,22 +229,6 @@ void initialize(PiperConfig &config) {
spdlog::debug("Initialized eSpeak");
}
- // Load onnx model for libtashkeel
- // https://github.com/mush42/libtashkeel/
- if (config.useTashkeel) {
- spdlog::debug("Using libtashkeel for diacritization");
- if (!config.tashkeelModelPath) {
- throw std::runtime_error("No path to libtashkeel model");
- }
-
- spdlog::debug("Loading libtashkeel model from {}",
- config.tashkeelModelPath.value());
- config.tashkeelState = std::make_unique<tashkeel::State>();
- tashkeel::tashkeel_load(config.tashkeelModelPath.value(),
- *config.tashkeelState);
- spdlog::debug("Initialized libtashkeel");
- }
-
spdlog::info("Initialized piper");
}
@@ -447,15 +431,6 @@ void textToAudio(PiperConfig &config, Voice &voice, std::string text,
voice.synthesisConfig.sampleRate * voice.synthesisConfig.channels);
}
- if (config.useTashkeel) {
- if (!config.tashkeelState) {
- throw std::runtime_error("Tashkeel model is not loaded");
- }
-
- spdlog::debug("Diacritizing text with libtashkeel: {}", text);
- text = tashkeel::tashkeel_run(text, *config.tashkeelState);
- }
-
// Phonemes for each sentence
spdlog::debug("Phonemizing text: {}", text);
std::vector<std::vector<Phoneme>> phonemes;
--- src/cpp/piper.hpp.orig
+++ src/cpp/piper.hpp
@@ -8,7 +8,7 @@
#include <string>
#include <vector>
-#include <onnxruntime_cxx_api.h>
+#include <onnxruntime/onnxruntime_cxx_api.h>
#include <piper-phonemize/phoneme_ids.hpp>
#include <piper-phonemize/phonemize.hpp>
#include <piper-phonemize/tashkeel.hpp>
+2
View File
@@ -0,0 +1,2 @@
A fast, local neural text to speech system that sounds great and is optimized
for the Raspberry Pi 4. Piper is used in a variety of projects.