-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
1364 lines (1198 loc) · 63.5 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
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="en">
<head>
<meta charset="UTF-8">
<title>Lyric Writing Tool</title>
<!-- Include Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<style>
/* Highlight classes */
.highlight1 {
background-color: #ffffd3;
}
.highlight2 {
background-color: #dbffdb;
}
/* Container for the textarea and highlighted text */
.textarea-container {
position: relative;
height: calc(100vh - 150px); /* Adjust as needed */
min-height: 1650px;
border: 1px solid #ccc;
display: flex; /* Use flex to align items */
overflow: hidden; /* Prevent double scrollbars */
}
/* Shared styles for both the textarea and the highlighted text */
#lyric-input,
#highlighted-text {
position: absolute;
top: 0;
left: 50px; /* Adjust left position to accommodate line counts */
width: calc(100% - 50px); /* Adjust width accordingly */
height: 100%;
padding: 10px;
overflow-y: auto;
overflow-x: auto;
font-family: Arial, sans-serif; /* Use your preferred font */
font-size: 16px;
line-height: 1.2;
box-sizing: border-box;
background-color: transparent;
border: none;
outline: none;
white-space: pre; /* Change from pre-wrap to pre */
word-wrap: normal; /* Disable word wrapping */
overflow-wrap: normal; /* Disable overflow wrapping */
overflow-x: auto; /* Enable horizontal scrolling */
}
/* Specific styles for the textarea */
#lyric-input {
resize: none;
color: transparent; /* Hide the text */
caret-color: black; /* Show the cursor */
spellcheck: false; /* Disable spell check */
}
/* Specific styles for the highlighted text */
#highlighted-text {
pointer-events: none; /* Makes the div non-interactive */
}
/* Hide scrollbar for highlighted-text div */
#highlighted-text::-webkit-scrollbar {
display: none;
}
#highlighted-text {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
/* Other styles */
.tag-cell {
color: black;
text-decoration: none;
min-width: 200px;
width: 230px;
font-weight: 500;
}
#rhymes-list {
height: 200px;
overflow-y: auto;
border: 1px solid #ccc;
padding: 5px;
}
.separator {
border-top: 1px solid #dee2e6;
margin: 1.5rem 0;
}
#rhymes-list ol {
counter-reset: item;
}
#rhymes-list ol li {
display: block;
}
#rhymes-list ol li:before {
content: counter(item) ". ";
counter-increment: item;
color: #bcbcbc;
}
/* Slider styling */
.slider-container {
margin-top: 10px;
}
.slider-container label {
font-weight: bold;
}
/* Blacklist highlighting */
.highlight-blacklist {
color: red;
/* font-weight: bold; */
}
#rhymes-list a {
color: #212529 !important;
}
/* Line Word Counts */
#line-word-counts {
position: relative;
width: 50px; /* Adjust the width as needed */
padding: 10px 5px 10px 0;
overflow: hidden;
text-align: right;
font-family: Arial, sans-serif; /* Match the textarea font */
font-size: 16px;
line-height: 1.2;
box-sizing: border-box;
border-right: 1px solid #ccc;
background-color: #f9f9f9;
color: #555;
white-space: pre-wrap;
}
#line-word-counts .line-count {
height: 1.2em; /* Match the line height */
color: #afafaf;
}
/* Adjust the scrollbars */
#lyric-input,
#highlighted-text {
scrollbar-width: none; /* Firefox */
}
#lyric-input::-webkit-scrollbar,
#highlighted-text::-webkit-scrollbar {
display: none; /* Hide scrollbar for WebKit browsers */
}
/* Adjusted styles for the tag popup */
#tag-popup {
max-width: 550px;
width: 430px;
max-height: 408px;
overflow-y: auto;
overflow-x: hidden;
}
/* Make the popup header sticky */
#tag-popup .card-header {
position: sticky;
top: 0;
z-index: 1;
background-color: white;
}
/* Custom styles for hover and active states */
.list-group-item-action:hover {
background-color: #f5f5f5;
}
.list-group-item.tag-active {
background-color: #007bff;
color: white;
}
/* Ensure the tag popup header is not overlapped */
#tag-popup {
overflow: hidden;
}
#tag-popup .list-group {
max-height: 350px; /* Adjust as needed */
overflow-y: auto;
}
#tag-popup .card-header {
position: sticky;
top: 0;
z-index: 1;
background-color: white;
}
</style>
</head>
<body class="bg-light">
<div class="container mt-5">
<div class="card shadow-sm">
<div class="card-body">
<div class="row">
<!-- First Column: Text Area -->
<div class="col-md-8">
<div class="textarea-container">
<!-- Line Word Counts -->
<div id="line-word-counts"></div>
<!-- Highlighted Text -->
<div id="highlighted-text"></div>
<!-- Textarea Input -->
<textarea id="lyric-input" placeholder="Write your lyrics here..." spellcheck="false"></textarea>
</div>
<!-- Tag Selection Popup -->
<div id="tag-popup" class="card" style="display:none; position:absolute; z-index:1000;">
<!--<div class="card-header py-2 d-flex justify-content-between align-items-center">
<h5 class="mb-0">Tags</h5>
<button type="button" id="tag-popup-close" class="close">×</button>
</div>-->
<ul id="tag-list" class="list-group list-group-flush">
<!-- Tag items will be added here -->
</ul>
</div>
<!-- Word and Letter Counter + Spell check-->
<div class="d-flex justify-content-between align-items-center mt-2">
<div id="counter">
Words: <span id="word-count">0</span> | Letters: <span id="letter-count">0</span>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="spellcheck-toggle">
<label class="form-check-label" for="spellcheck-toggle">Spell Check</label>
</div>
</div>
</div>
<!-- Second Column: Settings -->
<div class="col-md-4">
<!-- Title and Prompt Inputs -->
<div>
<div class="form-group">
<label for="title-input">Title</label>
<input type="text" id="title-input" class="form-control" placeholder="Enter song title">
</div>
<div class="form-group">
<label for="prompt-input">Prompt</label>
<input type="text" id="prompt-input" class="form-control" placeholder="Enter song prompt">
</div>
<!-- Save/Load Section -->
<div>
<button id="save-btn" class="btn btn-primary mb-2">Save</button>
<button id="load-btn" class="btn btn-secondary mb-2 ml-2">Load</button>
<!-- Hidden file input -->
<input type="file" id="load-input" accept=".json" style="display: none;">
</div>
</div>
<!-- Text-to-speech -->
<div class="separator"></div>
<h5 class="text-center" data-toggle="tooltip" data-placement="top" title="This tool convert text to speech using your selected language and voice options. The available voices may vary based on your browser; for the best experience, I recommend using Microsoft Edge.">Text-to-speech</h5>
<div>
<!-- Language Selection Dropdown -->
<div class="form-group">
<label for="languageSelect">Select Language</label>
<select id="languageSelect" class="form-control"></select>
</div>
<!-- Voice Selection Dropdown -->
<div class="form-group">
<label for="voiceSelect">Select Voice</label>
<select id="voiceSelect" class="form-control"></select>
</div>
<!-- Speech Rate Slider -->
<div class="form-group">
<label for="rateControl">Speech Rate (Tempo)</label>
<input type="range" id="rateControl" class="form-control-range" min="0.1" max="2" step="0.1" value="1">
<span id="rateValue">1.0</span>
</div>
<!-- Speak and Cancel Buttons -->
<div class="form-group">
<button class="btn btn-primary" onclick="speakText()">Speak</button>
<button class="btn btn-danger" id="cancelButton" onclick="cancelSpeech()" disabled>Cancel</button>
</div>
<!-- Status Display -->
<p id="status" class=""></p>
</div>
<div class="separator"></div>
<!-- Duration and Tempo -->
<div>
<h5 class="text-center" data-toggle="tooltip" data-placement="top" title="This tool helps you gauge how much text can be sung, depending on the song's duration and tempo. Keep in mind that adding tags will impact how much fits into each section.">Chunk highlighting</h5>
<!-- Duration Dropdown -->
<div class="form-group">
<label for="duration-select">Duration</label>
<select id="duration-select" class="form-control">
<option value="32">32 seconds</option>
<option value="130">130 seconds</option>
</select>
</div>
<!-- Tempo Dropdown -->
<div class="form-group">
<label for="tempo-select">Tempo</label>
<select id="tempo-select" class="form-control">
<option value="slow">Slow Tempo (~60 BPM)</option>
<option value="mid">Mid Tempo (~100 BPM)</option>
<option value="fast">Fast Tempo (~140 BPM)</option>
</select>
</div>
<!-- Prompt/Genre Suggestions -->
<div id="suggestions" class="mt-3">
<!-- Suggestions will be inserted here -->
</div>
</div>
<div class="separator"></div>
<!-- Rhyme Finder -->
<div>
<h5 class="text-center" data-toggle="tooltip" data-placement="top" title="A tool that helps you find words with similar endings.">Rhyme finder</h5>
<div class="form-group">
<label for="rhyme-input">Find Rhymes</label>
<input type="text" id="rhyme-input" class="form-control" placeholder="Enter a word">
<label for="ending-select" class="mt-2">Match ending letters:</label>
<select id="ending-select" class="form-control">
<option value="2">2 letters</option>
<option value="3" selected>3 letters</option>
<option value="4">4 letters</option>
<option value="5">5 letters</option>
</select>
<button id="rhyme-btn" class="btn btn-secondary mt-2">Search</button>
<div class="slider-container">
<label for="length-slider">Max Word Length: <span id="slider-value">0</span></label>
<input type="range" id="length-slider" class="form-control-range" min="1" max="1" value="1" disabled>
</div>
<div id="rhymes-list" class="mt-2"></div>
</div>
</div>
<div class="separator"></div>
<!-- Libraries Buttons -->
<div>
<h5 class="text-center" data-toggle="tooltip" data-placement="top" title="This is a knowledge base where you can read more about how to use Udio. More to come soon.">Libraries</h5>
<button id="cheat-sheet-btn" class="btn btn-info mb-3">Tags cheat-sheet</button>
<!-- Cheat Sheet Modal -->
<div class="modal fade" id="cheatSheetModal" tabindex="-1" role="dialog" aria-labelledby="cheatSheetModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="cheatSheetModalLabel">Cheat-sheet</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h3>Official tags</h3>
<table class="table">
<thead>
<tr>
<th>Tag</th>
<th>Explanation</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tag-cell">[Verse]</td>
<td>Main narrative section of a song.</td>
</tr>
<tr>
<td class="tag-cell">[Chorus]</td>
<td>Repetitive, catchy section that often contains the song's hook</td>
</tr>
<tr>
<td class="tag-cell">[Intro]</td>
<td>Opening section that sets the tone of the song</td>
</tr>
<tr>
<td class="tag-cell">[Outro]</td>
<td>Closing section that brings the song to an end</td>
</tr>
<tr>
<td class="tag-cell">[Bridge]</td>
<td>Contrasting section that connects two main parts of a song</td>
</tr>
<tr>
<td class="tag-cell">[Hook]</td>
<td>Catchy phrase or riff designed to grab the listener's attention</td>
</tr>
<tr>
<td class="tag-cell">[Pre-chorus]</td>
<td>Section that builds tension before the chorus</td>
</tr>
<tr>
<td class="tag-cell">[Refrain]</td>
<td>Repeated lyrical phrase or musical idea</td>
</tr>
<tr>
<td class="tag-cell">[Post-chorus]</td>
<td>Section that follows and extends the chorus</td>
</tr>
<tr>
<td class="tag-cell">[Drop]</td>
<td>Moment of musical climax, often in electronic dance music</td>
</tr>
<tr>
<td class="tag-cell">[Interlude]</td>
<td>Instrumental passage between other sections</td>
</tr>
<tr>
<td class="tag-cell">[Instrumental Break]</td>
<td>Section without vocals, showcasing instruments</td>
</tr>
<tr>
<td class="tag-cell">[Instrumental]</td>
<td>Piece or section of music without vocals</td>
</tr>
<tr>
<td class="tag-cell">[Build]</td>
<td>Gradual increase in intensity or complexity</td>
</tr>
<tr>
<td class="tag-cell">[Pre-hook]</td>
<td>Section that leads into the hook</td>
</tr>
<tr>
<td class="tag-cell">[Pre-drop]</td>
<td>Build-up section before the drop in electronic music</td>
</tr>
<tr>
<td class="tag-cell">[Pre-refrain]</td>
<td>Section leading into the refrain</td>
</tr>
<tr>
<td class="tag-cell">[Break]</td>
<td>Brief pause or change in the rhythm or melody</td>
</tr>
<tr>
<td class="tag-cell">[All]</td>
<td>Indicates all instruments or voices playing together</td>
</tr>
<tr>
<td class="tag-cell">[Breakdown]</td>
<td>Stripped-down section that contrasts with fuller sections</td>
</tr>
<tr>
<td class="tag-cell">[Instrumental Bridge]</td>
<td>Bridge section without vocals</td>
</tr>
<tr>
<td class="tag-cell">[Sample]</td>
<td>Use of a portion of another sound recording</td>
</tr>
<tr>
<td class="tag-cell">[Solo]</td>
<td>Section featuring a single instrument or voice</td>
</tr>
<tr>
<td class="tag-cell">[Ensemble]</td>
<td>Section featuring multiple instruments or voices together</td>
</tr>
<tr>
<td class="tag-cell">[Post-hook]</td>
<td>Section that follows and extends the hook</td>
</tr>
<tr>
<td class="tag-cell">[Spoken Word]</td>
<td>Poetic or prose section that is spoken rather than sung</td>
</tr>
<tr>
<td class="tag-cell">[Choir]</td>
<td>Section featuring a group of singers</td>
</tr>
<tr>
<td class="tag-cell">[Announcer]</td>
<td>Spoken introduction or commentary, often in live recordings</td>
</tr>
</tbody>
</table>
<br>
<h3>Community tags</h3>
<table class="table">
<thead>
<tr>
<th>Tag</th>
<th>Explanation</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tag-cell">[Verse: Male Vocalist]</td>
<td>Specifies that the verse should be sung by a male vocalist. (Not always honored)</td>
</tr>
<tr>
<td class="tag-cell">[Verse: Female Vocalist]</td>
<td>Specifies that the verse should be sung by a female vocalist. (Not always honored)</td>
</tr>
<tr>
<td class="tag-cell">[Final Chorus]</td>
<td>The last iteration of the chorus, often with added intensity or slight variations to emphasize the conclusion of the song.</td>
</tr>
<tr>
<td class="tag-cell">[Build-Up]</td>
<td>Similar to the [Pre-Chorus], but not necessarily leading into a chorus. It gradually increases intensity, setting up any major transition in the song.</td>
</tr>
<tr>
<td class="tag-cell">[Breakdown]</td>
<td>A section where the instrumentation or energy is reduced, often to build tension before a subsequent section.</td>
</tr>
<tr>
<td class="tag-cell">[Verse Repeat]</td>
<td>A repeated verse, usually with the same melody and lyrics as an earlier verse.</td>
</tr>
<tr>
<td class="tag-cell">[Chorus Repeat]</td>
<td>The chorus being repeated after another section.</td>
</tr>
<tr>
<td class="tag-cell">[Instrumental Outro]</td>
<td>A closing section with only instruments, no vocals.</td>
</tr>
<tr>
<td class="tag-cell">[Voiceover]</td>
<td>A spoken part added over the instrumental or vocal sections.</td>
</tr>
<tr>
<td class="tag-cell">[Spoken]</td>
<td>Lyrics delivered as spoken word rather than sung.</td>
</tr>
<tr>
<td class="tag-cell">[Hook Repeat]</td>
<td>Repetition of the hook, often found in the chorus or refrain.</td>
</tr>
<tr>
<td class="tag-cell">[Couplet]</td>
<td>Two lines of lyrics that typically rhyme and form a unit in a verse.</td>
</tr>
<tr>
<td class="tag-cell">[Pre-Break]</td>
<td>A section that precedes a break in the song, often building tension.</td>
</tr>
<tr>
<td class="tag-cell">[Emotional]</td>
<td>Used to indicate when the singer should deliver a heightened emotional performance, often by intensifying or emphasizing the last word of a line, like a scream or powerful vocal push.</td>
</tr>
<tr>
<td class="tag-cell">(lyrics in parentheses)</td>
<td>Use parentheses to indicate lyrics sung in a different manner, including words or sounds (e.g., “ooohhh”).</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Example Button -->
<button style="display:none;" id="example-btn" class="btn btn-info mb-3">Example</button>
<!-- Example Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleLabel">Example Song</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Example</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div> <!-- End of row -->
</div>
</div>
</div>
<!-- Include jQuery and Bootstrap JS for modal functionality -->
<script src="https://code.jquery.com/jquery-3.5.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<!-- Include the word list script -->
<script src="wordlist.js"></script>
<!-- Include the blacklist script -->
<script src="blacklist.js"></script>
<!-- Include the tags for pop-up -->
<script src="popup-tags.js"></script>
<!-- JavaScript Code -->
<!-- Text-to-speech -->
<script>
let voices = [];
let selectedVoiceIndex = null; // Store the selected voice index
// Load voices into the dropdowns
function loadVoices() {
voices = speechSynthesis.getVoices();
const languageSelect = document.getElementById('languageSelect');
const voiceSelect = document.getElementById('voiceSelect');
const uniqueLanguages = Array.from(new Set(voices.map(voice => voice.lang)));
// Populate language dropdown
languageSelect.innerHTML = '';
uniqueLanguages.forEach(language => {
const option = document.createElement('option');
option.value = language;
option.textContent = language;
languageSelect.appendChild(option);
});
// Trigger voice list update when a language is selected
languageSelect.addEventListener('change', updateVoicesByLanguage);
// Update the voices dropdown based on initial language selection
updateVoicesByLanguage();
}
// Update voices based on selected language
function updateVoicesByLanguage() {
const languageSelect = document.getElementById('languageSelect');
const selectedLanguage = languageSelect.value;
const voiceSelect = document.getElementById('voiceSelect');
// Save the current selected voice index before updating the list
const previouslySelectedIndex = voiceSelect.selectedIndex;
voiceSelect.innerHTML = ''; // Clear previous options
const filteredVoices = voices.filter(voice => voice.lang === selectedLanguage);
filteredVoices.forEach((voice, index) => {
const option = document.createElement('option');
option.value = voices.indexOf(voice); // Save the global index
option.textContent = `${voice.name} (${voice.lang})`;
voiceSelect.appendChild(option);
});
// Restore the selected option
if (previouslySelectedIndex !== -1 && previouslySelectedIndex < voiceSelect.options.length) {
voiceSelect.selectedIndex = previouslySelectedIndex;
} else if (filteredVoices.length > 0) {
// Default to the first voice if none is selected
voiceSelect.selectedIndex = 0;
}
}
// Ensure the voices are loaded when available
window.speechSynthesis.onvoiceschanged = loadVoices;
// Function to get selected text or full text
function getSelectedText() {
const textarea = document.getElementById('lyric-input');
const start = textarea.selectionStart;
const end = textarea.selectionEnd;
// If there is selected text, return it; otherwise return full text
let text = start !== end ? textarea.value.substring(start, end) : textarea.value;
// Use regular expression to remove text within [] and ()
text = text.replace(/\[.*?\]|\(.*?\)/g, '');
return text;
}
// Function to update status message
function updateStatus(message, color = 'green') {
const statusElement = document.getElementById('status');
statusElement.textContent = message;
statusElement.style.color = color;
}
// Update rate value display
document.getElementById('rateControl').addEventListener('input', function() {
document.getElementById('rateValue').textContent = this.value;
});
function speakText() {
// Stop any ongoing speech to prevent interruptions
if (speechSynthesis.speaking) {
speechSynthesis.cancel();
}
const text = getSelectedText();
if (text.trim() === '') return; // Don't speak empty text
// Split text into chunks if necessary
const chunkSize = 200; // Example chunk size
const chunks = text.match(new RegExp(`.{1,${chunkSize}}`, 'g'));
let chunkIndex = 0;
// Get the selected voice once and store its global index
const voiceSelect = document.getElementById('voiceSelect');
selectedVoiceIndex = voiceSelect.selectedIndex; // Store the current index
const selectedVoice = voices[voiceSelect.value];
function speakChunk() {
if (chunkIndex >= chunks.length) {
updateStatus('Speech finished.', 'blue');
document.getElementById('cancelButton').disabled = true; // Disable cancel button
return;
}
const utterance = new SpeechSynthesisUtterance(chunks[chunkIndex]);
// Explicitly set the selected voice each time
utterance.voice = selectedVoice;
// Set the speech rate based on the slider
const rateControl = document.getElementById('rateControl');
utterance.rate = rateControl.value;
// Handle events
utterance.onstart = function() {
updateStatus('Speaking...', 'green');
document.getElementById('cancelButton').disabled = false; // Enable cancel button
};
utterance.onend = function () {
chunkIndex++;
speakChunk(); // Speak the next chunk
};
utterance.onerror = function(e) {
updateStatus('Stopped: ' + e.error, 'red');
document.getElementById('cancelButton').disabled = true; // Disable cancel button
};
speechSynthesis.speak(utterance);
}
speakChunk();
}
function cancelSpeech() {
if (speechSynthesis.speaking) {
speechSynthesis.cancel();
updateStatus('Speech canceled.', 'red');
document.getElementById('cancelButton').disabled = true; // Disable cancel button
}
}
</script>
<!-- Tags pop-up -->
<script>
$(document).ready(function() {
var selectedTagIndex = -1;
var insertPosition = -1; // Position where '/' was typed
var filteredTagOptions = [];
// Event listener for keyup on '#lyric-input'
$('#lyric-input').on('keyup', function(event) {
// Ignore keys that shouldn't trigger the popup refresh
if (['ArrowUp', 'ArrowDown', 'Enter', 'Escape'].includes(event.key)) {
return;
}
var textarea = $(this)[0];
var position = textarea.selectionStart;
var text = textarea.value;
// Search backwards from the cursor for the last '/'
var slashPosition = text.lastIndexOf('/', position - 1);
if (slashPosition >= 0) {
// Get the filter text
var filterText = text.substring(slashPosition + 1, position);
showTagPopup(slashPosition, filterText);
} else {
hideTagPopup();
}
});
// Close button for the tag popup
$('#tag-popup-close').on('click', function() {
hideTagPopup();
});
// Function to show the tag selection popup
function showTagPopup(position, filterText) {
// Filter the tagOptions based on filterText
filteredTagOptions = tagOptions.filter(function(option) {
return option.tag.toLowerCase().includes(filterText.toLowerCase());
});
// If no options, hide the popup
if (filteredTagOptions.length === 0) {
hideTagPopup();
return;
}
// Populate the tag list
var $tagList = $('#tag-list');
$tagList.empty();
filteredTagOptions.forEach(function(option, index) {
var $item = $('<li class="list-group-item list-group-item-action"></li>');
$item.html('<strong>' + option.tag + '</strong><br><small>' + option.description + '</small>');
$item.on('click', function() {
var textarea = $('#lyric-input')[0];
var cursorPosition = textarea.selectionStart;
insertTagAtPosition(option.tag, position, cursorPosition);
hideTagPopup();
});
$item.on('mouseenter', function() {
// Update selectedTagIndex
selectedTagIndex = index;
updateTagSelection();
});
$tagList.append($item);
});
selectedTagIndex = 0; // Initialize selected index
updateTagSelection(); // Update the highlighting
insertPosition = position; // Store the position of '/'
// Position the tag-popup
var $textarea = $('#lyric-input');
var offset = $textarea.offset();
var textareaHeight = $textarea.outerHeight();
var textareaWidth = $textarea.outerWidth();
// Compute line number
var textareaElem = $textarea[0];
var textUpToPosition = textareaElem.value.substring(0, position + 1); // Include the '/'
var lines = textUpToPosition.split('\n');
var lineNumber = lines.length - 1;
// Compute line height
var lineHeight = parseInt($textarea.css('line-height'));
if (isNaN(lineHeight)) {
var fontSize = parseInt($textarea.css('font-size'));
var lineHeightMultiplier = parseFloat($textarea.css('line-height'));
if (isNaN(lineHeightMultiplier)) {
lineHeightMultiplier = 1.2; // Default line height
}
lineHeight = fontSize * lineHeightMultiplier;
}
// Adjust for padding
var paddingTop = parseInt($textarea.css('padding-top'));
// Compute the top position
var topPosition = paddingTop + (lineNumber * lineHeight) - $textarea.scrollTop();
// Adjust left position to align with the left edge of the textarea
var leftPosition = "70px";
// Position the popup over the textarea, just below the line where '/' was typed
$('#tag-popup').css({
top: topPosition + lineHeight, // Position below the line
left: leftPosition
}).show();
}
// Function to hide the tag popup
function hideTagPopup() {
$('#tag-popup').hide();
insertPosition = -1;
selectedTagIndex = -1;
$('#tag-list').empty(); // Clear the list to prevent duplication
filteredTagOptions = [];
}
// Function to update the selected item in the tag list
function updateTagSelection() {
var $items = $('#tag-list .list-group-item');
$items.removeClass('tag-active');
if (selectedTagIndex >= 0 && selectedTagIndex < $items.length) {
var $selectedItem = $items.eq(selectedTagIndex);
$selectedItem.addClass('tag-active');
// Scroll into view if necessary
var tagList = $('#tag-list');
var itemTop = $selectedItem.position().top;
var itemBottom = itemTop + $selectedItem.outerHeight();
if (itemBottom > tagList.height()) {
tagList.scrollTop(tagList.scrollTop() + itemBottom - tagList.height());
} else if (itemTop < 0) {
tagList.scrollTop(tagList.scrollTop() + itemTop);
}
}
}
// Function to insert the selected tag at the correct position
function insertTagAtPosition(tag, startPosition, endPosition) {
var textarea = $('#lyric-input')[0];
var text = textarea.value;
// Replace the text from startPosition to endPosition with the tag
var before = text.substring(0, startPosition);
var after = text.substring(endPosition);
var newText = before + tag + after;
var newCursorPos = startPosition + tag.length;
textarea.value = newText;
textarea.selectionStart = textarea.selectionEnd = newCursorPos;
textarea.focus();
// Trigger input event to update highlighting and counters
$('#lyric-input').trigger('input');
}
// Hide the tag popup when clicking outside or pressing ESC
$(document).on('click', function(event) {
if (!$(event.target).closest('#tag-popup, #lyric-input').length) {
hideTagPopup();
}
});
// Keydown event handler for keyboard navigation
$(document).on('keydown', function(event) {
if ($('#tag-popup').is(':visible')) {
if (event.key === 'ArrowDown') {
event.preventDefault(); // prevent cursor movement
selectedTagIndex = (selectedTagIndex + 1) % filteredTagOptions.length;
updateTagSelection();
} else if (event.key === 'ArrowUp') {
event.preventDefault(); // prevent cursor movement
selectedTagIndex = (selectedTagIndex - 1 + filteredTagOptions.length) % filteredTagOptions.length;
updateTagSelection();
} else if (event.key === 'Enter') {
event.preventDefault(); // prevent form submission or new line
if (selectedTagIndex >= 0 && selectedTagIndex < filteredTagOptions.length) {
var option = filteredTagOptions[selectedTagIndex];
var textarea = $('#lyric-input')[0];
var cursorPosition = textarea.selectionStart;
insertTagAtPosition(option.tag, insertPosition, cursorPosition);
hideTagPopup();
}
} else if (event.key === 'Escape') {
hideTagPopup();
}
} else {
if (event.key === 'Escape') {
hideTagPopup();
}
}
});
// Close button for the tag popup (if you have one)
$('#tag-popup-close').on('click', function() {
hideTagPopup();
});
});
</script>
<!-- General JavaScript -->
<script>
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
// Handle Cheat-sheet Modal
$('#cheat-sheet-btn').click(function() {
$('#cheatSheetModal').modal('show');
});
// Handle Example Modal
$('#example-btn').click(function() {
$('#exampleModal').modal('show');
});
// Spell Check Toggle
$('#spellcheck-toggle').change(function() {
if ($(this).is(':checked')) {
$('#lyric-input').attr('spellcheck', 'true');
} else {
$('#lyric-input').attr('spellcheck', 'false');
}
});
// Initialize spellcheck attribute based on the checkbox state
$('#lyric-input').attr('spellcheck', 'false'); // Default is off
// Generate suggestions based on tempo
function updateSuggestions() {
var tempo = $('#tempo-select').val();
var suggestions = '';
if (tempo === 'slow') {
suggestions = '<pre>Prompt suggestions: Tempo 60 BPM, Ballads, Blues, Lo-Fi Hip-Hop, Downtempo, soulful melodies, emotional or introspective lyrics.</pre>';
} else if (tempo === 'mid') {