-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathindex.html
More file actions
2509 lines (2155 loc) · 118 KB
/
index.html
File metadata and controls
2509 lines (2155 loc) · 118 KB
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="AI ContentCraft - 强大的内容创作工具,具备故事生成、文本转语音和图像生成功能">
<meta name="keywords" content="AI, 内容创作, 故事生成, 文本转语音, TTS, 播客, 图像生成">
<meta name="author" content="AI ContentCraft">
<!-- Favicon -->
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🎨</text></svg>">
<title>AI ContentCraft - 智能内容创作平台</title>
<!-- External Stylesheets -->
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="modern-styles.css">
<!-- Preconnect to external domains for performance -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
</head>
<body>
<!-- Skip to main content for accessibility -->
<a href="#main-content" class="sr-only">Skip to main content</a>
<div class="container">
<!-- Header with navigation -->
<header role="banner">
<nav class="nav-bar" role="navigation" aria-label="主导航">
<button class="nav-button active" onclick="switchPage('story')" aria-pressed="true" aria-describedby="story-desc">
<span>📖</span> 故事生成器
</button>
<button class="nav-button" onclick="switchPage('simple')" aria-pressed="false" aria-describedby="simple-desc">
<span>🗣️</span> 简单语音合成
</button>
<button class="nav-button" onclick="switchPage('multi')" aria-pressed="false" aria-describedby="multi-desc">
<span>🎭</span> 多声音语音合成
</button>
<button class="nav-button" onclick="switchPage('podcast')" aria-pressed="false" aria-describedby="podcast-desc">
<span>🎙️</span> 播客生成器
</button>
</nav>
<!-- Hidden descriptions for screen readers -->
<div class="sr-only">
<div id="story-desc">生成故事并转换为带图像的脚本</div>
<div id="simple-desc">使用单一声音将文本转换为语音</div>
<div id="multi-desc">使用不同说话者创建多声音音频</div>
<div id="podcast-desc">生成多主持人播客内容</div>
</div>
</header>
<!-- Main content area -->
<main id="main-content" role="main">
<!-- Story Generator Page -->
<section id="storyPage" class="page active" aria-labelledby="story-title">
<div class="story-page-layout">
<!-- Left Side: Instructions Panel -->
<div class="instructions-panel">
<div class="instructions-header">
<h2>📋 操作指南</h2>
<p class="instructions-subtitle">按照以下步骤创建您的故事</p>
</div>
<div class="instruction-steps">
<div class="instruction-step">
<div class="step-number">1</div>
<div class="step-content">
<h3>输入故事主题</h3>
<p>在右侧输入框中描述您想要的故事主题,例如"太空冒险"、"魔法森林"等</p>
</div>
<div class="step-arrow">→</div>
</div>
<div class="instruction-step">
<div class="step-number">2</div>
<div class="step-content">
<h3>选择语言</h3>
<p>选择您希望生成故事的语言:中文或英文</p>
</div>
<div class="step-arrow">→</div>
</div>
<div class="instruction-step">
<div class="step-number">3</div>
<div class="step-content">
<h3>生成故事</h3>
<p>点击"生成故事"按钮,AI将为您创作一个精彩的故事</p>
</div>
<div class="step-arrow">→</div>
</div>
<div class="instruction-step">
<div class="step-number">4</div>
<div class="step-content">
<h3>转换为脚本</h3>
<p>故事生成后,可以将其转换为包含对话和旁白的脚本格式</p>
</div>
<div class="step-arrow">→</div>
</div>
<div class="instruction-step">
<div class="step-number">5</div>
<div class="step-content">
<h3>生成音频和图片</h3>
<p>为每个脚本段落生成语音和配图,创建完整的多媒体故事</p>
</div>
</div>
</div>
<div class="tips-section">
<h3>💡 小贴士</h3>
<ul class="tips-list">
<li>主题描述越详细,生成的故事越精彩</li>
<li>可以指定故事类型,如"科幻"、"童话"、"悬疑"等</li>
<li>生成后可以编辑故事内容,让它更符合您的需求</li>
</ul>
</div>
</div>
<!-- Right Side: Story Generation Section -->
<div class="story-generation-panel">
<div class="story-container">
<h1 id="story-title">✨ 故事生成</h1>
<div class="form-group">
<label for="themeInput" class="sr-only">故事主题</label>
<input
type="text"
id="themeInput"
class="theme-input"
placeholder="输入您的故事主题(例如:'太空中的神奇冒险')..."
aria-describedby="theme-help"
autocomplete="off"
>
<div id="theme-help" class="sr-only">为您的故事输入主题或话题</div>
</div>
<!-- Language Selection for Story -->
<div class="form-group">
<label class="language-label">选择故事语言 / Choose Story Language:</label>
<div class="language-options">
<label class="radio-option">
<input type="radio" name="storyLanguage" value="chinese" checked>
<span class="radio-text">🇨🇳 中文</span>
</label>
<label class="radio-option">
<input type="radio" name="storyLanguage" value="english">
<span class="radio-text">🇺🇸 English</span>
</label>
</div>
</div>
<div class="button-container">
<button onclick="generateStory()" id="generateStoryBtn" class="primary-btn" aria-describedby="generate-help">
<span class="spinner" id="storySpinner"></span>
<span id="generateStoryText">🎯 生成故事</span>
</button>
</div>
<div id="generate-help" class="sr-only">点击根据您的主题生成故事</div>
<div class="form-group">
<label for="storyText" class="sr-only">生成的故事内容</label>
<textarea
id="storyText"
class="text-input"
placeholder="您生成的故事将在这里显示..."
aria-describedby="story-help"
readonly
></textarea>
<div id="story-help" class="sr-only">生成的故事内容将在此处显示</div>
</div>
</div>
</div>
</div>
<!-- Script Conversion Section -->
<div class="script-container">
<h2 id="script-title">🎬 脚本转换</h2>
<div class="script-buttons">
<button onclick="generateScript()" id="convertToScript" class="btn primary convert-script" aria-describedby="convert-help">
<span class="spinner" id="convertSpinner"></span>
<span id="convertText">📝 转换为脚本</span>
</button>
<div class="button-row">
<button onclick="generateStoryAudio()" id="generateStoryAudioBtn" class="btn secondary hidden" aria-describedby="audio-help">
<span class="spinner" id="audioSpinner"></span>
<span id="storyBtnText">🎵 生成音频</span>
</button>
<button onclick="downloadAllImages()" id="downloadImages" class="btn secondary hidden" aria-describedby="download-help">
<span>📥</span> 下载所有图片
</button>
</div>
</div>
<!-- Hidden help text for screen readers -->
<div class="sr-only">
<div id="convert-help">将您的故事转换为包含对话和旁白的脚本格式</div>
<div id="audio-help">从脚本部分生成音频</div>
<div id="download-help">将所有生成的图片下载为zip文件</div>
</div>
<div id="scriptSections" role="region" aria-label="脚本部分">
<!-- Script sections will be dynamically generated here -->
</div>
<div class="progress-container hidden" id="storyProgressContainer" role="status" aria-live="polite">
<div class="progress-text">
正在生成:<span id="storyCurrentProgress">0</span>/<span id="storyTotalSections">0</span>
</div>
<div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<div class="progress" id="storyProgress"></div>
</div>
</div>
<div class="audio-container">
<label for="storyAudioPlayer" class="sr-only">生成的故事音频</label>
<audio id="storyAudioPlayer" controls preload="none" aria-describedby="audio-player-help">
<source src="" type="audio/mp3">
您的浏览器不支持音频元素。
</audio>
<div id="audio-player-help" class="sr-only">生成故事的音频播放器</div>
</div>
</div>
</section>
<!-- Simple TTS Page -->
<section id="simplePage" class="page" aria-labelledby="simple-title">
<div class="simple-tts-container">
<h1 id="simple-title">🗣️ 简单文本转语音</h1>
<div class="form-group">
<label for="simpleTtsText" class="sr-only">要转换为语音的文本</label>
<textarea
id="simpleTtsText"
class="text-input"
placeholder="输入您想要转换为语音的文本..."
aria-describedby="simple-text-help"
style="min-height: 150px;"
></textarea>
<div id="simple-text-help" class="sr-only">输入任何文本以将其转换为语音</div>
</div>
<div class="voice-select-container">
<label for="simpleTtsVoice" class="form-label">🎭 选择声音:</label>
<select id="simpleTtsVoice" class="voice-select" aria-describedby="voice-help">
<option value="">正在加载声音...</option>
</select>
<div id="voice-help" class="sr-only">为文本转语音转换选择声音</div>
</div>
<div class="button-container">
<button onclick="generateSimpleTTS()" id="simpleTtsBtn" class="primary-btn" aria-describedby="simple-generate-help">
<span class="spinner" id="simpleTtsSpinner"></span>
<span id="simpleTtsButtonText">🎵 生成音频</span>
</button>
</div>
<div id="simple-generate-help" class="sr-only">从输入的文本生成音频</div>
<div class="audio-container">
<label for="simpleTtsPlayer" class="sr-only">生成的音频</label>
<audio id="simpleTtsPlayer" controls preload="none" aria-describedby="simple-audio-help">
<source src="" type="audio/mp3">
您的浏览器不支持音频元素。
</audio>
<div id="simple-audio-help" class="sr-only">生成语音的音频播放器</div>
</div>
</div>
</section>
<!-- Multi-Voice TTS Page -->
<section id="multiPage" class="page" aria-labelledby="multi-title">
<div class="multi-tts-container">
<h1 id="multi-title">🎭 多声音文本转语音</h1>
<div class="tabs-container">
<div class="tabs" role="tablist" aria-label="文本部分">
<button class="tab-btn active" onclick="switchTab(0)" role="tab" aria-selected="true" aria-controls="panel-0" id="tab-0">
📝 部分 1
</button>
<button class="tab-btn" onclick="switchTab(1)" role="tab" aria-selected="false" aria-controls="panel-1" id="tab-1">
📝 部分 2
</button>
<button class="tab-btn add-tab" onclick="addNewTab()" aria-label="添加新部分">
➕
</button>
</div>
<div class="tab-panels">
<div class="tab-panel active" role="tabpanel" aria-labelledby="tab-0" id="panel-0">
<div class="form-group">
<label for="text-0" class="sr-only">部分1的文本</label>
<textarea
id="text-0"
class="text-input"
placeholder="输入此部分的文本..."
aria-describedby="text-help-0"
></textarea>
<div id="text-help-0" class="sr-only">输入要由所选声音朗读的文本</div>
</div>
<div class="voice-select-container">
<label for="voice-0" class="form-label">🎭 声音:</label>
<select id="voice-0" class="voice-select" aria-describedby="voice-help-0">
<option value="">正在加载声音...</option>
</select>
<div id="voice-help-0" class="sr-only">为此部分选择声音</div>
</div>
</div>
<div class="tab-panel" role="tabpanel" aria-labelledby="tab-1" id="panel-1">
<div class="form-group">
<label for="text-1" class="sr-only">部分2的文本</label>
<textarea
id="text-1"
class="text-input"
placeholder="输入此部分的文本..."
aria-describedby="text-help-1"
></textarea>
<div id="text-help-1" class="sr-only">输入要由所选声音朗读的文本</div>
</div>
<div class="voice-select-container">
<label for="voice-1" class="form-label">🎭 声音:</label>
<select id="voice-1" class="voice-select" aria-describedby="voice-help-1">
<option value="">正在加载声音...</option>
</select>
<div id="voice-help-1" class="sr-only">为此部分选择声音</div>
</div>
</div>
</div>
</div>
<div class="button-container">
<button onclick="generateAllAudio()" id="generateBtn" class="primary-btn" aria-describedby="generate-all-help">
<span class="spinner" id="spinner"></span>
<span id="btnText">🎵 生成所有音频</span>
</button>
<button onclick="exportMergedAudio()" id="exportBtn" class="action-btn" aria-describedby="export-help">
<span>📥</span> 导出合并音频
</button>
</div>
<!-- Hidden help text -->
<div class="sr-only">
<div id="generate-all-help">为所有部分生成音频并将它们合并在一起</div>
<div id="export-help">下载合并的音频文件</div>
</div>
<div class="progress-container hidden" id="progressContainer" role="status" aria-live="polite">
<div class="progress-text">正在处理部分...</div>
<div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<div class="progress" id="progress"></div>
</div>
</div>
<div class="audio-container">
<label for="multiAudioPlayer" class="sr-only">生成的合并音频</label>
<audio id="multiAudioPlayer" controls preload="none" aria-describedby="multi-audio-help">
<source src="" type="audio/mp3">
您的浏览器不支持音频元素。
</audio>
<div id="multi-audio-help" class="sr-only">合并多声音音频的音频播放器</div>
</div>
<div class="history-container" id="historyContainer" role="region" aria-label="生成历史">
<!-- History items will be dynamically added here -->
</div>
</div>
</section>
<!-- Podcast Generator Page -->
<section id="podcastPage" class="page" aria-labelledby="podcast-title">
<div class="podcast-page-layout">
<!-- Left Side: Instructions Panel -->
<div class="instructions-panel">
<div class="instructions-header">
<h2>📋 操作指南</h2>
<p class="instructions-subtitle">按照以下步骤创建您的播客</p>
</div>
<div class="instruction-steps">
<div class="instruction-step">
<div class="step-number">1</div>
<div class="step-content">
<h3>输入播客主题</h3>
<p>在右侧输入框中描述您的播客主题、大纲或内容,可以尽可能详细</p>
</div>
<div class="step-arrow">→</div>
</div>
<div class="instruction-step">
<div class="step-number">2</div>
<div class="step-content">
<h3>选择语言</h3>
<p>选择您希望生成播客的语言:中文或英文</p>
</div>
<div class="step-arrow">→</div>
</div>
<div class="instruction-step">
<div class="step-number">3</div>
<div class="step-content">
<h3>生成播客内容</h3>
<p>点击"生成播客内容"按钮,AI将为您创作播客对话内容</p>
</div>
<div class="step-arrow">→</div>
</div>
<div class="instruction-step">
<div class="step-number">4</div>
<div class="step-content">
<h3>选择主持人声音</h3>
<p>为主持人A和主持人B选择合适的声音,创造不同的角色特色</p>
</div>
<div class="step-arrow">→</div>
</div>
<div class="instruction-step">
<div class="step-number">5</div>
<div class="step-content">
<h3>转换为脚本</h3>
<p>将播客内容转换为分段脚本,便于编辑和音频生成</p>
</div>
<div class="step-arrow">→</div>
</div>
<div class="instruction-step">
<div class="step-number">6</div>
<div class="step-content">
<h3>生成播客音频</h3>
<p>为每个对话段落生成语音,创建完整的播客音频文件</p>
</div>
</div>
</div>
<div class="tips-section">
<h3>💡 小贴士</h3>
<ul class="tips-list">
<li>主题描述越详细,生成的播客内容越丰富</li>
<li>可以指定播客类型,如"访谈"、"新闻"、"教育"等</li>
<li>生成后可以编辑对话内容,调整主持人的发言</li>
<li>选择不同的声音可以创造更好的对话效果</li>
</ul>
</div>
</div>
<!-- Right Side: Podcast Generation Panel -->
<div class="podcast-generation-panel">
<div class="podcast-container">
<h1 id="podcast-title">🎙️ 播客生成器</h1>
<!-- Topic Input Section -->
<div class="topic-section">
<div class="form-group">
<label for="podcastTopic" class="form-label">📝 播客主题或内容:</label>
<textarea
id="podcastTopic"
class="topic-input"
placeholder="在此输入您的播客主题、大纲或内容。可以尽可能详细..."
rows="6"
aria-describedby="topic-help"
></textarea>
<div id="topic-help" class="sr-only">输入您播客的主题或内容</div>
</div>
<!-- Language Selection for Podcast -->
<div class="form-group">
<label class="language-label">选择播客语言 / Choose Podcast Language:</label>
<div class="language-options">
<label class="radio-option">
<input type="radio" name="podcastLanguage" value="chinese" checked>
<span class="radio-text">🇨🇳 中文</span>
</label>
<label class="radio-option">
<input type="radio" name="podcastLanguage" value="english">
<span class="radio-text">🇺🇸 English</span>
</label>
</div>
</div>
<div class="button-container">
<button onclick="generatePodcastContent()" id="generatePodcastBtn" class="primary-btn" aria-describedby="podcast-generate-help">
<span class="spinner" id="podcastSpinner"></span>
<span id="podcastBtnText">🎯 生成播客内容</span>
</button>
</div>
<div id="podcast-generate-help" class="sr-only">根据您的主题生成播客内容</div>
</div>
<!-- Script Editor Section -->
<div class="script-editor hidden" id="podcastScriptEditor">
<div class="voice-selection">
<h3>🎭 为主持人选择声音</h3>
<div class="character-voices">
<div class="voice-select-group">
<label for="hostAVoice">🎤 主持人 A:</label>
<select id="hostAVoice" class="voice-select" aria-describedby="host-a-help">
<option value="">正在加载声音...</option>
</select>
<div id="host-a-help" class="sr-only">为第一位播客主持人选择声音</div>
</div>
<div class="voice-select-group">
<label for="hostBVoice">🎤 主持人 B:</label>
<select id="hostBVoice" class="voice-select" aria-describedby="host-b-help">
<option value="">正在加载声音...</option>
</select>
<div id="host-b-help" class="sr-only">为第二位播客主持人选择声音</div>
</div>
</div>
</div>
<div class="script-controls">
<button onclick="generatePodcastScript()" id="generateScriptBtn" class="btn primary convert-script" aria-describedby="script-help">
<span>📝</span> 转换为脚本
</button>
<button onclick="addPodcastDialog('A')" class="action-btn" aria-describedby="add-a-help">
<span>➕</span> 添加主持人 A
</button>
<button onclick="addPodcastDialog('B')" class="action-btn" aria-describedby="add-b-help">
<span>➕</span> 添加主持人 B
</button>
<button onclick="translateAndDownload()" id="translateBtn" class="action-btn" aria-describedby="translate-help">
<span>🌐</span> 翻译并下载
</button>
</div>
<!-- Hidden help text -->
<div class="sr-only">
<div id="script-help">将内容转换为对话脚本格式</div>
<div id="add-a-help">为主持人A添加新的对话部分</div>
<div id="add-b-help">为主持人B添加新的对话部分</div>
<div id="translate-help">翻译内容并下载脚本</div>
</div>
<div id="podcastSections" class="podcast-sections" role="region" aria-label="播客对话部分">
<!-- Dialogue sections will be dynamically generated here -->
</div>
<div class="button-container">
<button onclick="generatePodcastAudio()" id="generatePodcastAudioBtn" class="primary-btn" aria-describedby="podcast-audio-help">
<span class="spinner" id="podcastAudioSpinner"></span>
<span id="podcastAudioBtnText">🎵 生成播客音频</span>
</button>
</div>
<div id="podcast-audio-help" class="sr-only">为整个播客生成音频</div>
<div class="progress-container hidden" id="podcastProgressContainer" role="status" aria-live="polite">
<div class="progress-text">
正在生成:<span id="podcastCurrentProgress">0</span>/<span id="podcastTotalSections">0</span>
</div>
<div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<div class="progress" id="podcastProgress"></div>
</div>
</div>
<div class="audio-container">
<label for="podcastAudioPlayer" class="sr-only">生成的播客音频</label>
<audio id="podcastAudioPlayer" controls preload="none" aria-describedby="podcast-player-help">
<source src="" type="audio/mp3">
您的浏览器不支持音频元素。
</audio>
<div id="podcast-player-help" class="sr-only">生成播客的音频播放器</div>
</div>
</div>
</div>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer role="contentinfo" class="footer">
<p>© 2025 AI ContentCraft. Built with ❤️ for creators.</p>
</footer>
</div>
<script>
let voices = [];
// ===== NOTIFICATION SYSTEM =====
function showNotification(message, type = 'info', duration = 5000) {
// Remove existing notifications
const existingNotifications = document.querySelectorAll('.notification');
existingNotifications.forEach(n => n.remove());
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.setAttribute('role', 'alert');
notification.setAttribute('aria-live', 'polite');
const icon = {
'success': '✅',
'error': '❌',
'warning': '⚠️',
'info': 'ℹ️'
}[type] || 'ℹ️';
notification.innerHTML = `
<div class="notification-content">
<span class="notification-icon">${icon}</span>
<span class="notification-message">${message}</span>
<button class="notification-close" onclick="this.parentElement.parentElement.remove()" aria-label="Close notification">×</button>
</div>
`;
document.body.appendChild(notification);
// Auto-remove after duration
setTimeout(() => {
if (notification.parentElement) {
notification.style.opacity = '0';
notification.style.transform = 'translateY(-100%)';
setTimeout(() => notification.remove(), 300);
}
}, duration);
}
// ===== LOADING STATE MANAGEMENT =====
function setLoadingState(element, isLoading, loadingText = 'Loading...', originalText = '') {
if (isLoading) {
element.disabled = true;
element.classList.add('loading');
const spinner = element.querySelector('.spinner');
if (spinner) spinner.style.display = 'inline-block';
const textElement = element.querySelector('span:not(.spinner)');
if (textElement) {
textElement.dataset.originalText = textElement.textContent;
textElement.textContent = loadingText;
}
} else {
element.disabled = false;
element.classList.remove('loading');
const spinner = element.querySelector('.spinner');
if (spinner) spinner.style.display = 'none';
const textElement = element.querySelector('span:not(.spinner)');
if (textElement) {
textElement.textContent = textElement.dataset.originalText || originalText;
}
}
}
// ===== ACCESSIBILITY HELPERS =====
function announceToScreenReader(message) {
const announcement = document.createElement('div');
announcement.setAttribute('aria-live', 'polite');
announcement.setAttribute('aria-atomic', 'true');
announcement.className = 'sr-only';
announcement.textContent = message;
document.body.appendChild(announcement);
setTimeout(() => announcement.remove(), 1000);
}
// ===== FORM VALIDATION =====
function validateForm(formElement) {
const requiredFields = formElement.querySelectorAll('[required]');
let isValid = true;
requiredFields.forEach(field => {
if (!field.value.trim()) {
field.classList.add('error');
field.setAttribute('aria-invalid', 'true');
isValid = false;
} else {
field.classList.remove('error');
field.setAttribute('aria-invalid', 'false');
}
});
return isValid;
}
// ===== ELEMENT VISIBILITY HELPERS =====
function showElement(element) {
if (typeof element === 'string') {
element = document.getElementById(element);
}
if (element) {
element.classList.remove('hidden');
element.style.display = '';
}
}
function hideElement(element) {
if (typeof element === 'string') {
element = document.getElementById(element);
}
if (element) {
element.classList.add('hidden');
}
}
function toggleElement(element, show) {
if (show) {
showElement(element);
} else {
hideElement(element);
}
}
async function loadVoices() {
try {
const response = await fetch('/voices');
voices = await response.json();
// 更新所有语音选择下拉框
updateAllVoiceSelects();
// 更新简单TTS的语音选择
const simpleTtsVoice = document.getElementById('simpleTtsVoice');
if (simpleTtsVoice) {
const voiceOptionsHtml = voices.map(voice =>
`<option value="${voice.id}">${voice.name} (${voice.language}, ${voice.gender})</option>`
).join('');
simpleTtsVoice.innerHTML = voiceOptionsHtml;
simpleTtsVoice.value = 'Wise_Woman';
}
} catch (error) {
console.error('加载声音失败:', error);
voices = [
{ id: "Wise_Woman", name: "Wise Woman (Default)", language: "en-us", gender: "Female" }
];
updateAllVoiceSelects();
}
}
function updateAllVoiceSelects() {
const voiceSelects = document.querySelectorAll('.voice-select');
const voiceOptionsHtml = voices.map(voice =>
`<option value="${voice.id}">${voice.name} (${voice.language}, ${voice.gender})</option>`
).join('');
voiceSelects.forEach(select => {
select.innerHTML = voiceOptionsHtml;
// 为播客主持人设置默认语音
if (select.id === 'hostAVoice' || select.id === 'hostBVoice') {
const podcastLanguage = document.getElementById('podcastTopic')?.getAttribute('data-language') || 'english';
const gender = select.id === 'hostAVoice' ? 'Female' : 'Male';
select.value = getDefaultVoiceForLanguage(podcastLanguage, gender);
} else {
select.value = 'Wise_Woman';
}
});
}
// 根据语言选择合适的默认语音
function getDefaultVoiceForLanguage(language, gender = 'Female') {
// 所有语音都支持多语言,根据性别选择合适的默认语音
const suitableVoices = voices.filter(voice => voice.gender === gender);
if (suitableVoices.length > 0) {
// 根据语言和性别选择推荐的语音
if (language === 'chinese') {
if (gender === 'Female') {
return 'Wise_Woman'; // 智慧女声
} else if (gender === 'Male') {
return 'Deep_Voice_Man'; // 深沉男声
}
} else {
if (gender === 'Female') {
return 'Calm_Woman'; // 平静女声
} else if (gender === 'Male') {
return 'Elegant_Man'; // 优雅男声
}
}
return suitableVoices[0].id;
}
// 最后的备选方案
return 'Wise_Woman';
}
// 简单的语言检测函数
function detectLanguage(text) {
// 检测中文字符
const chineseRegex = /[\u4e00-\u9fff]/;
if (chineseRegex.test(text)) {
return 'chinese';
}
return 'english';
}
// 页面加载时获取声音列表
loadVoices();
// 添加播客语言选择变化的事件监听器
document.addEventListener('DOMContentLoaded', function() {
const podcastLanguageRadios = document.querySelectorAll('input[name="podcastLanguage"]');
podcastLanguageRadios.forEach(radio => {
radio.addEventListener('change', function() {
updatePodcastVoiceDefaults(this.value);
});
});
});
// 更新播客主持人的默认语音
function updatePodcastVoiceDefaults(language) {
const hostAVoice = document.getElementById('hostAVoice');
const hostBVoice = document.getElementById('hostBVoice');
if (hostAVoice && hostBVoice) {
hostAVoice.value = getDefaultVoiceForLanguage(language, 'Female');
hostBVoice.value = getDefaultVoiceForLanguage(language, 'Male');
}
}
function startProgressSimulation() {
progress.style.width = '0%';
let width = 0;
const interval = setInterval(() => {
if (width >= 90) {
clearInterval(interval);
return;
}
width += Math.random() * 10;
progress.style.width = Math.min(width, 90) + '%';
}, 200);
}
function addToHistory(filename, text, voice) {
const item = document.createElement('div');
item.className = 'history-item';
const timestamp = new Date().toLocaleTimeString();
item.innerHTML = `
<span>${timestamp}</span>
<audio controls src="${filename}"></audio>
<div class="history-text">
<div>${text.substring(0, 30)}${text.length > 30 ? '...' : ''}</div>
<div class="voice-name">Voice: ${voice}</div>
</div>
`;
historyContainer.insertBefore(item, historyContainer.firstChild);
}
let currentTab = 0;
let audioBuffers = [];
function switchTab(index) {
const tabs = document.querySelectorAll('.tab-btn:not(.add-tab)');
const panels = document.querySelectorAll('.tab-panel');
tabs.forEach(tab => tab.classList.remove('active'));
panels.forEach(panel => panel.classList.remove('active'));
tabs[index].classList.add('active');
panels[index].classList.add('active');
currentTab = index;
}
function addNewTab() {
const tabs = document.querySelector('.tabs');
const panels = document.querySelector('.tab-panels');
const newIndex = document.querySelectorAll('.tab-btn:not(.add-tab)').length;
// 添加新标签按钮
const tabBtn = document.createElement('button');
tabBtn.className = 'tab-btn';
tabBtn.textContent = `部分 ${newIndex + 1}`;
tabBtn.onclick = () => switchTab(newIndex);
tabs.insertBefore(tabBtn, tabs.lastElementChild);
// 添加新面板
const panel = document.createElement('div');
panel.className = 'tab-panel';
panel.innerHTML = `
<textarea class="text-input" placeholder="输入要转换为语音的文本..."></textarea>
<div class="voice-select-container">
<select class="voice-select">
${document.querySelector('.voice-select').innerHTML}
</select>
</div>
`;
panels.appendChild(panel);
// 设置默认语音为 Wise Woman
const voiceSelect = panel.querySelector('.voice-select');
voiceSelect.value = 'Wise_Woman';
// 切换到新标签
switchTab(newIndex);
}
async function generateAllAudio() {
const panels = document.querySelectorAll('.tab-panel');
const generateBtn = document.getElementById('generateBtn');
const spinner = document.getElementById('spinner');
const btnText = document.getElementById('btnText');
const progressContainer = document.getElementById('storyProgressContainer');
const progress = document.getElementById('storyProgress');
const sectionsData = Array.from(panels).map(panel => ({
text: panel.querySelector('.text-input').value.trim(),
voice: panel.querySelector('.voice-select').value
})).filter(s => s.text && s.voice);
if (sectionsData.length === 0) {
showNotification('请输入要转换的文本', 'warning');
return;
}
// 设置加载状态
generateBtn.disabled = true;
spinner.style.display = 'inline-block';
btnText.textContent = '🎵 正在生成音频...';
progressContainer.style.display = 'block';
progress.style.width = '0%';
// 显示开始生成的通知
showNotification('开始生成音频,请稍候...', 'info');
try {
// 获取故事的语言信息
const storyLanguage = document.getElementById('storyText').getAttribute('data-language') || 'english';
const response = await fetch('/generate-and-merge', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ sections: sectionsData, language: storyLanguage })
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const reader = response.body.getReader();
const decoder = new TextDecoder();
let audioGenerated = false;
while (true) {
const { value, done } = await reader.read();
if (done) break;
const lines = decoder.decode(value).split('\n');
for (const line of lines) {
if (!line.trim()) continue;
try {
const data = JSON.parse(line);
if (data.type === 'progress') {
progress.style.width = `${(data.current / data.total) * 100}%`;
} else if (data.type === 'complete' && data.success) {
const audioPlayer = document.getElementById('multiAudioPlayer');
audioPlayer.src = data.filename;
audioPlayer.load();
// 启用导出按钮
document.getElementById('exportBtn').disabled = false;
// 添加到历史记录
addToHistory(data.filename, `合并音频 (${sectionsData.length} 个部分)`, '多个');
// 标记音频已生成
audioGenerated = true;
// 显示成功通知
showNotification('🎉 音频生成成功!', 'success');
// 滚动到音频播放器
audioPlayer.scrollIntoView({ behavior: 'smooth', block: 'center' });
} else if (data.type === 'error') {
throw new Error(data.message || '生成过程中发生错误');
}
} catch (e) {
console.warn('Failed to parse line:', line, e);
}
}
}
// 如果没有收到成功消息,显示警告
if (!audioGenerated) {
showNotification('音频生成可能未完成,请检查结果', 'warning');
}
} catch (error) {
console.error('Audio generation error:', error);
showNotification('生成音频失败:' + error.message, 'error');
} finally {
// 恢复按钮状态
generateBtn.disabled = false;
spinner.style.display = 'none';
btnText.textContent = '🎵 生成所有音频';
// 延迟隐藏进度条
setTimeout(() => {
progressContainer.style.display = 'none';
progress.style.width = '0%';
}, 2000);
}
}
async function exportMergedAudio() {
const audioPlayer = document.getElementById('multiAudioPlayer');
if (!audioPlayer.src) {
alert('请先生成音频');
return;
}