forked from wxxxcxx/ms-ra-forwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
240 lines (224 loc) · 11 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html lang="en">
<head>
<title>ms-ra-forwarder</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" target="_blank" href="https://github.com/meetcw/ms-ra-forwarder">ms-ra-forwarder</a>
<ul class="navbar-nav">
<li class="nav-item">
<a class="github-button" href="https://github.com/meetcw/ms-ra-forwarder" data-size="large"
data-show-count="true" aria-label="Star meetcw/ms-ra-forwarder on GitHub">Star</a>
</li>
</ul>
</div>
</nav>
<div class="container" style="margin-top: 30px;">
<form>
<div class="mb-3">
<label for="name" class="form-label">配置名称:</label>
<input name="name" type="text" class="form-control" value="大声朗读" />
<div class="form-text">在阅读中显示的名称。默认为“大声朗读”。</div>
</div>
<div class="mb-3">
<label for="voiceName" class="form-label">声音:</label>
<select name="voiceName" class="form-select">
</select>
<div class="form-text">貌似接口就支持4种声音?推荐使用晓晓(晓晓yyds)。</div>
</div>
<div class="mb-3">
<label for="styleName" class="form-label">讲话风格:</label>
<div class="input-group">
<span class="input-group-text">名称</span>
<input name="styleName" class="form-control" type="text" value="normal">
<span class="input-group-text">风格强度</span>
<input name="styleDegree" class="form-control" type="number" min="0.01" max="2.00" step=".01" value="1.00">
</div>
<div class="form-text">
每个声音支持的讲话风格都不一样,具体可以参考:https://docs.microsoft.com/zh-CN/azure/cognitive-services/speech-service/speech-synthesis-markup?tabs=csharp#adjust-speaking-styles
</div>
</div>
<div class="mb-3">
<label for="voiceFormat" class="form-label">音频格式:</label>
<select name="voiceFormat" class="form-select">
<option value="raw-16khz-16bit-mono-pcm" disabled>raw-16khz-16bit-mono-pcm</option>
<option value="raw-48khz-16bit-mono-pcm" disabled>raw-48khz-16bit-mono-pcm</option>
<option value="raw-8khz-8bit-mono-mulaw" disabled>raw-8khz-8bit-mono-mulaw</option>
<option value="raw-8khz-8bit-mono-alaw" disabled>raw-8khz-8bit-mono-alaw</option>
<option value="raw-16khz-16bit-mono-truesilk" disabled>raw-16khz-16bit-mono-truesilk</option>
<option value="raw-24khz-16bit-mono-truesilk" disabled>raw-24khz-16bit-mono-truesilk</option>
<option value="riff-16khz-16bit-mono-pcm">riff-16khz-16bit-mono-pcm</option>
<option value="riff-24khz-16bit-mono-pcm">riff-24khz-16bit-mono-pcm</option>
<option value="riff-48khz-16bit-mono-pcm">riff-48khz-16bit-mono-pcm</option>
<option value="riff-8khz-8bit-mono-mulaw">riff-8khz-8bit-mono-mulaw</option>
<option value="riff-8khz-8bit-mono-alaw">riff-8khz-8bit-mono-alaw</option>
<option value="audio-16khz-32kbitrate-mono-mp3">audio-16khz-32kbitrate-mono-mp3</option>
<option value="audio-16khz-64kbitrate-mono-mp3">audio-16khz-64kbitrate-mono-mp3</option>
<option value="audio-16khz-128kbitrate-mono-mp3">audio-16khz-128kbitrate-mono-mp3</option>
<option value="audio-24khz-48kbitrate-mono-mp3">audio-24khz-48kbitrate-mono-mp3</option>
<option value="audio-24khz-96kbitrate-mono-mp3">audio-24khz-96kbitrate-mono-mp3</option>
<option value="audio-24khz-160kbitrate-mono-mp3">audio-24khz-160kbitrate-mono-mp3</option>
<option value="audio-48khz-96kbitrate-mono-mp3">audio-48khz-96kbitrate-mono-mp3</option>
<option value="audio-48khz-192kbitrate-mono-mp3">audio-48khz-192kbitrate-mono-mp3</option>
<option value="webm-16khz-16bit-mono-opus" disabled>webm-16khz-16bit-mono-opus</option>
<option value="webm-24khz-16bit-mono-opus" disabled>webm-24khz-16bit-mono-opus</option>
<option value="ogg-16khz-16bit-mono-opus" selected>ogg-16khz-16bit-mono-opus</option>
<option value="ogg-24khz-16bit-mono-opus">ogg-24khz-16bit-mono-opus</option>
<option value="ogg-48khz-16bit-mono-opus">ogg-48khz-16bit-mono-opus</option>
</select>
<div class="form-text">可以调整音频的格式和质量。质量越高,生成的文件越大,对网速和流量的需求越高。请根据自己的情况选择。(我禁用了一些在阅读中播放不了的格式)</div>
</div>
<div class="mb-3">
<label for="token" class="form-label">凭据(TOKEN):</label>
<input name="token" class="form-control" type="text" value="">
<div class="form-text">如果没有设置 TOKEN 环境变量请留空。</div>
</div>
<div class="mb-3">
<label for="previewText" class="form-label">测试文本:</label>
<textarea name="previewText" class="form-control" rows="3" cols="">如果喜欢这个项目的话请点个 Star 吧。</textarea>
</div>
<div class="col-auto">
<button id="previewButton" type="button" class="btn btn-secondary" onclick="preview()">测试</button>
<button type="button" class="btn btn-primary" onclick='createLegadoUrl()'>生成阅读(legado)语音引擎链接</button>
</div>
</form>
</div>
<div id="legadoUrlModal" class="modal " tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">阅读链接</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div id="legadoUrlQRCode" style="text-align:center">
</div>
<textarea id="legadoUrl" class="form-control" readonly rows="3" cols="2" value></textarea>
<div>
</div>
<div class="alert alert-primary" role="alert">
请在阅读的朗读引擎设置中选择网络导入此链接。
</div>
</div>
</div>
</div>
</div>
<script async defer src="https://buttons.github.io/buttons.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/qrcode.min.js"></script>
<script>
var voices = [];
fetch('https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=6A5AA1D4EAFF4E9FB37E23D68491D6F4')
.then(response => {
if (response.status == 200) {
return response.json();
} else {
console.log(response);
throw '加载失败';
}
}).then(data => {
voices = data;
refreshVoice();
}).catch(reason => {
alert(reason);
});
function refreshVoice() {
let voice = document.getElementsByName('voiceName')[0];
voices.forEach(item => {
if (item['FriendlyName'].indexOf('Chinese') >= 0) {
let option = document.createElement('option');
option.value = item['ShortName'];
option.innerText = item['FriendlyName'];
voice.append(option)
}
});
}
function createSSML(text, voiceName, styleName, styleDegree) {
var ssml = '\
<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="en-US">\
<voice name="'+ voiceName + '">\
<mstts:express-as style="'+ styleName + '" styledegree="' + styleDegree + '">\
<prosody rate="0%" pitch="0%">\
'+ text + '\
</prosody >\
</mstts:express-as>\
</voice >\
</speak > '
return ssml;
}
function preview() {
var headers = {'Content-Type': 'text/plain'};
var voiceName = document.getElementsByName('voiceName')[0].value;
var voiceFormat = document.getElementsByName('voiceFormat')[0].value;
var styleName = document.getElementsByName('styleName')[0].value;
var styleDegree = document.getElementsByName('styleDegree')[0].value;
var token = document.getElementsByName('token')[0].value;
var previewText = document.getElementsByName('previewText')[0].value;
var ssml = createSSML(previewText, voiceName, styleName, styleDegree)
if (token) {
headers['Authorization'] = 'Bearer ' + token;
}
headers['Format'] = voiceFormat;
var button = document.getElementById('previewButton');
button.disabled = true;
var ctx = new AudioContext();
fetch('/api/ra', {
method: 'post',
headers: headers,
body: ssml
}).then(response => {
if (response.status == 200) {
return response.arrayBuffer()
} else if (response.status == 401) {
throw '无效的密钥';
} else {
console.log(response);
throw '未知错误';
}
})
.then(arrayBuffer => ctx.decodeAudioData(arrayBuffer))
.then(audio => {
var player = ctx.createBufferSource();
player.buffer = audio;
player.connect(ctx.destination);
player.start(ctx.currentTime);
})
.catch(reason => {
alert(reason);
})
.finally(()=>{
button.disabled = false;
});
}
function createLegadoUrl() {
var name = document.getElementsByName('name')[0].value;
var voiceName = document.getElementsByName('voiceName')[0].value;
var voiceFormat = document.getElementsByName('voiceFormat')[0].value;
var styleName = document.getElementsByName('styleName')[0].value;
var styleDegree = document.getElementsByName('styleDegree')[0].value;
var token = document.getElementsByName('token')[0].value;
var previewText = document.getElementsByName('previewText')[0].value;
var url = window.location.protocol + '//' + window.location.host + '/api/legado?api=' + encodeURI(window.location.protocol + '//' + window.location.host + '/api/ra')
+ '&name=' + encodeURI(name)
+ '&voiceName=' + voiceName
+ '&voiceFormat=' + voiceFormat
+ '&styleName=' + styleName
+ '&styleDegree=' + styleDegree
+ '&token=' + token;
var svg = new QRCode(url).svg();
var modal = new bootstrap.Modal(document.getElementById('legadoUrlModal'))
modal.show();
document.getElementById('legadoUrlQRCode').innerHTML = svg;
document.getElementById('legadoUrl').value = url;
}
</script>
</body>
</html>