Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加对Web端支持 #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions HZYS_WEB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from huoZiYinShua import *
from flask import Flask, request, send_from_directory, make_response, render_template
import os

app = Flask(__name__)
tempDir = "./HZYSTempOutput"
HZYS = huoZiYinShua("./settings.json")
Voices = []
if not (os.path.exists(tempDir)):
os.makedirs(tempDir)


@app.route('/')
def index():
return render_template('index.html')


@app.route('/lizi.ico')
def icon():
return send_from_directory('', 'lizi.ico')


@app.route('/submit', methods=["GET"])
def run_voice():
isSubVoice = True
ysdd, reverses, norm = False, False, False
if (request.values.get('text') == ""): return "error"
else: text = request.values.get('text')
if (request.values.get('ysdd') == "on"): ysdd = True
if (request.values.get('reverse') == "on"): reverses = True
if (request.values.get('norm') == "on"): norm = True
pitch = float(request.values.get('pitch'))
speed = float(request.values.get('speed'))
VoicesId = str(len(Voices))
tempsound = tempDir + "/temp" + str(VoicesId) + ".wav"
Voices.append(tempsound)
print(Voices)
HZYS.export(text,
filePath=tempsound,
inYsddMode=ysdd,
pitchMult=pitch,
speedMult=speed,
reverse=reverses,
norm=norm)
return render_template('export.html', name=VoicesId)


@app.route('/getVoices', methods=["GET"])
def getVoice():
if (request.values.get('id') == ""): return "error"
else: VoiceId = int(request.values.get('id'))
file_path, file_name = os.path.split(Voices[VoiceId])
response = make_response(
send_from_directory(file_path, file_name, as_attachment=True))
for root, dirs, files in os.walk(tempDir):
for f in files:
if not ((tempDir + '/' + f) in Voices):
os.remove(tempDir + '/' + f)
Voices.pop(VoiceId)
return response


if __name__ == '__main__':
app.run(host="127.0.0.1", port=1234)
3 changes: 3 additions & 0 deletions openServer.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pip install -r requirements.txt
set FLASK_APP=HZYS_WEB.py
flask run
3 changes: 3 additions & 0 deletions openServer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pip install -r requirements.txt
export FLASK_APP=HZYS_WEB.py
flask run
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
psola
psola
numpy
soundfile
pypinyin
playsound
#注意:如果直接用pip install playsound安装,Windows系统下会报错
#需要去原作者Github页面下载最新的playsound.py
#https://github.com/TaylorSMarks/playsound/blob/master/playsound.py
Pillow
Pillow
flask
80 changes: 80 additions & 0 deletions templates/export.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!doctype html>

<head>
<link rel="shortcut icon" href="lizi.ico">
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
crossorigin="anonymous">
<style>
/* 防止遮挡 */
body {
padding-top: 50px;
}

.sub-header {
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}


.navbar-fixed-top {
border: 0;
}


.main {
padding: 20px;
}

.main .page-header {
margin-top: 0;
}

.placeholders {
margin-bottom: 30px;
text-align: center;
}

.placeholders h4 {
margin-bottom: 0;
}

.placeholder {
margin-bottom: 20px;
}

.placeholder img {
display: inline-block;
border-radius: 50%;
}
</style>
<title>欧炫!纯纯的活字印刷</title>
</head>

<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">活字印刷 Web版</a>
</div>
</div>
</nav>
<div class="col-sm-9 col-md-10 main">
{% if name %}
<h2>导出成功!</h2>
<p><a href="/getVoices?id={{ name }}">点此下载</a></p>
<small>文件只保留一次。</small>
{% else %}
<h1>错误</h1>
<p>没有正确的输出。</p>
<p>请检查服务器状态,或<a href="/">再试一次</a>。</p>
{% endif %}
</div>

<script>
</script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" crossorigin="anonymous"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
crossorigin="anonymous"></script>
</body>
144 changes: 144 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<!doctype html>

<head>
<link rel="shortcut icon" href="lizi.ico">
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
crossorigin="anonymous">
<style>
/* 防止遮挡 */
body {
padding-top: 50px;
}

.sub-header {
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}


.navbar-fixed-top {
border: 0;
}


.main {
padding: 20px;
}

.main .page-header {
margin-top: 0;
}

.placeholders {
margin-bottom: 30px;
text-align: center;
}

.placeholders h4 {
margin-bottom: 0;
}

.placeholder {
margin-bottom: 20px;
}

.placeholder img {
display: inline-block;
border-radius: 50%;
}

.github-corner:hover .octo-arm {
animation: octocat-wave 560ms ease-in-out
}

@keyframes octocat-wave {

0%,
100% {
transform: rotate(0)
}

20%,
60% {
transform: rotate(-25deg)
}

40%,
80% {
transform: rotate(10deg)
}
}

@media (max-width:500px) {
.github-corner:hover .octo-arm {
animation: none
}

.github-corner .octo-arm {
animation: octocat-wave 560ms ease-in-out
}
}
</style>
<title>欧炫!纯纯的活字印刷</title>
</head>

<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">活字印刷 Web版</a>
</div>
</div>
</nav>
<a href="https://github.com/DSP-8192/HuoZiYinShua" class="github-corner" aria-label="View source on GitHub"><svg
width="80" height="80" viewBox="0 0 250 250"
style="fill:#151513; color:#fff; position: absolute; top: 40px; border: 0; right: 0;" aria-hidden="true">
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
<path
d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
fill="currentColor" style="transform-origin: 130px 106px; " class="octo-arm"></path>
<path
d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
fill="currentColor" class="octo-body"></path>
</svg></a>
<div class="col-sm-9 col-md-10 main">
<form id="form-text" action="/submit" method="get">
<h2 class="sub-header">文字</h2>
<div class="row placeholders">
<textarea class="form-control" rows="5" name="text" maxlength="500"></textarea>
</div>
<h2 class="sub-header">选项</h2>
<div class="placeholder checkbox">
<label>
<input type="checkbox" name="ysdd">匹配到特定文字时使用原声大碟
</label>
<br>
<label>
<input type="checkbox" name="norm">统一每个字和每条原声大碟句子的音量
</label>
<br>
<label>
<input type="checkbox" name="reverse">频音的成生放倒
</label>
</div>
<div class="placeholder form-group">
<label><input type="number" value="1.0" max="2.0" min="1.0" step="0.1" name="pitch" />音调偏移</label>
<br>
<label><input type="number" value="1.0" max="2.0" min="1.0" step="0.1" name="speed" />播放速度</label>
</div>
<div class="pull-right row"><button class="btn btn-default" onclick="submitText();">导出</button></div>
</form>
</div>

<script>
function submitText() {
var form = document.getElementById("form-text");
form.submit();
}
</script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" crossorigin="anonymous"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
crossorigin="anonymous"></script>
</body>