重构程序文件目录结构并更新相关路径引用

- 创建新的目录结构:research/、tools/(含子目录)和apps/
- 移动核心理论文件到research/core-theory/
- 移动天山理论文件到research/specialized/
- 重组tools/目录为多个子目录:content-generation/、data-processing/等
- 更新所有文档中的路径引用,包括README.md、项目结构说明.md等
- 更新工作流文件和脚本中的路径引用
- 更新文档索引文件中的路径引用
This commit is contained in:
ben
2025-10-27 12:54:26 +00:00
parent a60b82182d
commit 5b0a6c7bc1
22 changed files with 243 additions and 70 deletions

View File

@@ -0,0 +1,49 @@
import subprocess
import os
import shutil
def generate_ebook(source_dir="documentation/docs", build_dir="documentation/docs/_build", output_format="epub"):
"""
使用 Sphinx 生成电子书 (EPUB 或 HTML)。
"""
print(f"开始生成 {output_format} 格式的电子书...")
# 确保构建目录存在
if not os.path.exists(build_dir):
os.makedirs(build_dir)
# 清理之前的构建
if os.path.exists(build_dir):
shutil.rmtree(build_dir)
print(f"清理目录: {build_dir}")
else:
print(f"构建目录不存在,无需清理: {build_dir}")
# 构建文档
build_command = [
f"./documentation/analysis/phallic-worship-analysis/venv/bin/sphinx-build",
"-b", output_format,
source_dir,
os.path.join(build_dir, output_format)
]
print(f"执行构建命令: {' '.join(build_command)}")
try:
subprocess.run(build_command, check=True, cwd='.')
print(f"{output_format} 电子书生成成功!")
return True
except subprocess.CalledProcessError as e:
print(f"生成 {output_format} 电子书失败: {e}")
return False
if __name__ == "__main__":
# 示例用法:生成 EPUB
if generate_ebook(output_format="epub"):
print("EPUB 电子书已生成。")
else:
print("EPUB 电子书生成失败。")
# 示例用法:生成 HTML
if generate_ebook(output_format="html"):
print("HTML 网站已生成。")
else:
print("HTML 网站生成失败。")

View File

@@ -0,0 +1,64 @@
import os
from gtts import gTTS
import argparse
def generate_podcast(text_file_path, output_audio_path, lang='zh-CN'):
"""
将文本文件内容转换为语音并保存为 MP3 文件。
"""
if not os.path.exists(text_file_path):
print(f"错误: 文本文件 '{text_file_path}' 不存在。")
return False
try:
with open(text_file_path, 'r', encoding='utf-8') as f:
text = f.read()
except Exception as e:
print(f"错误: 读取文本文件失败: {e}")
return False
if not text.strip():
print("警告: 文本文件内容为空,跳过语音生成。")
return False
try:
tts = gTTS(text=text, lang=lang, slow=False)
tts.save(output_audio_path)
print(f"成功将文本转换为语音并保存到 '{output_audio_path}'")
return True
except Exception as e:
print(f"错误: 文本转语音失败: {e}")
print("请确保已安装 gTTS 库: pip install gTTS")
return False
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="将文本文件转换为 Podcast 音频。")
parser.add_argument("--text_file", required=True, help="输入文本文件的路径。")
parser.add_argument("--output_audio", required=True, help="输出 MP3 音频文件的路径。")
parser.add_argument("--lang", default="zh-CN", help="语音语言 (例如 'en', 'zh-CN')。")
args = parser.parse_args()
# 确保 gTTS 已安装
try:
import gtts
except ImportError:
print("gTTS 库未安装。正在尝试安装...")
try:
subprocess.run([f"./documentation/analysis/phallic-worship-analysis/venv/bin/pip", "install", "gTTS"], check=True)
print("gTTS 安装成功。")
except Exception as e:
print(f"gTTS 安装失败: {e}")
exit(1)
# 在实际应用中,这里应该有一个明确的触发机制或配置来决定是否生成音频
# 例如,通过命令行参数 `--confirm-generate` 或环境变量
# 为了避免意外生成,这里默认不执行生成,除非明确指定
print("警告: 文本转语音功能默认不自动执行。")
print("如需生成音频,请在脚本中手动启用或通过 CI/CD 配置触发。")
# if args.confirm_generate: # 示例:如果添加了确认参数
# if generate_podcast(args.text_file, args.output_audio, args.lang):
# print("Podcast 生成完成。")
# else:
# print("Podcast 生成失败。")
# else:
# print("Podcast 生成已跳过,因为未收到明确的生成指令。")

View File

@@ -0,0 +1,96 @@
import os
import subprocess
import argparse
def generate_video(text_file_path, output_video_path, image_dir=None, audio_path=None):
"""
模拟视频生成过程。
在实际应用中,这里会集成 AI 视频生成服务(如免费 Token 提供的服务),
并进行视频剪辑、合成等操作。
"""
print(f"开始模拟视频生成,输入文本文件: '{text_file_path}'")
if not os.path.exists(text_file_path):
print(f"错误: 文本文件 '{text_file_path}' 不存在。")
return False
try:
with open(text_file_path, 'r', encoding='utf-8') as f:
script_content = f.read()
except Exception as e:
print(f"错误: 读取文本文件失败: {e}")
return False
print(f"视频脚本内容摘要: {script_content[:200]}...")
# --- 实际 AI 视频生成服务的集成点 ---
# 在这里,你会调用 AI 视频生成服务的 API传入 script_content 和其他参数
# 例如:
# ai_video_service.generate(script=script_content, images=image_dir, ...)
# 生成的视频片段会保存到临时目录
# 模拟生成一个空的视频文件作为占位符
# 实际中,这里会是 AI 服务返回的视频文件
try:
# 使用 ffmpeg 创建一个简单的黑色视频作为占位符
# 假设视频时长为 10 秒,分辨率 1280x720
ffmpeg_command = [
'ffmpeg',
'-f', 'lavfi',
'-i', 'color=c=black:s=1280x720:d=10',
'-y', # 覆盖输出文件
output_video_path
]
if audio_path and os.path.exists(audio_path):
ffmpeg_command = [
'ffmpeg',
'-i', audio_path,
'-f', 'lavfi',
'-i', 'color=c=black:s=1280x720',
'-shortest', # 视频时长与音频时长一致
'-y',
output_video_path
]
print(f"执行 FFmpeg 命令 (模拟视频生成): {' '.join(ffmpeg_command)}")
subprocess.run(ffmpeg_command, check=True, cwd='.')
print(f"模拟视频文件已创建: '{output_video_path}'")
return True
except FileNotFoundError:
print("错误: FFmpeg 未安装。请安装 FFmpeg 以生成视频。")
return False
except subprocess.CalledProcessError as e:
print(f"错误: FFmpeg 命令执行失败: {e}")
return False
except Exception as e:
print(f"错误: <20><>拟视频生成失败: {e}")
return False
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="生成视频。")
parser.add_argument("--text_file", required=True, help="输入视频脚本文本文件的路径。")
parser.add_argument("--output_video", required=True, help="输出 MP4 视频文件的路径。")
parser.add_argument("--image_dir", help="可选:用于视频生成的图片目录。")
parser.add_argument("--audio_path", help="可选:用于视频的背景音频文件路径。")
args = parser.parse_args()
# 确保 ffmpeg 已安装
try:
subprocess.run(['ffmpeg', '-version'], check=True, capture_output=True)
except FileNotFoundError:
print("错误: FFmpeg 未安装。请安装 FFmpeg (sudo apt install ffmpeg) 以生成视频。")
exit(1)
# 在实际应用中,这里应该有一个明确的触发机制或配置来决定是否生成视频
# 例如,通过命令行参数 `--confirm-generate` 或环境变量
# 为了避免意外生成,这里默认不执行生成,除非明确指定
print("警告: 视频生成功能默认不自动执行。")
print("如需生成视频,请在脚本中手动启用或通过 CI/CD 配置触发。")
print("请注意,视频生成可能需要 GPU 资源和 AI 服务的 API 配置。")
# if args.confirm_generate: # 示例:如果添加了确认参数
# if generate_video(args.text_file, args.output_video, args.image_dir, args.audio_path):
# print("视频生成完成。")
# else:
# print("视频生成失败。")
# else:
# print("视频生成已跳过,因为未收到明确的生成指令。")