-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_example.html
134 lines (117 loc) · 4.6 KB
/
api_example.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
<!-- MIT License
Copyright (c) 2024 Mateusz Dera
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WhisperSpeech web UI API Client</title>
<style>
body {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
form {
display: flex;
flex-direction: column;
gap: 10px;
}
label {
font-weight: bold;
}
input, select, button {
padding: 5px;
font-size: 16px;
}
button {
cursor: pointer;
}
.row {
display: flex;
gap: 10px;
}
.row input {
flex: 1;
}
</style>
</head>
<body>
<h1>WhisperSpeech API Client</h1>
<form id="ttsForm">
<div class="row">
<div>
<label for="ip">IP Address:</label>
<input type="text" id="ip" value="localhost" required>
</div>
<div>
<label for="port">Port:</label>
<input type="number" id="port" value="5050" required>
</div>
</div>
<label for="text">Text:</label>
<textarea id="text" rows="4" placeholder="English is the default language and does not require a tag if used standalone.
Multiple languages:
<pl>To jest tekst w języku polskim.<en> And this is text in English" required></textarea>
<label for="speed">Speed (characters per second):</label>
<input type="number" id="speed" min="10" max="15" step="0.25" value="13.5" required>
<label for="format">Audio Format:</label>
<select id="format" required>
<option value="wav">WAV</option>
<option value="mp3">MP3</option>
<option value="ogg">OGG</option>
</select>
<button type="submit">Generate Audio</button>
</form>
<audio id="audioPlayer" controls style="display: none; margin-top: 20px;"></audio>
<script>
const form = document.getElementById('ttsForm');
const audioPlayer = document.getElementById('audioPlayer');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const ip = document.getElementById('ip').value;
const port = document.getElementById('port').value;
const text = document.getElementById('text').value;
const speed = document.getElementById('speed').value;
const format = document.getElementById('format').value;
const apiUrl = `http://${ip}:${port}/generate`;
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text, speed: parseFloat(speed), format }),
});
if (response.ok) {
const blob = await response.blob();
const url = URL.createObjectURL(blob);
audioPlayer.src = url;
audioPlayer.style.display = 'block';
audioPlayer.play();
} else {
throw new Error('Server response was not ok.');
}
} catch (error) {
console.error('Error:', error);
alert('Error generating audio. Please check the API address and try again.');
}
});
</script>
</body>
</html>