增加tts初步支持,大文件存储改用lfs

This commit is contained in:
:NoBody: committed 2026-05-19 12:23:10 +08:00
1 parent 512651be68
commit 7df49b37f3
13 files changed
+159 -277

No files matched your search

+1
View File
@@ -0,0 +1 @@
.venv
+2 -1
View File
@@ -1,2 +1,3 @@
./outputs/
outputs/*
private_key.asc
+1
View File
@@ -5,6 +5,7 @@
"imports": {
"@std/assert": "jsr:@std/assert@1",
"@std/toml": "jsr:@std/toml@^1.0.11",
"fs": "npm:fs@^0.0.1-security",
"markdown-it": "npm:markdown-it@^14.1.1",
"openpgp": "npm:openpgp@^6.3.0",
"pdf-lib": "npm:pdf-lib@^1.17.1",
+5
View File
@@ -5,6 +5,7 @@
"jsr:@std/collections@^1.1.3": "1.1.6",
"jsr:@std/internal@^1.0.12": "1.0.12",
"jsr:@std/toml@^1.0.11": "1.0.11",
"npm:fs@^0.0.1-security": "0.0.1-security",
"npm:markdown-it@^14.1.1": "14.1.1",
"npm:openpgp@^6.3.0": "6.3.0",
"npm:pdf-lib@^1.17.1": "1.17.1",
@@ -119,6 +120,9 @@
"[email protected]": {
"integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw=="
},
"[email protected]": {
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"[email protected]": {
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"os": ["darwin"],
@@ -244,6 +248,7 @@
"dependencies": [
"jsr:@std/assert@1",
"jsr:@std/toml@^1.0.11",
"npm:fs@^0.0.1-security",
"npm:markdown-it@^14.1.1",
"npm:openpgp@^6.3.0",
"npm:pdf-lib@^1.17.1",
+31 -13
View File
@@ -32,17 +32,35 @@ import { PDFParse } from "pdf-parse";
// },
// });
Deno.test({
name: "OpenPGPSigner test",
sanitizeOps: false,
sanitizeResources: false,
async fn() {
const { OpenPGPSigner } = await import("./pdf_builder/builder.ts");
const signer = new OpenPGPSigner(
"./outputs/mobile.pdf",
"./private_key.asc",
"./outputs/mobile.pdf.sig",
);
await signer.sign();
},
// Deno.test({
// name: "OpenPGPSigner test",
// sanitizeOps: false,
// sanitizeResources: false,
// async fn() {
// const { OpenPGPSigner } = await import("./pdf_builder/builder.ts");
// const signer = new OpenPGPSigner(
// "./outputs/mobile.pdf",
// "./private_key.asc",
// "./outputs/mobile.pdf.sig",
// );
// await signer.sign();
// },
// });
import { writeFileSync } from "node:fs";
Deno.test("TTS test", async () => {
const { PiperCloudTTS } = await import("./pdf_builder/tts.ts");
const tts = new PiperCloudTTS("https://piper.cmlmuf.org/");
const contents = Deno.readTextFileSync(
"./outputs/工农解放报RSF续刊第一期-适合手机阅读.md",
);
await tts.stream_to_file(
contents,
"zh_CN-xiao_ya-medium",
"./outputs/test_audio.wav",
1000,
);
console.log("Audio streaming completed to ./outputs/test_audio.wav");
});
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:488a086da08698b32c6b53d9ad7206559e69a2f13fd4571f089b9292c228044b
size 1044017
oid sha256:522a27fb94672c600552efa7842ce84e038f899d6894dea4327c17353011af71
size 1039520
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e081480ba83e85554028953bca535adf3529962cbf84454236612728832f497b
size 1044070
oid sha256:522a27fb94672c600552efa7842ce84e038f899d6894dea4327c17353011af71
size 1039520
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8fae6cce7619f098ed43ff53e556f6e2d195dc6aa918ac09bf8f128f1a211661
size 1042003
oid sha256:7e26e82dd37cc6f10feda34473b07d2cc0edd47757c57c5a61d1b6dccc91289f
size 1039427
+9 -2
View File
@@ -52,8 +52,15 @@ export class DocuBuilder {
async as_markdown() {
const turndownService = new TurndownService();
const md_page = turndownService.turndown(await this.as_html_page());
const html_page = await this.as_html_page();
const cleaned_html = html_page.replace(
`/<[^>]class="[^"]\bc_title\b[^"]"[^>]>([\s\S]*?)</[^>]+>/gi`,
"# $1",
).replace(
/<script\b[^>]*>[\s\S]*?<\/script>|<style\b[^>]*>[\s\S]*?<\/style>/gi,
"",
);
const md_page = turndownService.turndown(cleaned_html);
this.pages = [md_page];
}
+63
View File
@@ -0,0 +1,63 @@
export interface TTS {
say_all(content: string, voice: string): Promise<ArrayBuffer>;
}
export class PiperCloudTTS {
api_url: string;
constructor(api_url: string) {
this.api_url = api_url;
}
async say_all(content: string, voice: string): Promise<ArrayBuffer> {
const response = await fetch(this.api_url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0",
},
body: JSON.stringify({ text: content, voice: voice }),
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(
`Failed to fetch ${this.api_url}: ${response.status} ${response.statusText} - ${errorText}`,
);
}
return await response.arrayBuffer();
}
/**
* 将长文本分段并直接流式写入文件
*/
async stream_to_file(
content: string,
voice: string,
outputPath: string,
chunkSize = 1000,
): Promise<void> {
const file = await Deno.open(outputPath, {
write: true,
create: true,
truncate: true,
});
try {
for (let i = 0; i < content.length; i += chunkSize) {
const chunk = content.slice(i, i + chunkSize);
console.log(`Processing chunk ${i / chunkSize + 1}...`);
const audioData = await this.say_all(chunk, voice);
// WAV 文件通常包含头。注意:如果只是简单合并 WAV,
// 只有第一个 chunk 的头是有效的,后续 chunk 的头会被视为数据(可能会有杂音)。
// 如果 API 返回的是原始 PCM,则没问题。
// 这里我们先按照用户要求的流式写入实现。
await file.write(new Uint8Array(audioData));
}
} finally {
file.close();
}
}
}
-255
View File
@@ -1,255 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.mzdbl.cn">
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<HTML><HEAD><TITLE>红军旗网站 首页</TITLE>
<DIV style="LINE-HEIGHT: 140%">
<META NAME="Keywords" CONTENT=" 毛泽东 毛泽东著作 毛泽东照片 毛泽东时代 毛泽东颂歌 共产主义 社会主义 共产党">
<body bgcolor="#D1E3FE" link="#FFFF00" vlink="#FFFFFF" leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>
<table width="90%" border="0" align="center">
<tr>
<th width="30%" height="120" scope="col"><a href="jianshe.html" target="_blank"><img src="image/biaoti1-2.gif" alt="敬告网友" width=264 height=90 border=0></a></th>
<th width="50%" scope="col"><img src="image/biaoti2.gif" width="578" height="90"></th>
<th width="20%" scope="col"><img src="image/biaoti1.gif" width="120" height="120"> </th>
</table>
<div align="left"></div>
<table width="873" height="85" border="0" align="center">
<tr>
<th width="450" height="81"><a href="yinyue/guojige/index.html" target="_blank"><img src="image/biaoti2.jpg" width="450" height="89" border="0"></a></th>
<th width="100" scope="col"><a href="yinyue/jingxuan246/247国际歌.mp3" target="_blank"><img src="image/flag1.gif" alt="国际歌" width="100" height="66" border="0"></a></th>
<th width="100" scope="col"><a href="yinyue/junyue/002解放军军歌.mp3" target="_blank"><img src="image/flag2.gif" alt="解放军军歌" width="100" height="66" border="0"></a></th>
<th width="100" valign="middle" scope="col"><a href="yinyue/junyue/001义勇军进行曲.mp3" target="_blank"><img src="image/flag3.gif" alt="国歌" width="100" height="66" border="0"></a></th>
</tr>
</table>
<TD background=imagee.files/t_m.gif colSpan=5 width=600>
<TBODY> <TABLE width=90% border=0 align="center" cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<TD width="30%" height="586" align=middle vAlign=top bgcolor="#FF0000">
<TABLE width="100%" height=335 border=0 align=center
cellPadding=0 cellSpacing=0 bgcolor="#FF0000">
<TBODY>
<TR>
<TD height=335 align="center" vAlign=top><font color="#FFFF00" size="+1">
<table width="60%" height="59" border="2" cellpadding="0" cellspacing="0">
<tr>
<th scope="col"><div align=center>
<script language="JavaScript">
todayDate = new Date();
date = todayDate.getDate();
month= todayDate.getMonth() +1;
year= todayDate.getYear();
document.write("今天是")
document.write("<br>")
if(navigator.appName == "Netscape")
{
document.write(1900+year);
document.write("年");
document.write(month);
document.write("月");
document.write(date);
document.write("日");
document.write("<br>")
}
if(navigator.appVersion.indexOf("MSIE") != -1)
{
document.write(year);
document.write("年");
document.write(month);
document.write("月");
document.write(date);
document.write("日");
document.write("<br>")
}
if (todayDate.getDay() == 5) document.write("星期五")
if (todayDate.getDay() == 6) document.write("星期六")
if (todayDate.getDay() == 0) document.write("星期日")
if (todayDate.getDay() == 1) document.write("星期一")
if (todayDate.getDay() == 2) document.write("星期二")
if (todayDate.getDay() == 3) document.write("星期三")
if (todayDate.getDay() == 4) document.write("星期四")
</script>
</th>
</tr>
</table></font><table width="80%" height=251 align=center cellpadding=0 cellspacing=5>
<tbody>
<th height="19"><table width="40%" border="2" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="40%" height="15" bordercolor="#FFFF00" scope="col"><a href="jianshe.html" target="_blank">敬告网友</a></th>
</tr>
</table></th>
<TR>
<td height="139"><div align="center"><a href="yulu/index.html" target="_blank"><img src="image/beijing.gif" alt="阅读《毛主席语录》" width="183" height="28" border="0"></a>
</div>
<font color="#FFFF00"><strong><p align="left">&nbsp;<font color="#FFFF00"><strong>&nbsp;&nbsp;&nbsp;&nbsp;什么人站在革命人民方面,他就是革命派,什么人站在帝国主义封建主义官僚资本主义方面,他就是反革命派。什么人只是口头上站在革命人民方面而在行动上则另是一样,他就是一个口头革命派,如果不但在口头上而且在行动上也站在革命人民方面,他就是一个完全的革命派。</strong></font></p>
</strong></font>
<p align="right"><font color="#FFFF00"><strong>在中国人民政治协商会议<br>
第一届全国委员会第二次<br>
会议上的闭幕词&nbsp;&nbsp;</strong></font></p>
</TR>
<tr>
</tr>
</table></TD>
</TR>
</TBODY></TABLE>
<table width="139" border="1" align="center">
<tr>
<td width="129" height="159" align="center"><img src="image/公众号.jpg" alt="微信《红色年代》" width="129" height="129" border="0">
扫一扫订阅<br>《毛泽东博览》微信</td>
</tr>
</table>
<TABLE width=145 height=150 border=1 align="center" cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<TD height="13"><DIV align=center><B>参考网站</B></DIV></TD></TR>
<TR>
<TD>
<DIV align=center><A href="http://bbs1.people.com.cn/boardList.do?action=postList&boardId=1" target="_blank"><IMG
src="image/logo/1.gif" alt=人民网强国论坛 width="88" height="31" border=0></A></DIV></TD></TR>
<TR>
<TD>
<DIV align=center><a href="https://www.news.cn/comments/index.html" target="_blank"><img src="image/logo/2.gif" alt=新华网发展论坛 width="88" height="31" border=0></a></DIV></TD></TR>
<TR>
<TD><DIV align=center><a href="http://www.xinhuanet.com/changzheng/index.htm" target="_blank"><img src="image/logo/cz70.gif" alt=毛主席网站 width="88" height="31" border=0></a></DIV></TD></TR><TR>
</TR>
</TBODY></TABLE>
<DIV align=center>
<table width="200" height="101" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="216" height="14" scope="col">
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin4.html" target="_blank"><font color="#000000">2025年4月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin5.html" target="_blank"><font color="#000000">2025年5月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin6.html" target="_blank"><font color="#000000">2025年6月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin7.html" target="_blank"><font color="#000000">2025年7月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin8.html" target="_blank"><font color="#000000">2025年8月更新内容</font></a></strong></div></td>
<tr/>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin9.html" target="_blank"><font color="#000000">2025年9月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin10.html" target="_blank"><font color="#000000">2025年10月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin11.html" target="_blank"><font color="#000000">2025年11月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin12.html" target="_blank"><font color="#000000">2025年12月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin1.html" target="_blank"><font color="#000000">2026年1月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin2.html" target="_blank"><font color="#000000">2026年2月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td height="20" bgcolor="#CCCCCC"><div align="center"><strong><a href="xin3.html" target="_blank"><font color="#000000">2026年3月新增内容</font></a></strong></div></td>
</tr>
<tr>
<td><div align="center"><a href="7x/毛体字库.rar" target="_blank">毛体字库 下载</a></div></td>
</tr>
</table>
</DIV>
</TD><TD>
<th vAlign=top width=90%>
<div align="center">
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<p>
<th width="100%" height="48" bgcolor="#FF0000" scope="col"><table width="100%">
<tr>
<td width="83%">
<p align="center"><b><a href="maoxuan/dangshi.html" target="_blank"><font size="5">学习中共党史参考资料</font></a></b></p>
<p align="center"><b><a href="马列著作/index.html" target="_blank"><font size="5">向初学者推荐:马列著作选读</font></a></b></p>
</tr>
</table>
</tr>
<tr>
<th height="13" scope="col"><p>&nbsp;</p>
<p><font size="5">提示:点击下面各个画面进入相关栏目</font></p>
<p>&nbsp;</p></th>
</tr>
</table>
</div>
<TABLE width=100% height="225" border=0 cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<Th width="33%" height="225"><a href="maoxuan/index.html" target="_blank"><img src="image/zhuzuo.gif" alt="阅读毛主席著作" width="164" height="220" hspace=0 border="0" align=baseline></a></Th>
<Th width="33%"><a href="xiangji/index.html" target="_blank"><img src="image/maozedong.gif" alt="观看毛泽东像集" width="164" height="225" hspace=0 border=0 align=baseline></a></Th>
<Th width="33%"><a href="huaji/1/index.html" target="_blank"><img src="image/maohuaji.gif" alt="欣赏毛主席图片" width="164" height="220" hspace=0 border=0 align=baseline></a></Th>
</TR></TBODY></TABLE>
<p>
<table width=100% height="220" border=0 align="center" cellpadding=0 cellspacing=0>
<tbody>
<tr>
<th width="33%" height="220"><a href="gushi/index.html" target="_blank"><img src="image/gushi.jpg" alt="关于毛泽东的故事" width="164" height="220" hspace=0 border=0 align=baseline></a></th>
<th width="33%"><a href="shici/index.html" target="_blank"><img src="image/maoshici.gif" alt="欣赏诗词与书法" width="164" height="220" hspace=0 border=0 align=baseline></a></th>
<th width="33%"><a href="yinyue/index.html" target="_blank"><img src="image/maoyingshi.gif" alt="视听资料" width="164" height="220" hspace=0 border=0 align=baseline></a></th>
</tr>
</tbody>
</table>
<table width="99%" border="1" >
<tr>
<th height="32" scope="col"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FF0000">
<th width="97%" height="32" scope="col"><p>&nbsp;</p>
<p><b><a href="maoxuan/jundui.html" target="_blank"><font size="5">毛主席论人民军队(本站编辑)</font></a></b></p>
<p><b><a href="mp4/sugong/index.html" target="_blank"><font size="5">专题片《居安思危——苏共亡党的历史教训》</font></a></b></p></th>
</table></th>
</tr>
</table>
<table width="100%" border="1" >
<tr>
<th width="536" height="23" scope="col">友 情 链 接 </th>
</tr>
<tr>
<td height="60"><table width="100%" height="45" cellpadding="0" cellspacing="0">
<tr>
<th width="16%" height="43" scope="col"><a href="http://www.txssw.com/" target="_blank"><img src="image/logo/txssw.jpg" alt="天下韶山网" width="88" height="31" border="0"></a></th>
<th width="16%" scope="col"><a href="http://www.szhgh.com" target="_blank"><img src="image/logo/szhgh.jpg" alt="深圳红歌会" width="88" height="32" border="0"></a></th>
<th width="16%" scope="col"><a href="http://www.nanjiecun.cn/homepage.asp" target="_blank"><img src="image/logo/13.jpg" alt=南街村 width="88" height="31" border=0></a></th>
<th width="16%" scope="col"><a href="http://myy.cass.cn/" target="_blank"><img src="image/logo/cass.jpg" width="88" height="31" border="0"></a></th>
<th width="16%" scope="col"><a href="http://www.chinaha.net/" target="_blank"><img src="image/logo/19.gif" alt="中国军事网" width="88" height="31" border="0"></a></th>
</tr>
</table></td>
</tr>
</table>
</TR>
</TBODY></TABLE>
<table
width=90% height=60 border=0 align="center" cellpadding=0 cellspacing=3 bgcolor=#FF0000>
<tbody>
<tr>
<td width="90%" align="center"><font color="#FFFF00">
<p align="left">&nbsp;&nbsp;&nbsp;&nbsp;伟大的领袖和导师毛泽东主席,是中国共产党的缔造者,是当代最伟大的马克思列宁主义者。毛主席把马克思列宁主义的普遍真理和革命的具体实践相结合,在反对帝国主义和国内反动阶级的斗争中,在反对党内右的和“左”的机会主义路线的斗争中,在反对国际现代修正主义的斗争中,继承、捍卫和发展了马克思列宁主义。毛主席领导我党我军和我国人民,经过长期的革命斗争和革命战争,取得了新民主主义革命的彻底胜利,建立了无产阶级专政的中华人民共和国,接着又经过无产阶级和资产阶级激烈的复杂的斗争,经过史无前例的无产阶级文化大革命,取得了社会主义革命和社会主义建设的伟大胜利。毛主席的旗帜,是我们党团结战斗、争取胜利的伟大旗帜。
</p><p>
中国共产党章程(1977年8月18日中国共产党第十一次全国代表大会通过)</p>
</font>
<p><font color="#000000"><strong>交流:</strong> <img border=0 alt=MSN src="image/mail.jpg" width=90 height=67> <A
target=_blank><strong>[email protected]</strong></A></font><img src="image/&#24494;&#20449;&#36190;&#21161;.gif" width="150" height="86">
<P><font color="#000000"><A href="https://beian.miit.gov.cn" target="_blank"><strong>辽ICP备10003589号-1</strong></A></font><BR>
</P>
</td>
</tr>
</tbody>
</table>
<bgsound src="yinyue\jingxuan246\001东方红 钟声.mp3">
</html>