File size: 18,585 Bytes
3ca5f72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
{% extends "base.html" %}

{% block title %}TTSFM {{ _('nav.playground') }} - {{ _('playground.title') }}{% endblock %}

{% block content %}
<!-- Clean Playground Header -->
<section class="py-5" style="background-color: white; border-bottom: 1px solid #e5e7eb;">
    <div class="container">
        <div class="row align-items-center">
            <div class="col-lg-8">
                <div class="fade-in">
                    <div class="badge bg-primary text-white mb-3 px-3 py-2">
                        <i class="fas fa-flask me-2"></i>Demo
                    </div>
                    <h1 class="display-4 fw-bold mb-3 text-dark">
                        <i class="fas fa-play-circle me-3 text-primary"></i>{{ _('playground.title') }}
                    </h1>
                    <p class="lead mb-4 text-muted">
                        {{ _('playground.subtitle') }}
                    </p>
                </div>
            </div>
            <div class="col-lg-4 text-center">
                <div class="playground-visual fade-in" style="animation-delay: 0.3s;">
                    <div class="playground-icon">
                        <i class="fas fa-waveform-lines text-primary"></i>
                        <div class="pulse-ring"></div>
                        <div class="pulse-ring pulse-ring-delay"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<div class="container py-5 playground">

    <div class="row">
        <div class="col-lg-10 mx-auto">
            <div class="card shadow-lg-custom border-0 fade-in">
                <div class="card-header bg-gradient-primary text-white">
                    <h4 class="mb-0 d-flex align-items-center">
                        <i class="fas fa-microphone me-2"></i>
                        {{ _('playground.title') }}
                    </h4>
                </div>
                <div class="card-body p-4">
                    <form id="tts-form" onsubmit="return false;">
                        <!-- Enhanced Text Input -->
                        <div class="mb-4">
                            <label for="text-input" class="form-label fw-bold d-flex align-items-center">
                                <i class="fas fa-edit me-2 text-primary"></i>
                                {{ _('playground.text_input_label') }}
                            </label>
                            <div class="position-relative">
                                <textarea

                                    class="form-control shadow-sm"

                                    id="text-input"

                                    rows="4"

                                    placeholder="{{ _('playground.text_input_placeholder') }}"

                                    required

                                >Hello! This is a test of the TTSFM text-to-speech system.</textarea>
                                <div class="position-absolute top-0 end-0 p-2">
                                    <button type="button" class="btn btn-sm btn-outline-secondary" id="clear-text-btn" title="Clear text">
                                        <i class="fas fa-times"></i>
                                    </button>
                                </div>
                            </div>
                            <div class="form-text d-flex justify-content-between align-items-center">
                                <div class="d-flex align-items-center gap-3">
                                    <span class="text-muted">
                                        <i class="fas fa-keyboard me-1"></i>
                                        <span id="char-count">0</span> {{ _('playground.character_count') }}
                                    </span>
                                    <span id="length-status" class=""></span>
                                    <span id="auto-combine-status" class="badge bg-success d-none">
                                        <i class="fas fa-magic me-1"></i>{{ _('playground.max_length_warning') }}
                                    </span>
                                    <span class="text-muted small">
                                        <i class="fas fa-lightbulb me-1"></i>
                                        Tip: Use Ctrl+Enter to generate
                                    </span>
                                </div>
                                <div class="btn-group" role="group">
                                    <button type="button" class="btn btn-sm btn-outline-primary" id="validate-text-btn">
                                        <i class="fas fa-check me-1"></i>{{ _('common.validate') if _('common.validate') != 'common.validate' else 'Validate' }}
                                    </button>
                                    <button type="button" class="btn btn-sm btn-outline-secondary" id="random-text-btn">
                                        <i class="fas fa-dice me-1"></i>{{ _('playground.random_text') }}
                                    </button>
                                </div>
                            </div>
                            <div id="validation-result" class="mt-2 d-none"></div>
                        </div>

                        <div class="row">
                            <!-- Enhanced Voice Selection -->
                            <div class="col-md-6 mb-4">
                                <label for="voice-select" class="form-label fw-bold d-flex align-items-center">
                                    <i class="fas fa-microphone me-2 text-primary"></i>
                                    {{ _('playground.voice_label') }}
                                </label>
                                <select class="form-select shadow-sm" id="voice-select" required>
                                    <option value="">{{ _('common.loading_voices') }}</option>
                                </select>
                                <div class="form-text">
                                    <span>{{ _('common.choose_voice') }}</span>
                                </div>
                            </div>

                            <!-- Enhanced Format Selection -->
                            <div class="col-md-6 mb-4">
                                <label for="format-select" class="form-label fw-bold d-flex align-items-center">
                                    <i class="fas fa-file-audio me-2 text-primary"></i>
                                    {{ _('playground.format_label') }}
                                </label>
                                <select class="form-select shadow-sm" id="format-select" required>
                                    <option value="">{{ _('common.loading_formats') }}</option>
                                </select>
                                <div class="form-text">
                                    <span>{{ _('common.select_format') }}</span>
                                </div>
                            </div>
                        </div>

                        <!-- Advanced Options -->
                        <div class="row">
                            <div class="col-md-6 mb-4">
                                <label for="max-length-input" class="form-label fw-bold">
                                    <i class="fas fa-ruler me-2"></i>{{ _('common.max_length') }}
                                </label>
                                <input

                                    type="number"

                                    class="form-control"

                                    id="max-length-input"

                                    value="4096"

                                    min="100"

                                    max="10000"

                                >
                                <div class="form-text">
                                    {{ _('playground.max_length_description') }}
                                </div>
                            </div>

                            <div class="col-md-6 mb-4">
                                <label class="form-label fw-bold">
                                    <i class="fas fa-cog me-2"></i>{{ _('common.options') }}
                                </label>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" id="validate-length-check" checked>
                                    <label class="form-check-label" for="validate-length-check">
                                        {{ _('playground.enable_length_validation') }}
                                    </label>
                                </div>
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" id="auto-combine-check" checked>
                                    <label class="form-check-label" for="auto-combine-check">
                                        <span class="fw-bold text-primary">{{ _('playground.auto_combine_long_text') }}</span>
                                        <i class="fas fa-info-circle ms-1" data-bs-toggle="tooltip"

                                           title="{{ _('playground.auto_combine_tooltip') }}"></i>
                                    </label>
                                    <div class="form-text small">
                                        <i class="fas fa-magic me-1"></i>
                                        {{ _('playground.auto_combine_description') }}
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Instructions (Optional) -->
                        <div class="mb-4">
                            <label for="instructions-input" class="form-label fw-bold">
                                <i class="fas fa-magic me-2"></i>{{ _('playground.instructions_label') }}
                            </label>
                            <input

                                type="text"

                                class="form-control"

                                id="instructions-input"

                                placeholder="{{ _('playground.instructions_placeholder') }}"

                            >
                            <div class="form-text">
                                {{ _('playground.instructions_description') }}
                            </div>
                        </div>

                        <!-- API Key (Optional) -->
                        <div class="mb-4" id="api-key-section">
                            <label for="api-key-input" class="form-label fw-bold">
                                <i class="fas fa-key me-2"></i>{{ _('playground.api_key_optional') }}
                            </label>
                            <div class="input-group">
                                <input

                                    type="password"

                                    class="form-control"

                                    id="api-key-input"

                                    placeholder="{{ _('playground.api_key_placeholder') }}"

                                >
                                <button class="btn btn-outline-secondary" type="button" id="toggle-api-key-visibility">
                                    <i class="fas fa-eye" id="api-key-eye-icon"></i>
                                </button>
                            </div>
                            <div class="form-text">
                                <i class="fas fa-info-circle me-1"></i>
                                {{ _('playground.api_key_description') }}
                            </div>
                        </div>

                        <!-- Enhanced Generate Button -->
                        <div class="text-center mb-4">
                            <div class="d-grid gap-2 d-md-block">
                                <button type="submit" class="btn btn-primary btn-lg px-4 py-3" id="generate-btn">
                                    <span class="btn-text">
                                        <i class="fas fa-magic me-2"></i>{{ _('playground.generate_speech') }}
                                    </span>
                                    <span class="loading-spinner">
                                        <i class="fas fa-spinner fa-spin me-2"></i>{{ _('playground.generating') }}
                                    </span>
                                </button>
                                <button type="button" class="btn btn-outline-secondary btn-lg ms-md-3" id="reset-form-btn">
                                    <i class="fas fa-redo me-2"></i>{{ _('common.reset') }}
                                </button>
                            </div>
                        </div>
                    </form>

                    <!-- Enhanced Audio Player -->
                    <div id="audio-result" class="d-none">
                        <div class="border-top pt-4 mt-4">
                            <div class="d-flex align-items-center justify-content-between mb-3">
                                <h5 class="mb-0 d-flex align-items-center">
                                    <i class="fas fa-volume-up me-2 text-success"></i>
                                    {{ _('playground.audio_player_title') }}
                                    <span class="badge bg-success ms-2">
                                        <i class="fas fa-check me-1"></i>Ready
                                    </span>
                                </h5>
                                <div class="btn-group" role="group">
                                    <button type="button" class="btn btn-sm btn-outline-primary" id="replay-btn" title="Replay audio">
                                        <i class="fas fa-redo"></i>
                                    </button>
                                    <button type="button" class="btn btn-sm btn-outline-secondary" id="share-btn" title="Share audio">
                                        <i class="fas fa-share"></i>
                                    </button>
                                </div>
                            </div>

                            <div class="audio-player-container bg-light rounded p-3 mb-3">
                                <audio controls class="audio-player w-100" id="audio-player" preload="metadata">
                                    Your browser does not support the audio element.
                                </audio>
                                <div class="audio-controls mt-2 d-flex justify-content-between align-items-center">
                                    <div class="audio-info">
                                        <span id="audio-info" class="text-muted small"></span>
                                    </div>
                                    <div class="audio-actions">
                                        <button type="button" class="btn btn-success btn-sm" id="download-btn">
                                            <i class="fas fa-download me-1"></i>{{ _('playground.download_audio') }}
                                        </button>
                                    </div>
                                </div>
                            </div>

                            <div class="audio-stats row text-center">
                                <div class="col-md-3 col-6">
                                    <div class="stat-item">
                                        <i class="fas fa-clock text-primary"></i>
                                        <div class="stat-value" id="audio-duration">--</div>
                                        <div class="stat-label">{{ _('playground.duration') }}</div>
                                    </div>
                                </div>
                                <div class="col-md-3 col-6">
                                    <div class="stat-item">
                                        <i class="fas fa-file text-info"></i>
                                        <div class="stat-value" id="audio-size">--</div>
                                        <div class="stat-label">{{ _('playground.file_size') }}</div>
                                    </div>
                                </div>
                                <div class="col-md-3 col-6">
                                    <div class="stat-item">
                                        <i class="fas fa-microphone text-warning"></i>
                                        <div class="stat-value" id="audio-voice">--</div>
                                        <div class="stat-label">{{ _('playground.voice') }}</div>
                                    </div>
                                </div>
                                <div class="col-md-3 col-6">
                                    <div class="stat-item">
                                        <i class="fas fa-music text-success"></i>
                                        <div class="stat-value" id="audio-format">--</div>
                                        <div class="stat-label">{{ _('playground.format') }}</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>


                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<!-- Socket.IO for WebSocket support -->
<script src="https://cdn.socket.io/4.6.0/socket.io.min.js"></script>
<!-- WebSocket TTS Client -->
<script src="{{ url_for('static', filename='js/websocket-tts.js') }}"></script>
<!-- Enhanced Playground JavaScript with WebSocket Support -->
<script src="{{ url_for('static', filename='js/playground-enhanced-fixed.js') }}"></script>
<script>

    // Additional playground-specific functionality

    console.log('TTSFM Enhanced Playground with WebSocket support loaded successfully!');





</script>
{% endblock %}