liumaolin
commited on
Commit
·
aa586b2
1
Parent(s):
d673573
Add PyInstaller hooks and spec file for project packaging.
Browse files
build/pyinstaller/hooks/hook-en_core_web_sm.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PyInstaller.utils.hooks import collect_data_files, copy_metadata
|
| 2 |
+
|
| 3 |
+
datas = collect_data_files('en_core_web_sm')
|
| 4 |
+
datas += copy_metadata('en_core_web_sm')
|
build/pyinstaller/hooks/hook-voice_dialogue.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Voice Dialogue PyInstaller Hook
|
| 3 |
+
用于配置 Voice Dialogue 应用程序的 PyInstaller 打包规则
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import pathlib
|
| 7 |
+
|
| 8 |
+
from PyInstaller.utils.hooks import (
|
| 9 |
+
collect_submodules,
|
| 10 |
+
collect_data_files,
|
| 11 |
+
collect_system_data_files,
|
| 12 |
+
collect_dynamic_libs
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# ============================================================================
|
| 16 |
+
# 路径配置
|
| 17 |
+
# ============================================================================
|
| 18 |
+
PROJECT_ROOT = pathlib.Path(__file__).parent.parent.parent.parent
|
| 19 |
+
ASSETS_ROOT = PROJECT_ROOT / "assets"
|
| 20 |
+
|
| 21 |
+
# ============================================================================
|
| 22 |
+
# 核心模块收集
|
| 23 |
+
# ============================================================================
|
| 24 |
+
# 收集主模块的所有子模块
|
| 25 |
+
hiddenimports = collect_submodules('voice_dialogue')
|
| 26 |
+
datas = collect_data_files('moyoyo_tts', include_py_files=True)
|
| 27 |
+
# 收集系统资源文件
|
| 28 |
+
datas += collect_system_data_files(ASSETS_ROOT.as_posix(), "assets")
|
| 29 |
+
|
| 30 |
+
# ============================================================================
|
| 31 |
+
# 第三方依赖配置
|
| 32 |
+
# ============================================================================
|
| 33 |
+
|
| 34 |
+
# AI/ML 相关依赖
|
| 35 |
+
ML_DEPENDENCIES = [
|
| 36 |
+
"llama_cpp",
|
| 37 |
+
"torch",
|
| 38 |
+
"transformers",
|
| 39 |
+
"pytorch_lightning",
|
| 40 |
+
"huggingface_hub",
|
| 41 |
+
"einops",
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
# 语音处理相关依赖
|
| 45 |
+
AUDIO_DEPENDENCIES = [
|
| 46 |
+
"librosa",
|
| 47 |
+
"soundfile",
|
| 48 |
+
"funasr_onnx",
|
| 49 |
+
"pywhispercpp",
|
| 50 |
+
"kokoro_onnx",
|
| 51 |
+
"playsound",
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
+
# 文本处理相关依赖
|
| 55 |
+
TEXT_PROCESSING_DEPENDENCIES = [
|
| 56 |
+
"jieba",
|
| 57 |
+
"jieba_fast",
|
| 58 |
+
"cn2an",
|
| 59 |
+
"g2p_en",
|
| 60 |
+
"pypinyin",
|
| 61 |
+
"misaki",
|
| 62 |
+
"opencc",
|
| 63 |
+
"wordsegment",
|
| 64 |
+
"LangSegment",
|
| 65 |
+
"en_core_web_sm",
|
| 66 |
+
"spacy",
|
| 67 |
+
"spacy_curated_transformers",
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
# Web/网络相关依赖
|
| 71 |
+
WEB_DEPENDENCIES = [
|
| 72 |
+
"fastapi",
|
| 73 |
+
"uvicorn",
|
| 74 |
+
"websockets",
|
| 75 |
+
"langchain",
|
| 76 |
+
"langchain_community",
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
# 系统相关依赖
|
| 80 |
+
SYSTEM_DEPENDENCIES = [
|
| 81 |
+
"AppKit", # macOS
|
| 82 |
+
"Foundation", # macOS
|
| 83 |
+
"ffmpeg",
|
| 84 |
+
]
|
| 85 |
+
|
| 86 |
+
# 其他依赖
|
| 87 |
+
OTHER_DEPENDENCIES = [
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
# 合并所有隐藏导入
|
| 91 |
+
hiddenimports.extend(
|
| 92 |
+
ML_DEPENDENCIES +
|
| 93 |
+
AUDIO_DEPENDENCIES +
|
| 94 |
+
TEXT_PROCESSING_DEPENDENCIES +
|
| 95 |
+
WEB_DEPENDENCIES +
|
| 96 |
+
SYSTEM_DEPENDENCIES +
|
| 97 |
+
OTHER_DEPENDENCIES
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# ============================================================================
|
| 101 |
+
# 数据文件收集
|
| 102 |
+
# ============================================================================
|
| 103 |
+
|
| 104 |
+
# 需要收集数据文件的包配置
|
| 105 |
+
DATA_PACKAGES = [
|
| 106 |
+
("jieba_fast", {}),
|
| 107 |
+
("kokoro_onnx", {}),
|
| 108 |
+
("language_tags", {}),
|
| 109 |
+
("py3langid", {}),
|
| 110 |
+
("inflect", {"include_py_files": True}),
|
| 111 |
+
("g2p_en", {}),
|
| 112 |
+
("wordsegment", {}),
|
| 113 |
+
("espeakng_loader", {}),
|
| 114 |
+
("spacy", {"include_py_files": True}),
|
| 115 |
+
("misaki", {}),
|
| 116 |
+
]
|
| 117 |
+
|
| 118 |
+
# 收集数据文件
|
| 119 |
+
for package_name, kwargs in DATA_PACKAGES:
|
| 120 |
+
try:
|
| 121 |
+
datas += collect_data_files(package_name, **kwargs)
|
| 122 |
+
except Exception as e:
|
| 123 |
+
print(f"警告:无法收集包 {package_name} 的数据文件: {e}")
|
| 124 |
+
|
| 125 |
+
# ============================================================================
|
| 126 |
+
# 动态库收集
|
| 127 |
+
# ============================================================================
|
| 128 |
+
|
| 129 |
+
# 需要收集动态库的包
|
| 130 |
+
BINARY_PACKAGES = [
|
| 131 |
+
"llama_cpp",
|
| 132 |
+
]
|
| 133 |
+
|
| 134 |
+
binaries = []
|
| 135 |
+
for package_name in BINARY_PACKAGES:
|
| 136 |
+
try:
|
| 137 |
+
binaries += collect_dynamic_libs(package_name)
|
| 138 |
+
except Exception as e:
|
| 139 |
+
print(f"警告:无法收集包 {package_name} 的动态库: {e}")
|
build/pyinstaller/voice_dialogue.spec
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- mode: python ; coding: utf-8 -*-
|
| 2 |
+
import os
|
| 3 |
+
import pathlib
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
project_root = pathlib.Path(os.getcwd()).resolve()
|
| 7 |
+
main_path = project_root / "main.py"
|
| 8 |
+
build_path = project_root / "build"
|
| 9 |
+
build_pyinstaller_path = build_path / "pyinstaller"
|
| 10 |
+
|
| 11 |
+
source_code_root = project_root / "src"
|
| 12 |
+
third_party_root = project_root / "third_party"
|
| 13 |
+
|
| 14 |
+
if source_code_root.as_posix() not in sys.path:
|
| 15 |
+
sys.path.insert(0, source_code_root.as_posix())
|
| 16 |
+
|
| 17 |
+
if third_party_root.as_posix() not in sys.path:
|
| 18 |
+
sys.path.insert(0, third_party_root.as_posix())
|
| 19 |
+
|
| 20 |
+
a = Analysis(
|
| 21 |
+
[main_path.as_posix()],
|
| 22 |
+
pathex=[],
|
| 23 |
+
binaries=[],
|
| 24 |
+
datas=[
|
| 25 |
+
],
|
| 26 |
+
hiddenimports=[],
|
| 27 |
+
hookspath=[build_pyinstaller_path / "hooks"],
|
| 28 |
+
hooksconfig={},
|
| 29 |
+
runtime_hooks=[],
|
| 30 |
+
excludes=[],
|
| 31 |
+
noarchive=False,
|
| 32 |
+
optimize=0,
|
| 33 |
+
)
|
| 34 |
+
pyz = PYZ(a.pure)
|
| 35 |
+
|
| 36 |
+
exe = EXE(
|
| 37 |
+
pyz,
|
| 38 |
+
a.scripts,
|
| 39 |
+
[],
|
| 40 |
+
exclude_binaries=True,
|
| 41 |
+
name='voice_dialogue',
|
| 42 |
+
debug=False,
|
| 43 |
+
bootloader_ignore_signals=False,
|
| 44 |
+
strip=False,
|
| 45 |
+
upx=True,
|
| 46 |
+
console=False,
|
| 47 |
+
disable_windowed_traceback=False,
|
| 48 |
+
argv_emulation=False,
|
| 49 |
+
target_arch='arm64',
|
| 50 |
+
codesign_identity=None,
|
| 51 |
+
entitlements_file=None,
|
| 52 |
+
)
|
| 53 |
+
coll = COLLECT(
|
| 54 |
+
exe,
|
| 55 |
+
a.binaries,
|
| 56 |
+
a.datas,
|
| 57 |
+
strip=False,
|
| 58 |
+
upx=True,
|
| 59 |
+
upx_exclude=[],
|
| 60 |
+
name='voice_dialogue',
|
| 61 |
+
)
|
| 62 |
+
app = BUNDLE(
|
| 63 |
+
coll,
|
| 64 |
+
name='voice_dialogue.app',
|
| 65 |
+
icon=None,
|
| 66 |
+
bundle_identifier=None,
|
| 67 |
+
)
|