-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PakettieSpeak.lua
930 lines (852 loc) · 35.4 KB
/
PakettieSpeak.lua
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
-- Initialize the ViewBuilder and other variables
local vb = renoise.ViewBuilder()
local dialog = nil
local rns = nil
local rnt = renoise.tool()
local ra = renoise.app()
local button_press_active = false
local LANGUAGES = {{"Afrikaans","af"},{"Albanian","sq"},{"Amharic","am"},{"Aragonese","an"},{"Arabic","ar"},{"Armenian (East Armenia)","hy"},{"Armenian (West Armenia)","hyw"},{"Assamese","as"},{"Azerbaijani","az"},{"Bashkir","ba"},{"Basque","eu"},{"Belarusian","be"},{"Bengali","bn"},{"Bishnupriya Manipuri","bpy"},{"Bosnian","bs"},{"Bulgarian","bg"},{"Catalan","ca"},{"Cherokee","chr"},{"Chinese (Cantonese)","yue"},{"Chinese (Cantonese, Latin as Jyutping)","yue-Latn-jyutping"},{"Chinese (Mandarin, Latin as English)","cmn"},{"Chinese (Mandarin, Latin as Pinyin)","cmn-Latn-pinyin"},{"Chuvash","cv"},{"Croatian","hr"},{"Czech","cs"},{"Danish","da"},{"Dutch","nl"},{"English (America)","en-US"},{"English (America, New York City)","en-US-nyc"},{"English (Caribbean)","en-029"},{"English (Great Britain)","en"},{"English (Lancaster)","en-GB-x-gbclan"},{"English (Received Pronunciation)","en-GB-x-rp"},{"English (Scotland)","en-GB-scotland"},{"English (West Midlands)","en-GB-x-gbcwmd"},{"Esperanto","eo"},{"Estonian","et"},{"Finnish","fi"},{"French (Belgium)","fr-BE"},{"French (France)","fr"},{"French (Switzerland)","fr-CH"},{"Gaelic (Irish)","ga"},{"Gaelic (Scottish)","gd"},{"Georgian","ka"},{"German","de"},{"Greek","el"},{"Greek (Ancient)","grc"},{"Greenlandic","kl"},{"Gujarati","gu"},{"Haitian Creole","ht"},{"Hakka Chinese","hak"},{"Hawaiian","haw"},{"Hebrew","he"},{"Hindi","hi"},{"Hungarian","hu"},{"Icelandic","is"},{"Ido","io"},{"Indonesian","id"},{"Interlingua","ia"},{"Italian","it"},{"Japanese","ja"},{"Kazakh","kk"},{"K'iche'","quc"},{"Klingon","piqd"},{"Kannada","kn"},{"Konkani","kok"},{"Korean","ko"},{"Kurdish","ku"},{"Kyrgyz","ky"},{"Lang Belta","qdb"},{"Latin","la"},{"Latgalian","ltg"},{"Latvian","lv"},{"Lingua Franca Nova","lfn"},{"Lithuanian","lt"},{"Lojban","jbo"},{"Luxembourgish","lb"},{"Lule Saami","smj"},{"Macedonian","mk"},{"Maori","mi"},{"Malay","ms"},{"Malayalam","ml"},{"Maltese","mt"},{"Marathi","mr"},{"Myanmar (Burmese)","my"},{"Nahuatl (Classical)","nci"},{"Nepali","ne"},{"Norwegian Bokmål","nb"},{"Nogai","nog"},{"Oromo","om"},{"Oriya","or"},{"Papiamento","pap"},{"Persian","fa"},{"Persian (Pinglish)","fa-Latn"},{"Polish","pl"},{"Portuguese (Brazil)","pt-BR"},{"Portuguese (Portugal)","pt"},{"Punjabi","pa"},{"Pyash","py"},{"Quechua","qu"},{"Quenya","qya"},{"Romanian","ro"},{"Russian","ru"},{"Russian (Latvia)","ru-LV"},{"Sindarin","sjn"},{"Sindhi","sd"},{"Sinhala","si"},{"Shan (Tai Yai)","shn"},{"Slovak","sk"},{"Slovenian","sl"},{"Spanish (Latin America)","es-419"},{"Spanish (Spain)","es"},{"Swahili","sw"},{"Swedish","sv"},{"Tamil","ta"},{"Telugu","te"},{"Thai","th"},{"Turkish","tr"},{"Turkmen","tk"},{"Tatar","tt"},{"Ukrainian","uk"},{"Urdu","ur"},{"Uyghur","ug"},{"Uzbek","uz"},{"Vietnamese (Central)","vi-VN-x-central"},{"Vietnamese (Northern)","vi"},{"Vietnamese (Southern)","vi-VN-x-south"},{"Welsh","cy"}}
local VOICES = {"None","adam","Alex","Alicia","Andrea","Andy","anika","anikaRobot","Annie","announcer","antonio","AnxiousAndy","aunty","belinda","benjamin","boris","caleb","croak","david","Demonic","Denis","Diogo","ed","edward","edward2","f1","f2","f3","f4","f5","fast","Gene","Gene2","grandma","grandpa","gustave","Henrique","Hugo","iven","iven2","iven3","iven4","Jacky","john","kaukovalta","klatt","klatt2","klatt3","klatt4","klatt5","klatt6","Lee","linda","m1","m2","m3","m4","m5","m6","m7","m8","marcelo","Marco","Mario","max","miguel","Michael","michel","Mike","Mr serious","Nguyen","norbert","pablo","paul","pedro","quincy","RicishayMax","RicishayMax2","RicishayMax3","rob","robert","robosoft","sandro","shelby","steph","Storm","travis","Tweaky","victor","whisper","whisperf","zac"}
local LANGUAGE_NAMES = {}
local LANGUAGE_SHORTS = {}
local VOICES_NAMES = {}
for _, langs in pairs(LANGUAGES) do
table.insert(LANGUAGE_NAMES, langs[1])
table.insert(LANGUAGE_SHORTS, langs[2])
end
for _, voice in pairs(VOICES) do
table.insert(VOICES_NAMES, voice)
end
local os_name = os.platform()
local default_executable
if os_name == "WINDOWS" then
default_executable = "C:\\Program Files\\espeak\\espeak.exe"
elseif os_name == "MACINTOSH" then
default_executable = "/opt/homebrew/bin/espeak-ng"
else
default_executable = "/usr/bin/espeak-ng"
end
function PakettieSpeakConvertPath(path)
path = tostring(path)
if os_name == "WINDOWS" then
return string.gsub(path, "/", "\\")
else
return path
end
end
function PakettieSpeakRevertPath(path)
path = tostring(path)
if os_name == "WINDOWS" then
return string.gsub(path, "\\", "/")
else
return path
end
end
local selected_textfile = ""
function PakettieSpeakLoadTextfile(refresh)
if not refresh then
selected_textfile = renoise.app():prompt_for_filename_to_read({"*.txt"}, "Load Textfile")
end
if selected_textfile ~= "" then
local file = io.open(selected_textfile, "r")
if file then
local content = file:read("*all")
file:close()
vb.views.PakettieSpeak_text_field.text = content
vb.views.PakettieSpeak_load_textfile_button.text = selected_textfile:match("[^/\\]+$")
print("Loaded textfile:", content)
eSpeak.text.value = content
PakettieSpeakCreateSample()
PakettieSpeakUpdateLineCount() -- Update line count after loading textfile
else
renoise.app():show_error("Failed to read the file.")
end
end
end
function PakettieSpeakGetLines(text)
local lines = {}
for line in text:gmatch("[^\r\n]+") do
table.insert(lines, line)
end
return lines
end
function PakettieSpeakUpdateLineCount()
if not dialog then return end
local text = vb.views.PakettieSpeak_text_field.text
local lines = PakettieSpeakGetLines(text)
local line_count = #lines
vb.views.PakettieSpeak_which_row.max = math.max(line_count, 1)
if vb.views.PakettieSpeak_which_row.value > line_count then
vb.views.PakettieSpeak_which_row.value = 0 -- Set to 0 to render all text
end
end
local dialog_width = 300
local control_width = 190
local valuebox_width = 60
local button_width = 190
local path_to_espeak = vb:text{ width = control_width, height = 24, text ="Path to eSpeak", font="bold"}
local randomize_everything = vb:row{
vb:button{id = "PakettieSpeak_randomize_everything",
text = "Randomized String",
width = button_width + button_width,
height = 24,
notifier = function()
local characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#€%&/()=?"
local result = ""
local count = math.random(10, 100)
for i = 1, count do
local random_index = math.random(1, #characters)
result = result .. characters:sub(random_index, random_index)
end
vb.views.PakettieSpeak_text_field.text = result
eSpeak.text.value = result
PakettieSpeakCreateSample()
PakettieSpeakUpdateLineCount()
end
}
}
local randomize_consonants = vb:button{id = "PakettieSpeak_randomize_consonants",
text = "Randomize Consonants",
width = button_width,
height = 24,
notifier = function()
local consonants = "bcdfghjklmnpqrstvwxyz"
local result = ""
local count = math.random(10, 100)
for i = 1, count do
local random_index = math.random(1, #consonants)
result = result .. consonants:sub(random_index, random_index)
end
vb.views.PakettieSpeak_text_field.text = result
eSpeak.text.value = result
PakettieSpeakCreateSample()
PakettieSpeakUpdateLineCount()
end
}
local randomize_vowels = vb:button{id = "PakettieSpeak_randomize_vowels",
text = "Randomize Vowels",
width = button_width,
height = 24,
notifier = function()
local vowels = "aeiou"
local result = ""
local count = math.random(10, 100)
for i = 1, count do
local random_index = math.random(1, #vowels)
result = result .. vowels:sub(random_index, random_index)
end
vb.views.PakettieSpeak_text_field.text = result
eSpeak.text.value = result
PakettieSpeakCreateSample()
PakettieSpeakUpdateLineCount()
end
}
local exe_button = vb:button{id="PakettieSpeak_exe_button",
width = control_width,
height = 24,
text = PakettieSpeakRevertPath(eSpeak.executable),
notifier = function()
local filename = renoise.app():prompt_for_filename_to_read({"*.*"}, "Select Executable")
if filename ~= "" then
eSpeak.executable = PakettieSpeakConvertPath(filename)
renoise.tool().preferences.pakettieSpeak.executable = eSpeak.executable
vb.views.PakettieSpeak_exe_button.text = PakettieSpeakRevertPath(eSpeak.executable)
vb.views.PakettieSpeak_exe_button.width = math.min(#vb.views.PakettieSpeak_exe_button.text * 8, control_width)
end end}
local horalign =vb:horizontal_aligner{mode="right",path_to_espeak,exe_button}
local consonants_vowels = vb:row{randomize_consonants,randomize_vowels,}
local loadtext_refresh= vb:row{
vb:button{id = "PakettieSpeak_load_textfile_button",
text = "Load Textfile",
width = button_width,
height = 24,
notifier = function()
PakettieSpeakLoadTextfile(false)
end
},
vb:button{
text = "Refresh",
width = button_width,
height = 24,
notifier = function()
PakettieSpeakLoadTextfile(true)
print("Refresh: loaded textfile and updated textfield")
eSpeak.text.value = vb.views.PakettieSpeak_text_field.text
PakettieSpeakUpdateLineCount()
end
}
}
local eSpeak_textfield= vb:column{
margin = renoise.ViewBuilder.DEFAULT_CONTROL_MARGIN,
spacing = renoise.ViewBuilder.DEFAULT_CONTROL_SPACING,
width = 380,
style = "group",
vb:multiline_textfield{
id = "PakettieSpeak_text_field",
width = 373,
height = 100,
style = "border",
text = tostring(eSpeak.text.value),
notifier = function()
PakettieSpeakUpdateLineCount()
end
}
}
local which_row= vb:row{
vb:text{text = "Which row:", width=80},
vb:valuebox{
id = "PakettieSpeak_which_row",
min = 0,
max = 1,
value = 0,
notifier = function(value)
local text = vb.views.PakettieSpeak_text_field.text
local lines = PakettieSpeakGetLines(text)
if value == 0 then
eSpeak.text.value = text -- Render all text
else
local selected_line = lines[value] or ""
eSpeak.text.value = selected_line
end
if eSpeak.render_on_change.value then
PakettieSpeakCreateSample(eSpeak.text.value)
end
end
}
}
function PakettieSpeakUpdateSelection()
local text = vb.views.PakettieSpeak_text_field.text
local start = vb.views.PakettieSpeak_start_pos.value
local length = vb.views.PakettieSpeak_length_pos.value
local max_length = #text - start + 1
if length > max_length then
length = max_length
vb.views.PakettieSpeak_length_pos.value = length
renoise.app():show_status("No more can be selected")
end
if length == 0 then
vb.views.PakettieSpeak_selection_display.text = ""
else
local end_pos = start + length - 1
if start <= #text and end_pos <= #text and start <= end_pos then
local selected_text = text:sub(start, end_pos)
vb.views.PakettieSpeak_selection_display.text = selected_text
end
end
end
local start_pos= vb:row{
vb:text{text = "Start:", width=80},
vb:valuebox{
id = "PakettieSpeak_start_pos",
min = 1,
max = 500,
value = 1,
notifier = PakettieSpeakUpdateSelection
},
vb:text{text = "Length:"},
vb:valuebox{
id = "PakettieSpeak_length_pos",
min = 0,
max = 500,
value = 0,
notifier = function()
PakettieSpeakUpdateSelection()
end
},
vb:button{
text = "-",
width = 20,
notifier = function()
if vb.views.PakettieSpeak_length_pos.value > 0 then
vb.views.PakettieSpeak_length_pos.value = vb.views.PakettieSpeak_length_pos.value - 1
PakettieSpeakUpdateSelection()
if eSpeak.render_on_change.value then
PakettieSpeakCreateSample(vb.views.PakettieSpeak_selection_display.text)
end
end
end
},
vb:button{
text = "+",
width = 20,
notifier = function()
if vb.views.PakettieSpeak_length_pos.value < 500 then
vb.views.PakettieSpeak_length_pos.value = vb.views.PakettieSpeak_length_pos.value + 1
PakettieSpeakUpdateSelection()
if eSpeak.render_on_change.value then
PakettieSpeakCreateSample(vb.views.PakettieSpeak_selection_display.text)
end
end
end
}
}
local eSpeakselection= vb:row{
vb:text{text = "Selection:", width=80},
vb:textfield{
id = "PakettieSpeak_selection_display",
width = 290,
height = 20,
edit_mode = false
}
}
local eSpeakGenerateSelection= vb:horizontal_aligner{
mode = "center",
vb:button{
text = "Generate Selection",
width = button_width,
height = 24,
notifier = function()
local text = vb.views.PakettieSpeak_text_field.text
local start = vb.views.PakettieSpeak_start_pos.value
local length = vb.views.PakettieSpeak_length_pos.value
local end_pos = start + length - 1
if start <= #text and end_pos <= #text and start <= end_pos then
local selected_text = text:sub(start, end_pos)
print("Selected text:", selected_text)
renoise.app():show_status("Selected text: " .. selected_text)
eSpeak.text.value = selected_text
PakettieSpeakCreateSample()
else
renoise.app():show_status("Invalid selection range")
end
end
}
}
local settingsControls= vb:row{
vb:text{text = "Language:", width = 80},
vb:popup{
id = "PakettieSpeak_language",
width = 250,
items = LANGUAGE_NAMES,
value = eSpeak.language.value,
notifier = function(idx)
if not button_press_active then
eSpeak.language.value = idx
if eSpeak.render_on_change.value then PakettieSpeakCreateSample(eSpeak.text.value) end
end
end
},
vb:button{
text = "-",
width = 20,
notifier = function()
if vb.views.PakettieSpeak_language.value > 1 then
button_press_active = true
vb.views.PakettieSpeak_language.value = vb.views.PakettieSpeak_language.value - 1
eSpeak.language.value = vb.views.PakettieSpeak_language.value
if eSpeak.render_on_change.value then PakettieSpeakCreateSample(eSpeak.text.value) end
button_press_active = false
else
renoise.app():show_status("You are at the beginning of the list.")
end
end
},
vb:button{
text = "+",
width = 20,
notifier = function()
if vb.views.PakettieSpeak_language.value < #LANGUAGE_NAMES then
button_press_active = true
vb.views.PakettieSpeak_language.value = vb.views.PakettieSpeak_language.value + 1
eSpeak.language.value = vb.views.PakettieSpeak_language.value
if eSpeak.render_on_change.value then PakettieSpeakCreateSample(eSpeak.text.value) end
button_press_active = false
else
renoise.app():show_status("You are at the bottom of the list.")
end
end
}
}
local eSpeakvoice= vb:row{
vb:text{text = "Voice:", width = 80}, vb:popup{
id = "PakettieSpeak_voice",
width = 250,
items = VOICES,
value = eSpeak.voice.value,
notifier = function(idx)
if not button_press_active then
eSpeak.voice.value = idx
if eSpeak.render_on_change.value then PakettieSpeakCreateSample(eSpeak.text.value) end
end
end
},
vb:button{
text = "-",
width = 20,
notifier = function()
if vb.views.PakettieSpeak_voice.value > 2 then
button_press_active = true
vb.views.PakettieSpeak_voice.value = vb.views.PakettieSpeak_voice.value - 1
eSpeak.voice.value = vb.views.PakettieSpeak_voice.value
if eSpeak.render_on_change.value then PakettieSpeakCreateSample(eSpeak.text.value) end
button_press_active = false
else
renoise.app():show_status("You are at the beginning of the list")
end
end
},
vb:button{
text = "+",
width = 20,
notifier = function()
if vb.views.PakettieSpeak_voice.value < #VOICES then
button_press_active = true
vb.views.PakettieSpeak_voice.value = vb.views.PakettieSpeak_voice.value + 1
eSpeak.voice.value = vb.views.PakettieSpeak_voice.value
if eSpeak.render_on_change.value then PakettieSpeakCreateSample(eSpeak.text.value) end
button_press_active = false
else
renoise.app():show_status("You are at the bottom of the list")
end
end
}}
local eSpeakgapbox= vb:row{
vb:text{width = 80, text = "Word Gap:"},
vb:valuebox{
id = "PakettieSpeak_gap_box",
width = valuebox_width,
min = 1,
max = 10000,
value = eSpeak.word_gap.value,
steps = {1, 10, 100},
notifier = function(gap)
eSpeak.word_gap.value = gap
print("Word Gap set to:", gap)
end
}
}
local eSpeakpitchcap= vb:row{
vb:text{width = 80, text = "Pitch Capitals:"},
vb:valuebox{
id = "PakettieSpeak_capitals_box",
width = valuebox_width,
min = 1,
max = 100,
value = eSpeak.capitals.value,
steps = {1, 5},
notifier = function(capitals)
eSpeak.capitals.value = capitals
print("Pitch Capitals set to:", capitals)
end
}
}
local eSpeakpitchbox= vb:row{
vb:text{width = 80, text = "Pitch:"},
vb:valuebox{
id = "PakettieSpeak_pitch_box",
width = valuebox_width,
min = 0,
max = 99,
value = eSpeak.pitch.value,
steps = {1, 5},
notifier = function(pitch)
eSpeak.pitch.value = pitch
print("Pitch set to:", pitch)
end
}
}
local eSpeakamplitude= vb:row{
vb:text{width = 80, text = "Amplitude:"},
vb:valuebox{
id = "PakettieSpeak_amplitude_box",
width = valuebox_width,
min = 0,
max = 200,
value = eSpeak.amplitude.value,
steps = {1, 5},
notifier = function(amplitude)
eSpeak.amplitude.value = amplitude
print("Amplitude set to:", amplitude)
end
}
}
local eSpeakspeedbox= vb:row{
vb:text{width = 80, text = "Speed:"},
vb:valuebox{
id = "PakettieSpeak_speed_box",
width = valuebox_width,
min = 1,
max = 500,
value = eSpeak.speed.value,
steps = {1, 5},
notifier = function(speed)
eSpeak.speed.value = speed
print("Speed set to:", speed)
end
}
}
local settingsColumn= vb:column{
margin = renoise.ViewBuilder.DEFAULT_CONTROL_MARGIN,
spacing = renoise.ViewBuilder.DEFAULT_CONTROL_SPACING,
width = 373,
settingsControls,
eSpeakvoice,
eSpeakgapbox,
eSpeakpitchcap,
eSpeakpitchbox,
eSpeakamplitude,
eSpeakspeedbox,}
local clearallsamples= -- Checkboxes
vb:row{
vb:checkbox{
id = "PakettieSpeak_clear_all_samples",
width = 18,
height = 18,
value = eSpeak.clear_all_samples.value == true,
notifier = function(bool)
eSpeak.clear_all_samples.value = bool
print("Clear All Samples set to:", bool)
end
},
vb:text{text = "Overwrite Samples in Selected Instrument"}
}
local addrendertocurrentinstrument=vb:row{
vb:checkbox{
id = "PakettieSpeak_add_render_to_current_instrument",
width = 18,
height = 18,
value = eSpeak.add_render_to_current_instrument.value == true,
notifier = function(bool)
eSpeak.add_render_to_current_instrument.value = bool
vb.views.PakettieSpeak_clear_all_samples.value = false
print("Add Render to Current Instrument set to:", bool)
end
},
vb:text{text = "Add Render to Current Instrument"}
}
local renderonchange= vb:row{
vb:checkbox{
id = "PakettieSpeak_render_on_change",
width = 18,
height = 18,
value = eSpeak.render_on_change.value == true,
notifier = function(bool)
eSpeak.render_on_change.value = bool
print("Render on Change set to:", bool)
end
},
vb:text{text = "+/- Click Should Render Again"}
}
local eSpeakloadsave= vb:horizontal_aligner{
mode = "center",
vb:button{
id = "PakettieSpeak_load_button",
width = button_width,
height = 24,
text = "Load Settings",
notifier = function()
local filename = renoise.app():prompt_for_filename_to_read({"*.rts"}, "Load Settings")
if filename ~= "" then
local result = eSpeak:load_from(filename)
if result == nil then
renoise.app():show_error("Unable to Load Settings.")
else
print("Loaded Settings:", result)
vb.views.PakettieSpeak_text_field.text = tostring(eSpeak.text.value)
vb.views.PakettieSpeak_language.value = eSpeak.language.value
vb.views.PakettieSpeak_voice.value = eSpeak.voice.value
vb.views.PakettieSpeak_gap_box.value = eSpeak.word_gap.value
vb.views.PakettieSpeak_capitals_box.value = eSpeak.capitals.value
vb.views.PakettieSpeak_pitch_box.value = eSpeak.pitch.value
vb.views.PakettieSpeak_amplitude_box.value = eSpeak.amplitude.value
vb.views.PakettieSpeak_speed_box.value = eSpeak.speed.value
local espeak_executable = PakettieSpeakRevertPath(eSpeak.executable)
vb.views.PakettieSpeak_exe_button.text = espeak_executable
vb.views.PakettieSpeak_exe_button.width = math.min(#vb.views.PakettieSpeak_exe_button.text * 8, control_width)
renoise.tool().preferences.pakettieSpeak.executable = espeak_executable
vb.views.PakettieSpeak_clear_all_samples.value = eSpeak.clear_all_samples.value == true
vb.views.PakettieSpeak_render_on_change.value = eSpeak.render_on_change.value == true
PakettieSpeakUpdateLineCount()
end
end
end
},
vb:button{
id = "PakettieSpeak_save_button",
width = button_width,
height = 24,
text = "Save Settings",
notifier = function()
local filename = renoise.app():prompt_for_filename_to_write(".rts", "Save Settings")
if filename ~= "" then
eSpeak.text.value = vb.views.PakettieSpeak_text_field.text
local result = eSpeak:save_as(filename)
if result == nil then
renoise.app():show_error("Unable to Save Settings.")
else
print("Saved Settings:", result)
end
end
end
}
}
local lastbuttons= vb:horizontal_aligner{
mode = "center",
vb:button{
text = "Generate Sample",
width = button_width,
height = 24,
notifier = function()
eSpeak.text.value = vb.views.PakettieSpeak_text_field.text
PakettieSpeakCreateSample()
normalize_selected_sample()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end
},
vb:button{
text = "Randomize Settings",
width = button_width,
height = 24,
notifier = function()
vb.views.PakettieSpeak_language.value = math.random(1, #LANGUAGE_NAMES)
eSpeak.language.value = vb.views.PakettieSpeak_language.value
vb.views.PakettieSpeak_voice.value = math.random(1, #VOICES)
eSpeak.voice.value = vb.views.PakettieSpeak_voice.value
local random_gap = math.random(1, 100)
vb.views.PakettieSpeak_gap_box.value = random_gap
eSpeak.word_gap.value = random_gap
local random_capitals = math.random(1, 100)
vb.views.PakettieSpeak_capitals_box.value = random_capitals
eSpeak.capitals.value = random_capitals
local random_pitch = math.random(0, 99)
vb.views.PakettieSpeak_pitch_box.value = random_pitch
eSpeak.pitch.value = random_pitch
local random_speed = math.random(1, 500)
vb.views.PakettieSpeak_speed_box.value = random_speed
eSpeak.speed.value = random_speed
if eSpeak.render_on_change.value then
PakettieSpeakCreateSample(eSpeak.text.value)
end
eSpeak.text.value = vb.views.PakettieSpeak_text_field.text
PakettieSpeakCreateSample()
normalize_selected_sample()
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
end
}
}
local wholegui=vb:column{
width = dialog_width,
horalign,
randomize_everything,
consonants_vowels,
loadtext_refresh,
eSpeak_textfield,
which_row,
start_pos,
eSpeakselection,
eSpeakGenerateSelection,
settingsColumn,
clearallsamples,
addrendertocurrentinstrument,
renderonchange,
eSpeakloadsave,
lastbuttons}
function PakettieSpeakMakeGUI()
return wholegui
end
function PakettieSpeakShowGUI()
local gui = PakettieSpeakMakeGUI()
dialog = renoise.app():show_custom_dialog("Paketti eSpeak Text-to-Speech", gui, PakettieSpeakKeyHandlerFunc)
PakettieSpeakUpdateLineCount() -- Update line count when showing the dialog
end
function PakettieSpeakPrepare()
print("Starting dialog with settings:")
print("Text:",eSpeak.text.value)
print("Loaded Language:",eSpeak.language.value)
print("Loaded Voice:",eSpeak.voice.value)
print("Loaded Word Gap:",eSpeak.word_gap.value)
print("Loaded Pitch Capitals:",eSpeak.capitals.value)
print("Loaded Pitch:",eSpeak.pitch.value)
print("Loaded Amplitude:",eSpeak.amplitude.value)
print("Loaded Speed:",eSpeak.speed.value)
print("Loaded Executable:",eSpeak.executable.value)
print("Loaded Clear All Samples:",eSpeak.clear_all_samples.value)
if dialog and dialog.visible then
dialog:show()
return
end
local espeak_location = renoise.tool().preferences.pakettieSpeak.executable
if espeak_location ~= "" then
eSpeak.executable = PakettieSpeakConvertPath(espeak_location)
else
renoise.app():show_alert("Please set the eSpeak path before running.")
return
end
PakettieSpeakShowGUI()
end
function PakettieSpeakKeyHandlerFunc(dialog, key)
-- if key.modifiers == "" and key.name == "esc" then
if key.modifiers == "control" and key.name == "r" then
PakettieSpeakLoadTextfile(true)
print("Refresh: loaded textfile and updated textfield")
eSpeak.text.value = vb.views.PakettieSpeak_text_field.text
PakettieSpeakUpdateLineCount()
end
if key.modifiers == "control" and key.name == "return" then
eSpeak.text.value = vb.views.PakettieSpeak_text_field.text
PakettieSpeakCreateSample()
normalize_selected_sample()
end
if key.modifiers == "alt" and key.name == "return" then
local text = vb.views.PakettieSpeak_text_field.text
local start = vb.views.PakettieSpeak_start_pos.value
local length = vb.views.PakettieSpeak_length_pos.value
local end_pos = start + length - 1
if start <= #text and end_pos <= #text and start <= end_pos then
local selected_text = text:sub(start, end_pos)
print("Selected text:", selected_text)
renoise.app():show_status("Selected text: " .. selected_text)
eSpeak.text.value = selected_text
PakettieSpeakCreateSample()
else
renoise.app():show_status("Invalid selection range")
end
end
local closer = preferences.pakettiDialogClose.value
print (closer)
if key.modifiers == "" and key.name == closer then
dialog:close()
dialog = nil
--vb = nil
else
return key
end
end
function PakettieSpeakToggleDialog()
if dialog and dialog.visible then
eSpeak.text.value = vb.views.PakettieSpeak_text_field.text
PakettieSpeakCreateSample()
else
PakettieSpeakPrepare()
end
end
function PakettieSpeakCreateSample(custom_text)
local text_to_render = custom_text or eSpeak.text.value
print(text_to_render)
local executable = PakettieSpeakRevertPath(eSpeak.executable)
local path = os.tmpname() .. ".wav"
local cmd = executable
cmd=cmd .. " -a " .. eSpeak.amplitude.value
cmd=cmd .. " -v " .. LANGUAGE_SHORTS[eSpeak.language.value]
if eSpeak.voice.value ~= 1 then
cmd = cmd .. "+" .. VOICES[eSpeak.voice.value]
end
cmd=cmd .. " -b 1 -m "
cmd=cmd .. " -p " .. eSpeak.pitch.value
cmd=cmd .. " -s " .. eSpeak.speed.value
cmd=cmd .. " -g " .. eSpeak.word_gap.value
cmd=cmd .. " -k " .. eSpeak.capitals.value
cmd=cmd .. " -w " .. path
cmd=cmd .. ' "' .. text_to_render .. '"'
print("Command to be executed:" .. cmd)
os.execute(cmd)
local song = renoise.song()
local instrument
-- **Check if "Add Render to Current Instrument" is Enabled**
if eSpeak.add_render_to_current_instrument.value then
-- **If No Instruments Exist, Load the Pitchbend Instrument**
if #song.instruments == 0 then
pakettiPreferencesDefaultInstrumentLoader()
print("No instruments found. Loaded pitchbend instrument.")
end
instrument = song.selected_instrument
if not instrument then
renoise.app():show_error("No instrument selected and failed to load the pitchbend instrument.")
return
end
-- **Add a New Sample Slot to the Current Instrument**
local new_sample_index = #instrument.samples + 1
local sample = instrument:insert_sample_at(new_sample_index)
song.selected_sample_index = new_sample_index
sample.name = "eSpeak (" .. LANGUAGE_NAMES[eSpeak.language.value] .. ", " .. VOICES_NAMES[eSpeak.voice.value] .. ")"
print("Added new sample slot to current instrument:", sample.name)
elseif eSpeak.clear_all_samples.value then
-- **Existing Behavior: Clear All Samples and Add One**
instrument = song.selected_instrument
pakettiPreferencesDefaultInstrumentLoader()
while #instrument.samples > 0 do
instrument:delete_sample_at(1)
end
local sample = instrument:insert_sample_at(1)
song.selected_sample_index = 1
sample.name = "eSpeak (" .. LANGUAGE_NAMES[eSpeak.language.value] .. ", " .. VOICES_NAMES[eSpeak.voice.value] .. ")"
print("Cleared all samples and added new sample:", sample.name)
else
-- **Existing Behavior: Insert New Instrument and Add Sample**
instrument = song:insert_instrument_at(renoise.song().selected_instrument_index + 1)
song.selected_instrument_index = song.selected_instrument_index + 1
pakettiPreferencesDefaultInstrumentLoader()
instrument = song.selected_instrument
instrument.name = "eSpeak (" .. LANGUAGE_NAMES[eSpeak.language.value] .. ", " .. VOICES_NAMES[eSpeak.voice.value] .. ")"
local sample = instrument:insert_sample_at(1)
sample.name = "eSpeak (" .. LANGUAGE_NAMES[eSpeak.language.value] .. ", " .. VOICES_NAMES[eSpeak.voice.value] .. ")"
song.selected_sample_index = 1
print("Inserted new instrument and added sample:", sample.name)
end
-- **Load the Rendered WAV File into the Selected Sample**
local sample = song.selected_sample
local buffer = sample.sample_buffer
print("Loading path:" .. path)
if not PakettieSpeakFileExists(path) then
renoise.app():show_error("Sample was not rendered. An error happened.")
return
end
local success, result = buffer:load_from(path)
if not success then
renoise.app():show_error("Failed to load sample from " .. path)
return
end
renoise.app().window.active_middle_frame = renoise.ApplicationWindow.MIDDLE_FRAME_INSTRUMENT_SAMPLE_EDITOR
normalize_selected_sample()
print("Sample loaded successfully.")
end
-- **End of Modified Function**
-- Check if file exists
function PakettieSpeakFileExists(path)
local f = io.open(path, "r")
return f ~= nil and io.close(f)
end
renoise.tool():add_menu_entry{name="Sample Editor:Paketti..:Paketti eSpeak Text-to-Speech...",invoke=function() PakettieSpeakToggleDialog() end}
renoise.tool():add_keybinding{name="Global:Paketti:Paketti eSpeak Text-to-Speech",invoke=function() PakettieSpeakToggleDialog() end}
renoise.tool():add_keybinding{name="Global:Paketti:Paketti eSpeak Generate Sample",invoke=function()
if dialog and dialog.visible then
eSpeak.text.value = vb.views.PakettieSpeak_text_field.text
PakettieSpeakCreateSample()
normalize_selected_sample()
else PakettieSpeakPrepare() end end }
renoise.tool():add_keybinding{name="Global:Paketti:Paketti eSpeak Generate Selection",invoke=function()
if dialog and dialog.visible then
local text = vb.views.PakettieSpeak_text_field.text
local start = vb.views.PakettieSpeak_start_pos.value
local length = vb.views.PakettieSpeak_length_pos.value
local end_pos = start + length - 1
if start <= #text and end_pos <= #text and start <= end_pos then
local selected_text = text:sub(start, end_pos)
print("Selected text:", selected_text)
renoise.app():show_status("Selected text: " .. selected_text)
eSpeak.text.value = selected_text
PakettieSpeakCreateSample()
else
renoise.app():show_status("Invalid selection range")
end
else PakettieSpeakPrepare() end end}
for value = 0, 31 do
renoise.tool():add_keybinding{name=("Global:Paketti:Paketti eSpeak Generate Row %02d"):format(value),invoke=function()
local text = vb.views.PakettieSpeak_text_field.text
local lines = PakettieSpeakGetLines(text)
-- If value is 0, take all the content, otherwise select the specific line.
local selected_line = (value == 0) and text or (lines[value] or "")
-- Protection: do nothing if selected line is empty
if selected_line == "" then return end
eSpeak.text.value = selected_line
if eSpeak.render_on_change.value then
PakettieSpeakCreateSample(eSpeak.text.value) end end}
end
renoise.tool():add_keybinding{name="Global:Paketti:Paketti eSpeak Refresh",invoke=function()
if dialog and dialog.visible then
PakettieSpeakLoadTextfile(true)
print("Refresh: loaded textfile and updated textfield")
eSpeak.text.value = vb.views.PakettieSpeak_text_field.text
PakettieSpeakUpdateLineCount()
else PakettieSpeakPrepare() end end}
_AUTO_RELOAD_DEBUG = function() end