Skip to content

Commit

Permalink
feat: 添加源阅读tts
Browse files Browse the repository at this point in the history
  • Loading branch information
x-dr committed Nov 28, 2023
1 parent 96bfaf6 commit 87ea6a0
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ http://ip:3035/

### 3. 使用说明

> 开源阅读3.0 tts使用 一键导入或复制链接填写
> iOS源阅读tts复制链接网络导入即可
<img src="https://img1.131213.xyz/file/d7171ec78c7042bed42cb.png" width="50%" height="50%" />
<img src="https://img1.131213.xyz/file/04cc986d0350a53ae104f.jpg" width="50%" height="50%" />

### 4. 更新日志

+ 2023-11-27 : 添加一键导入阅读3.0 按钮
+ 2023-11-27 : 添加阅读3.0和iOS源阅读 tts

### Star History

Expand Down
35 changes: 33 additions & 2 deletions cf_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const handleRequest = async (request) => {
const origin = url.origin
const params = new URLSearchParams(url.search);
// 获取查询参数中的文本
const text = params.get("text");
// const text = params.get("text");
// 获取查询参数中的语速
const rate = params.get("rate");
// 获取查询参数中的音高
Expand Down Expand Up @@ -151,7 +151,38 @@ const handleRequest = async (request) => {



}
} else if (url.pathname == "/sourcereader") {
const origin = url.origin
const params = new URLSearchParams(url.search);
// 获取查询参数中的文本
// const text = params.get("text");
// 获取查询参数中的语速
const rate = params.get("rate");
// 获取查询参数中的音高
const pitch = params.get("pitch");
// 获取查询参数中的音色
const voice = params.get("voice");
// 获取查询参数中的音色风格
const voiceStyle = params.get("voiceStyle");

const dataJson = [{
"customOrder": 100,
"id": Date.now(),
"lastUpdateTime": Date.now(),
"name": ` ${voice} ${voiceStyle} pitch: ${pitch} rate:${rate}`,
"url": `${origin}/audio?text={{speakText}}&rate=${rate}&pitch=${pitch}&voice=${voice}&voiceStyle=${voiceStyle},{"method":"GET"}`,
}]
return new Response(JSON.stringify(dataJson), {
headers: {
"content-type": "application/json;charset=UTF-8",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Methods": "*",
"ip": `Access cloudflare's ip:${clientIP}`
},
})
}
else {
return new Response("page", {
headers: {
Expand Down
26 changes: 25 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ app.get("/audio", async (req, res) => {
}
});

app.get("/legado", async (req, res) => {
app.get("/sourcereader", async (req, res) => {
try{

const { voice, rate, pitch, voiceStyle } = req.query;
Expand Down Expand Up @@ -74,6 +74,30 @@ app.get("/legado", async (req, res) => {

}

});
app.get("/legado", async (req, res) => {
try{

const { voice, rate, pitch, voiceStyle } = req.query;

// const hostname = req.hostname;
const hostname = req.rawHeaders[1];
console.log(req.rawHeaders[1]);

const dataJson = [{
"customOrder": 100,
"id": Date.now(),
"lastUpdateTime": Date.now(),
"name": ` ${voice} ${voiceStyle} pitch: ${pitch} rate:${rate}`,
"url": `https://${hostname}/audio?text={{speakText}}&rate=${rate}&pitch=${pitch}&voice=${voice}&voiceStyle=${voiceStyle},{"method":"GET"}`,
}]

res.send(dataJson);

}catch(error){

}

});

// 启动服务器,监听在指定端口上
Expand Down
7 changes: 4 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ <h1>语音合成</h1>
</div>
<div class="button-group">
<button onclick="legado()">一键导入阅读</button>
<button onclick="sourceReader()">复制阅读tts链接</button>
<button onclick="sourceReader()">复制源阅读tts链接</button>
</div>
</div>
<audio id="audioPlayer" controls></audio>
Expand Down Expand Up @@ -258,7 +258,7 @@ <h1>语音合成</h1>
const pitch = document.getElementById("pitchRange").value;
const text = document.getElementById("ssmlInput").value;

const url = `/legado?voice=${encodeURIComponent(voice)}&voiceStyle=${encodeURIComponent(voiceStyle)}&rate=${encodeURIComponent(rate)}&pitch=${encodeURIComponent(pitch)}&text=${encodeURIComponent(text)}`;
const url = `/legado?voice=${encodeURIComponent(voice)}&voiceStyle=${encodeURIComponent(voiceStyle)}&rate=${encodeURIComponent(rate)}&pitch=${encodeURIComponent(pitch)}`;
importUrl = "legado://import/httpTTS?src=" + encodeURIComponent(window.location.origin + url);
window.open(importUrl, '_blank');
}
Expand All @@ -268,7 +268,8 @@ <h1>语音合成</h1>
const voiceStyle = document.getElementById("voiceStyleSelect").value;
const rate = document.getElementById("rateRange").value;
const pitch = document.getElementById("pitchRange").value;
const url = `/audio?text={{speakText}}&rate=${encodeURIComponent(rate)}&pitch=${encodeURIComponent(pitch)}&voice=${encodeURIComponent(voice)}&voiceStyle=${encodeURIComponent(voiceStyle)},{"method":"GET"}`;
const text = document.getElementById("ssmlInput").value;
const url = `/sourcereader?voice=${encodeURIComponent(voice)}&voiceStyle=${encodeURIComponent(voiceStyle)}&rate=${encodeURIComponent(rate)}&pitch=${encodeURIComponent(pitch)}`;
navigator.clipboard.writeText(window.location.origin + url).then(function () {
alert('复制成功!');
}, function (err) {
Expand Down

0 comments on commit 87ea6a0

Please sign in to comment.