Start work on getting rid of piper code and only using the model data

The inference code if a few hundred lines anyway, piper is unmaintained
and forked and the fork depends on the gigantic python ONNXRuntime
bindings. Just write the few hundred lines myself.
This commit is contained in:
Kovid Goyal 2025-07-23 17:27:47 +05:30
parent 920b87ac2b
commit c46e58d479
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 60 additions and 0 deletions

View File

@ -153,6 +153,8 @@ uchardet_inc_dirs, uchardet_lib_dirs, uchardet_libs = [], [], ['uchardet']
openssl_inc_dirs, openssl_lib_dirs = [], [] openssl_inc_dirs, openssl_lib_dirs = [], []
piper_inc_dirs, piper_lib_dirs, piper_libs = [], [], []
ICU = sw = '' ICU = sw = ''
if iswindows: if iswindows:
@ -211,6 +213,10 @@ else:
uchardet_inc_dirs = pkgconfig_include_dirs('uchardet', '', '/usr/include/uchardet') uchardet_inc_dirs = pkgconfig_include_dirs('uchardet', '', '/usr/include/uchardet')
uchardet_lib_dirs = pkgconfig_lib_dirs('uchardet', '', '/usr/lib') uchardet_lib_dirs = pkgconfig_lib_dirs('uchardet', '', '/usr/lib')
uchardet_libs = pkgconfig_libs('uchardet', '', '') uchardet_libs = pkgconfig_libs('uchardet', '', '')
piper_inc_dirs = pkgconfig_include_dirs('espeak-ng', '', '/usr/include') + pkgconfig_include_dirs(
'libonnxruntime', '', '/usr/include/onnxruntime')
piper_lib_dirs = pkgconfig_lib_dirs('espeak-ng', '', '/usr/lib') + pkgconfig_lib_dirs('libonnxruntime', '', '/usr/lib')
piper_libs = pkgconfig_libs('espeak-ng', '', 'espeak-ng') + pkgconfig_libs('libonnxruntime', '', 'onnxruntime')
for x in ('libavcodec', 'libavformat', 'libavdevice', 'libavfilter', 'libavutil', 'libpostproc', 'libswresample', 'libswscale'): for x in ('libavcodec', 'libavformat', 'libavdevice', 'libavfilter', 'libavutil', 'libpostproc', 'libswresample', 'libswscale'):
for inc in pkgconfig_include_dirs(x, '', '/usr/include'): for inc in pkgconfig_include_dirs(x, '', '/usr/include'):
if inc and inc not in ffmpeg_inc_dirs: if inc and inc not in ffmpeg_inc_dirs:

View File

@ -134,6 +134,14 @@
"error": "!podofo_error", "error": "!podofo_error",
"needs_c++": "17" "needs_c++": "17"
}, },
{
"name": "piper",
"sources": "calibre/utils/tts/piper.cpp",
"needs_c++": "17",
"libraries": "!piper_libs",
"lib_dirs": "!piper_lib_dirs",
"inc_dirs": "!piper_inc_dirs"
},
{ {
"name": "html_as_json", "name": "html_as_json",
"sources": "calibre/srv/html_as_json.cpp", "sources": "calibre/srv/html_as_json.cpp",

View File

@ -258,6 +258,7 @@ class ExtensionsImporter:
'rcc_backend', 'rcc_backend',
'icu', 'icu',
'speedup', 'speedup',
'piper',
'html_as_json', 'html_as_json',
'fast_css_transform', 'fast_css_transform',
'fast_html_entities', 'fast_html_entities',

View File

View File

@ -0,0 +1,39 @@
/*
* piper.cpp
* Copyright (C) 2025 Kovid Goyal <kovid at kovidgoyal.net>
*
* Distributed under terms of the GPL3 license.
*/
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <espeak-ng/speak_lib.h>
static PyObject*
phonemize(PyObject *self, PyObject *args) {
Py_RETURN_NONE;
}
// Boilerplate {{{
static char doc[] = "Text to speech using the Piper TTS models";
static PyMethodDef methods[] = {
{"phonemize", (PyCFunction)phonemize, METH_VARARGS,
"Convert the specified text into espeak-ng phonemes"
},
{NULL} /* Sentinel */
};
static int
exec_module(PyObject *mod) { return 0; }
static PyModuleDef_Slot slots[] = { {Py_mod_exec, (void*)exec_module}, {0, NULL} };
static struct PyModuleDef module_def = {PyModuleDef_HEAD_INIT};
CALIBRE_MODINIT_FUNC PyInit_piper(void) {
module_def.m_name = "piper";
module_def.m_slots = slots;
module_def.m_doc = doc;
module_def.m_methods = methods;
return PyModuleDef_Init(&module_def);
}
// }}}

View File

@ -0,0 +1,6 @@
#!/usr/bin/env python
# License: GPLv3 Copyright: 2025, Kovid Goyal <kovid at kovidgoyal.net>
import calibre_extensions.piper as piper
piper