File size: 61,930 Bytes
3adf9ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "machine_shape": "hm",
      "gpuType": "A100",
      "authorship_tag": "ABX9TyPdN5espelPFPe/F1OA4L5f",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU",
    "widgets": {
      "application/vnd.jupyter.widget-state+json": {
        "425505387f374468870cc4bcb52ea6c5": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "model_module_version": "1.5.0",
          "state": {
            "_dom_classes": [],
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "HBoxModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/controls",
            "_view_module_version": "1.5.0",
            "_view_name": "HBoxView",
            "box_style": "",
            "children": [
              "IPY_MODEL_9b039beb3d7c4bc59ab95bd5d8a7dfcc",
              "IPY_MODEL_55bf104e557340e5a88962134a765f1b",
              "IPY_MODEL_f0768ce2c3484c4583810f461a0b742e"
            ],
            "layout": "IPY_MODEL_ff7dff340d9f41c29313ca68034be359"
          }
        },
        "9b039beb3d7c4bc59ab95bd5d8a7dfcc": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_dom_classes": [],
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "HTMLModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/controls",
            "_view_module_version": "1.5.0",
            "_view_name": "HTMLView",
            "description": "",
            "description_tooltip": null,
            "layout": "IPY_MODEL_77a54e634f0d44c080eb769a4d2921b0",
            "placeholder": "​",
            "style": "IPY_MODEL_5584c9aaa4e04734bb6833cf7cf76534",
            "value": "Downloading (…)rt_base_ls960_14.pth: 100%"
          }
        },
        "55bf104e557340e5a88962134a765f1b": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "model_module_version": "1.5.0",
          "state": {
            "_dom_classes": [],
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "FloatProgressModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/controls",
            "_view_module_version": "1.5.0",
            "_view_name": "ProgressView",
            "bar_style": "success",
            "description": "",
            "description_tooltip": null,
            "layout": "IPY_MODEL_7a2e70b96a054cdd89f73edd2474e20c",
            "max": 103981977,
            "min": 0,
            "orientation": "horizontal",
            "style": "IPY_MODEL_1120230111694b4d8e63d476b0a35454",
            "value": 103981977
          }
        },
        "f0768ce2c3484c4583810f461a0b742e": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_dom_classes": [],
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "HTMLModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/controls",
            "_view_module_version": "1.5.0",
            "_view_name": "HTMLView",
            "description": "",
            "description_tooltip": null,
            "layout": "IPY_MODEL_643343218af349aaa63afbcd3cbc8009",
            "placeholder": "​",
            "style": "IPY_MODEL_dfb0df17546545a4b74ed7f5f10c7a9a",
            "value": " 104M/104M [00:00<00:00, 406MB/s]"
          }
        },
        "ff7dff340d9f41c29313ca68034be359": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_model_module": "@jupyter-widgets/base",
            "_model_module_version": "1.2.0",
            "_model_name": "LayoutModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "LayoutView",
            "align_content": null,
            "align_items": null,
            "align_self": null,
            "border": null,
            "bottom": null,
            "display": null,
            "flex": null,
            "flex_flow": null,
            "grid_area": null,
            "grid_auto_columns": null,
            "grid_auto_flow": null,
            "grid_auto_rows": null,
            "grid_column": null,
            "grid_gap": null,
            "grid_row": null,
            "grid_template_areas": null,
            "grid_template_columns": null,
            "grid_template_rows": null,
            "height": null,
            "justify_content": null,
            "justify_items": null,
            "left": null,
            "margin": null,
            "max_height": null,
            "max_width": null,
            "min_height": null,
            "min_width": null,
            "object_fit": null,
            "object_position": null,
            "order": null,
            "overflow": null,
            "overflow_x": null,
            "overflow_y": null,
            "padding": null,
            "right": null,
            "top": null,
            "visibility": null,
            "width": null
          }
        },
        "77a54e634f0d44c080eb769a4d2921b0": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_model_module": "@jupyter-widgets/base",
            "_model_module_version": "1.2.0",
            "_model_name": "LayoutModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "LayoutView",
            "align_content": null,
            "align_items": null,
            "align_self": null,
            "border": null,
            "bottom": null,
            "display": null,
            "flex": null,
            "flex_flow": null,
            "grid_area": null,
            "grid_auto_columns": null,
            "grid_auto_flow": null,
            "grid_auto_rows": null,
            "grid_column": null,
            "grid_gap": null,
            "grid_row": null,
            "grid_template_areas": null,
            "grid_template_columns": null,
            "grid_template_rows": null,
            "height": null,
            "justify_content": null,
            "justify_items": null,
            "left": null,
            "margin": null,
            "max_height": null,
            "max_width": null,
            "min_height": null,
            "min_width": null,
            "object_fit": null,
            "object_position": null,
            "order": null,
            "overflow": null,
            "overflow_x": null,
            "overflow_y": null,
            "padding": null,
            "right": null,
            "top": null,
            "visibility": null,
            "width": null
          }
        },
        "5584c9aaa4e04734bb6833cf7cf76534": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "DescriptionStyleModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "StyleView",
            "description_width": ""
          }
        },
        "7a2e70b96a054cdd89f73edd2474e20c": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_model_module": "@jupyter-widgets/base",
            "_model_module_version": "1.2.0",
            "_model_name": "LayoutModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "LayoutView",
            "align_content": null,
            "align_items": null,
            "align_self": null,
            "border": null,
            "bottom": null,
            "display": null,
            "flex": null,
            "flex_flow": null,
            "grid_area": null,
            "grid_auto_columns": null,
            "grid_auto_flow": null,
            "grid_auto_rows": null,
            "grid_column": null,
            "grid_gap": null,
            "grid_row": null,
            "grid_template_areas": null,
            "grid_template_columns": null,
            "grid_template_rows": null,
            "height": null,
            "justify_content": null,
            "justify_items": null,
            "left": null,
            "margin": null,
            "max_height": null,
            "max_width": null,
            "min_height": null,
            "min_width": null,
            "object_fit": null,
            "object_position": null,
            "order": null,
            "overflow": null,
            "overflow_x": null,
            "overflow_y": null,
            "padding": null,
            "right": null,
            "top": null,
            "visibility": null,
            "width": null
          }
        },
        "1120230111694b4d8e63d476b0a35454": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "ProgressStyleModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "StyleView",
            "bar_color": null,
            "description_width": ""
          }
        },
        "643343218af349aaa63afbcd3cbc8009": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_model_module": "@jupyter-widgets/base",
            "_model_module_version": "1.2.0",
            "_model_name": "LayoutModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "LayoutView",
            "align_content": null,
            "align_items": null,
            "align_self": null,
            "border": null,
            "bottom": null,
            "display": null,
            "flex": null,
            "flex_flow": null,
            "grid_area": null,
            "grid_auto_columns": null,
            "grid_auto_flow": null,
            "grid_auto_rows": null,
            "grid_column": null,
            "grid_gap": null,
            "grid_row": null,
            "grid_template_areas": null,
            "grid_template_columns": null,
            "grid_template_rows": null,
            "height": null,
            "justify_content": null,
            "justify_items": null,
            "left": null,
            "margin": null,
            "max_height": null,
            "max_width": null,
            "min_height": null,
            "min_width": null,
            "object_fit": null,
            "object_position": null,
            "order": null,
            "overflow": null,
            "overflow_x": null,
            "overflow_y": null,
            "padding": null,
            "right": null,
            "top": null,
            "visibility": null,
            "width": null
          }
        },
        "dfb0df17546545a4b74ed7f5f10c7a9a": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "DescriptionStyleModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "StyleView",
            "description_width": ""
          }
        }
      }
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/KevinWang676/Bark-Voice-Cloning/blob/main/Bark_Voice_Cloning_UI.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "n281rhWYnEbf",
        "outputId": "cf8d7edf-63ff-4b7f-9cc0-97640e113c1b"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Cloning into 'Bark-Voice-Cloning'...\n",
            "remote: Enumerating objects: 132, done.\u001b[K\n",
            "remote: Counting objects: 100% (59/59), done.\u001b[K\n",
            "remote: Compressing objects: 100% (59/59), done.\u001b[K\n",
            "remote: Total 132 (delta 30), reused 0 (delta 0), pack-reused 73\u001b[K\n",
            "Receiving objects: 100% (132/132), 225.44 KiB | 15.03 MiB/s, done.\n",
            "Resolving deltas: 100% (38/38), done.\n"
          ]
        }
      ],
      "source": [
        "!git clone https://github.com/KevinWang676/Bark-Voice-Cloning.git"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "cd Bark-Voice-Cloning/"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "uyyMhQgBnJLG",
        "outputId": "4a91aa03-787c-41e8-b59d-dbddc9eed3b8"
      },
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content/Bark-Voice-Cloning\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "pip install -r requirements.txt"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "fm8b-BXPnPDb",
        "outputId": "df4bfdec-d418-4edd-d41b-7cf4d40a6a2e"
      },
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
            "Ignoring fairseq: markers 'platform_system == \"Windows\"' don't match your environment\n",
            "Ignoring soundfile: markers 'platform_system == \"Windows\"' don't match your environment\n",
            "Requirement already satisfied: fairseq in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 1)) (0.12.2)\n",
            "Requirement already satisfied: audiolm-pytorch in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 3)) (1.1.4)\n",
            "Requirement already satisfied: gradio in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 4)) (3.34.0)\n",
            "Requirement already satisfied: funcy in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 5)) (2.0)\n",
            "Requirement already satisfied: linkify in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 6)) (1.4)\n",
            "Requirement already satisfied: mutagen in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 7)) (1.46.0)\n",
            "Requirement already satisfied: pytorch_seed in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 8)) (0.2.0)\n",
            "Requirement already satisfied: pyyaml in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 9)) (6.0)\n",
            "Requirement already satisfied: sentencepiece in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 10)) (0.1.99)\n",
            "Requirement already satisfied: sox in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 12)) (1.4.1)\n",
            "Requirement already satisfied: transformers in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 13)) (4.30.1)\n",
            "Requirement already satisfied: cffi in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (1.15.1)\n",
            "Requirement already satisfied: cython in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (0.29.34)\n",
            "Requirement already satisfied: hydra-core<1.1,>=1.0.7 in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (1.0.7)\n",
            "Requirement already satisfied: omegaconf<2.1 in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (2.0.6)\n",
            "Requirement already satisfied: regex in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (2022.10.31)\n",
            "Requirement already satisfied: sacrebleu>=1.4.12 in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (2.3.1)\n",
            "Requirement already satisfied: torch in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (2.0.1+cu118)\n",
            "Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (4.65.0)\n",
            "Requirement already satisfied: bitarray in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (2.7.5)\n",
            "Requirement already satisfied: torchaudio>=0.8.0 in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (2.0.2+cu118)\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from fairseq->-r requirements.txt (line 1)) (1.22.4)\n",
            "Requirement already satisfied: accelerate in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (0.20.3)\n",
            "Requirement already satisfied: beartype in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (0.14.1)\n",
            "Requirement already satisfied: einops>=0.6.1 in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (0.6.1)\n",
            "Requirement already satisfied: ema-pytorch>=0.2.2 in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (0.2.3)\n",
            "Requirement already satisfied: encodec in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (0.1.1)\n",
            "Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (1.2.0)\n",
            "Requirement already satisfied: lion-pytorch in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (0.1.2)\n",
            "Requirement already satisfied: local-attention>=1.8.4 in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (1.8.6)\n",
            "Requirement already satisfied: scikit-learn in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (1.2.2)\n",
            "Requirement already satisfied: vector-quantize-pytorch>=1.5.14 in /usr/local/lib/python3.10/dist-packages (from audiolm-pytorch->-r requirements.txt (line 3)) (1.6.11)\n",
            "Requirement already satisfied: aiofiles in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (23.1.0)\n",
            "Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (3.8.4)\n",
            "Requirement already satisfied: altair>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (4.2.2)\n",
            "Requirement already satisfied: fastapi in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (0.97.0)\n",
            "Requirement already satisfied: ffmpy in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (0.3.0)\n",
            "Requirement already satisfied: gradio-client>=0.2.6 in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (0.2.6)\n",
            "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (0.24.1)\n",
            "Requirement already satisfied: huggingface-hub>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (0.15.1)\n",
            "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (3.1.2)\n",
            "Requirement already satisfied: markdown-it-py[linkify]>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (2.2.0)\n",
            "Requirement already satisfied: markupsafe in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (2.1.2)\n",
            "Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (3.7.1)\n",
            "Requirement already satisfied: mdit-py-plugins<=0.3.3 in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (0.3.3)\n",
            "Requirement already satisfied: orjson in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (3.9.1)\n",
            "Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (1.5.3)\n",
            "Requirement already satisfied: pillow in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (8.4.0)\n",
            "Requirement already satisfied: pydantic in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (1.10.7)\n",
            "Requirement already satisfied: pydub in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (0.25.1)\n",
            "Requirement already satisfied: pygments>=2.12.0 in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (2.14.0)\n",
            "Requirement already satisfied: python-multipart in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (0.0.6)\n",
            "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (2.27.1)\n",
            "Requirement already satisfied: semantic-version in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (2.10.0)\n",
            "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (4.5.0)\n",
            "Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (0.22.0)\n",
            "Requirement already satisfied: websockets>=10.0 in /usr/local/lib/python3.10/dist-packages (from gradio->-r requirements.txt (line 4)) (11.0.3)\n",
            "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 13)) (3.12.0)\n",
            "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 13)) (23.1)\n",
            "Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 13)) (0.13.3)\n",
            "Requirement already satisfied: safetensors>=0.3.1 in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 13)) (0.3.1)\n",
            "Requirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair>=4.2.0->gradio->-r requirements.txt (line 4)) (0.4)\n",
            "Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair>=4.2.0->gradio->-r requirements.txt (line 4)) (4.3.3)\n",
            "Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair>=4.2.0->gradio->-r requirements.txt (line 4)) (0.12.0)\n",
            "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client>=0.2.6->gradio->-r requirements.txt (line 4)) (2023.4.0)\n",
            "Requirement already satisfied: antlr4-python3-runtime==4.8 in /usr/local/lib/python3.10/dist-packages (from hydra-core<1.1,>=1.0.7->fairseq->-r requirements.txt (line 1)) (4.8)\n",
            "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py[linkify]>=2.0.0->gradio->-r requirements.txt (line 4)) (0.1.2)\n",
            "Requirement already satisfied: linkify-it-py<3,>=1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py[linkify]>=2.0.0->gradio->-r requirements.txt (line 4)) (2.0.2)\n",
            "Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas->gradio->-r requirements.txt (line 4)) (2.8.2)\n",
            "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->gradio->-r requirements.txt (line 4)) (2022.7.1)\n",
            "Requirement already satisfied: portalocker in /usr/local/lib/python3.10/dist-packages (from sacrebleu>=1.4.12->fairseq->-r requirements.txt (line 1)) (2.7.0)\n",
            "Requirement already satisfied: tabulate>=0.8.9 in /usr/local/lib/python3.10/dist-packages (from sacrebleu>=1.4.12->fairseq->-r requirements.txt (line 1)) (0.8.10)\n",
            "Requirement already satisfied: colorama in /usr/local/lib/python3.10/dist-packages (from sacrebleu>=1.4.12->fairseq->-r requirements.txt (line 1)) (0.4.6)\n",
            "Requirement already satisfied: lxml in /usr/local/lib/python3.10/dist-packages (from sacrebleu>=1.4.12->fairseq->-r requirements.txt (line 1)) (4.9.2)\n",
            "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch->fairseq->-r requirements.txt (line 1)) (1.11.1)\n",
            "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch->fairseq->-r requirements.txt (line 1)) (3.1)\n",
            "Requirement already satisfied: triton==2.0.0 in /usr/local/lib/python3.10/dist-packages (from torch->fairseq->-r requirements.txt (line 1)) (2.0.0)\n",
            "Requirement already satisfied: cmake in /usr/local/lib/python3.10/dist-packages (from triton==2.0.0->torch->fairseq->-r requirements.txt (line 1)) (3.25.2)\n",
            "Requirement already satisfied: lit in /usr/local/lib/python3.10/dist-packages (from triton==2.0.0->torch->fairseq->-r requirements.txt (line 1)) (16.0.5)\n",
            "Requirement already satisfied: click>=7.0 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio->-r requirements.txt (line 4)) (8.1.3)\n",
            "Requirement already satisfied: h11>=0.8 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio->-r requirements.txt (line 4)) (0.14.0)\n",
            "Requirement already satisfied: psutil in /usr/local/lib/python3.10/dist-packages (from accelerate->audiolm-pytorch->-r requirements.txt (line 3)) (5.9.5)\n",
            "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->gradio->-r requirements.txt (line 4)) (23.1.0)\n",
            "Requirement already satisfied: charset-normalizer<4.0,>=2.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->gradio->-r requirements.txt (line 4)) (2.0.12)\n",
            "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->gradio->-r requirements.txt (line 4)) (6.0.4)\n",
            "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /usr/local/lib/python3.10/dist-packages (from aiohttp->gradio->-r requirements.txt (line 4)) (4.0.2)\n",
            "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->gradio->-r requirements.txt (line 4)) (1.9.2)\n",
            "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->gradio->-r requirements.txt (line 4)) (1.3.3)\n",
            "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->gradio->-r requirements.txt (line 4)) (1.3.1)\n",
            "Requirement already satisfied: pycparser in /usr/local/lib/python3.10/dist-packages (from cffi->fairseq->-r requirements.txt (line 1)) (2.21)\n",
            "Requirement already satisfied: starlette<0.28.0,>=0.27.0 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio->-r requirements.txt (line 4)) (0.27.0)\n",
            "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->gradio->-r requirements.txt (line 4)) (2022.12.7)\n",
            "Requirement already satisfied: httpcore<0.18.0,>=0.15.0 in /usr/local/lib/python3.10/dist-packages (from httpx->gradio->-r requirements.txt (line 4)) (0.17.2)\n",
            "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->gradio->-r requirements.txt (line 4)) (3.4)\n",
            "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->gradio->-r requirements.txt (line 4)) (1.3.0)\n",
            "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->gradio->-r requirements.txt (line 4)) (1.0.7)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->gradio->-r requirements.txt (line 4)) (0.11.0)\n",
            "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->gradio->-r requirements.txt (line 4)) (4.39.3)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->gradio->-r requirements.txt (line 4)) (1.4.4)\n",
            "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->gradio->-r requirements.txt (line 4)) (3.0.9)\n",
            "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->gradio->-r requirements.txt (line 4)) (1.26.15)\n",
            "Requirement already satisfied: scipy>=1.3.2 in /usr/local/lib/python3.10/dist-packages (from scikit-learn->audiolm-pytorch->-r requirements.txt (line 3)) (1.10.1)\n",
            "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn->audiolm-pytorch->-r requirements.txt (line 3)) (3.1.0)\n",
            "Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.10/dist-packages (from httpcore<0.18.0,>=0.15.0->httpx->gradio->-r requirements.txt (line 4)) (3.6.2)\n",
            "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair>=4.2.0->gradio->-r requirements.txt (line 4)) (0.19.3)\n",
            "Requirement already satisfied: uc-micro-py in /usr/local/lib/python3.10/dist-packages (from linkify-it-py<3,>=1->markdown-it-py[linkify]>=2.0.0->gradio->-r requirements.txt (line 4)) (1.0.2)\n",
            "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.1->pandas->gradio->-r requirements.txt (line 4)) (1.16.0)\n",
            "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch->fairseq->-r requirements.txt (line 1)) (1.3.0)\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from cProfile import label\n",
        "import dataclasses\n",
        "from distutils.command.check import check\n",
        "from doctest import Example\n",
        "import gradio as gr\n",
        "import os\n",
        "import sys\n",
        "import numpy as np\n",
        "import logging\n",
        "import torch\n",
        "import pytorch_seed\n",
        "import time\n",
        "\n",
        "from xml.sax import saxutils\n",
        "from bark.api import generate_with_settings\n",
        "from bark.api import save_as_prompt\n",
        "from util.settings import Settings\n",
        "#import nltk\n",
        "\n",
        "from bark import SAMPLE_RATE\n",
        "from cloning.clonevoice import clone_voice\n",
        "from bark.generation import SAMPLE_RATE, preload_models, _load_history_prompt, codec_decode\n",
        "from scipy.io.wavfile import write as write_wav\n",
        "from util.parseinput import split_and_recombine_text, build_ssml, is_ssml, create_clips_from_ssml\n",
        "from datetime import datetime\n",
        "from tqdm.auto import tqdm\n",
        "from util.helper import create_filename, add_id3_tag\n",
        "from swap_voice import swap_voice_from_audio\n",
        "from training.training_prepare import prepare_semantics_from_text, prepare_wavs_from_semantics\n",
        "from training.train import training_prepare_files, train\n",
        "\n",
        "settings = Settings('config.yaml')\n",
        "\n",
        "\n",
        "def generate_text_to_speech(text, selected_speaker, text_temp, waveform_temp, eos_prob, quick_generation, complete_settings, seed, batchcount, progress=gr.Progress(track_tqdm=True)):\n",
        "    # Chunk the text into smaller pieces then combine the generated audio\n",
        "\n",
        "    # generation settings\n",
        "    if selected_speaker == 'None':\n",
        "        selected_speaker = None\n",
        "\n",
        "    voice_name = selected_speaker\n",
        "\n",
        "    if text == None or len(text) < 1:\n",
        "       if selected_speaker == None:\n",
        "            raise gr.Error('No text entered!')\n",
        "\n",
        "       # Extract audio data from speaker if no text and speaker selected\n",
        "       voicedata = _load_history_prompt(voice_name)\n",
        "       audio_arr = codec_decode(voicedata[\"fine_prompt\"])\n",
        "       result = create_filename(settings.output_folder_path, \"None\", \"extract\",\".wav\")\n",
        "       save_wav(audio_arr, result)\n",
        "       return result\n",
        "\n",
        "    if batchcount < 1:\n",
        "        batchcount = 1\n",
        "\n",
        "\n",
        "    silenceshort = np.zeros(int((float(settings.silence_sentence) / 1000.0) * SAMPLE_RATE), dtype=np.int16)  # quarter second of silence\n",
        "    silencelong = np.zeros(int((float(settings.silence_speakers) / 1000.0) * SAMPLE_RATE), dtype=np.float32)  # half a second of silence\n",
        "    use_last_generation_as_history = \"Use last generation as history\" in complete_settings\n",
        "    save_last_generation = \"Save generation as Voice\" in complete_settings\n",
        "    for l in range(batchcount):\n",
        "        currentseed = seed\n",
        "        if seed != None and seed > 2**32 - 1:\n",
        "            logger.warning(f\"Seed {seed} > 2**32 - 1 (max), setting to random\")\n",
        "            currentseed = None\n",
        "        if currentseed == None or currentseed <= 0:\n",
        "            currentseed = np.random.default_rng().integers(1, 2**32 - 1)\n",
        "        assert(0 < currentseed and currentseed < 2**32)\n",
        "\n",
        "        progress(0, desc=\"Generating\")\n",
        "\n",
        "        full_generation = None\n",
        "\n",
        "        all_parts = []\n",
        "        complete_text = \"\"\n",
        "        text = text.lstrip()\n",
        "        if is_ssml(text):\n",
        "            list_speak = create_clips_from_ssml(text)\n",
        "            prev_speaker = None\n",
        "            for i, clip in tqdm(enumerate(list_speak), total=len(list_speak)):\n",
        "                selected_speaker = clip[0]\n",
        "                # Add pause break between speakers\n",
        "                if i > 0 and selected_speaker != prev_speaker:\n",
        "                    all_parts += [silencelong.copy()]\n",
        "                prev_speaker = selected_speaker\n",
        "                text = clip[1]\n",
        "                text = saxutils.unescape(text)\n",
        "                if selected_speaker == \"None\":\n",
        "                    selected_speaker = None\n",
        "\n",
        "                print(f\"\\nGenerating Text ({i+1}/{len(list_speak)}) -> {selected_speaker} (Seed {currentseed}):`{text}`\")\n",
        "                complete_text += text\n",
        "                with pytorch_seed.SavedRNG(currentseed):\n",
        "                    audio_array = generate_with_settings(text_prompt=text, voice_name=selected_speaker, semantic_temp=text_temp, coarse_temp=waveform_temp, eos_p=eos_prob)\n",
        "                    currentseed = torch.random.initial_seed()\n",
        "                if len(list_speak) > 1:\n",
        "                    filename = create_filename(settings.output_folder_path, currentseed, \"audioclip\",\".wav\")\n",
        "                    save_wav(audio_array, filename)\n",
        "                    add_id3_tag(filename, text, selected_speaker, currentseed)\n",
        "\n",
        "                all_parts += [audio_array]\n",
        "        else:\n",
        "            texts = split_and_recombine_text(text, settings.input_text_desired_length, settings.input_text_max_length)\n",
        "            for i, text in tqdm(enumerate(texts), total=len(texts)):\n",
        "                print(f\"\\nGenerating Text ({i+1}/{len(texts)}) -> {selected_speaker} (Seed {currentseed}):`{text}`\")\n",
        "                complete_text += text\n",
        "                if quick_generation == True:\n",
        "                    with pytorch_seed.SavedRNG(currentseed):\n",
        "                        audio_array = generate_with_settings(text_prompt=text, voice_name=selected_speaker, semantic_temp=text_temp, coarse_temp=waveform_temp, eos_p=eos_prob)\n",
        "                        currentseed = torch.random.initial_seed()\n",
        "                else:\n",
        "                    full_output = use_last_generation_as_history or save_last_generation\n",
        "                    if full_output:\n",
        "                        full_generation, audio_array = generate_with_settings(text_prompt=text, voice_name=voice_name, semantic_temp=text_temp, coarse_temp=waveform_temp, eos_p=eos_prob, output_full=True)\n",
        "                    else:\n",
        "                        audio_array = generate_with_settings(text_prompt=text, voice_name=voice_name, semantic_temp=text_temp, coarse_temp=waveform_temp, eos_p=eos_prob)\n",
        "\n",
        "                # Noticed this in the HF Demo - convert to 16bit int -32767/32767 - most used audio format  \n",
        "                # audio_array = (audio_array * 32767).astype(np.int16)\n",
        "\n",
        "                if len(texts) > 1:\n",
        "                    filename = create_filename(settings.output_folder_path, currentseed, \"audioclip\",\".wav\")\n",
        "                    save_wav(audio_array, filename)\n",
        "                    add_id3_tag(filename, text, selected_speaker, currentseed)\n",
        "\n",
        "                if quick_generation == False and (save_last_generation == True or use_last_generation_as_history == True):\n",
        "                    # save to npz\n",
        "                    voice_name = create_filename(settings.output_folder_path, seed, \"audioclip\", \".npz\")\n",
        "                    save_as_prompt(voice_name, full_generation)\n",
        "                    if use_last_generation_as_history:\n",
        "                        selected_speaker = voice_name\n",
        "\n",
        "                all_parts += [audio_array]\n",
        "                # Add short pause between sentences\n",
        "                if text[-1] in \"!?.\\n\" and i > 1:\n",
        "                    all_parts += [silenceshort.copy()]\n",
        "\n",
        "        # save & play audio\n",
        "        result = create_filename(settings.output_folder_path, currentseed, \"final\",\".wav\")\n",
        "        save_wav(np.concatenate(all_parts), result)\n",
        "        # write id3 tag with text truncated to 60 chars, as a precaution...\n",
        "        add_id3_tag(result, complete_text, selected_speaker, currentseed)\n",
        "\n",
        "    return result\n",
        "\n",
        "\n",
        "\n",
        "def save_wav(audio_array, filename):\n",
        "    write_wav(filename, SAMPLE_RATE, audio_array)\n",
        "\n",
        "def save_voice(filename, semantic_prompt, coarse_prompt, fine_prompt):\n",
        "    np.savez_compressed(\n",
        "        filename,\n",
        "        semantic_prompt=semantic_prompt,\n",
        "        coarse_prompt=coarse_prompt,\n",
        "        fine_prompt=fine_prompt\n",
        "    )\n",
        "    \n",
        "\n",
        "def on_quick_gen_changed(checkbox):\n",
        "    if checkbox == False:\n",
        "        return gr.CheckboxGroup.update(visible=True)\n",
        "    return gr.CheckboxGroup.update(visible=False)\n",
        "\n",
        "def delete_output_files(checkbox_state):\n",
        "    if checkbox_state:\n",
        "        outputs_folder = os.path.join(os.getcwd(), settings.output_folder_path)\n",
        "        if os.path.exists(outputs_folder):\n",
        "            purgedir(outputs_folder)\n",
        "    return False\n",
        "\n",
        "\n",
        "# https://stackoverflow.com/a/54494779\n",
        "def purgedir(parent):\n",
        "    for root, dirs, files in os.walk(parent):                                      \n",
        "        for item in files:\n",
        "            # Delete subordinate files                                                 \n",
        "            filespec = os.path.join(root, item)\n",
        "            os.unlink(filespec)\n",
        "        for item in dirs:\n",
        "            # Recursively perform this operation for subordinate directories   \n",
        "            purgedir(os.path.join(root, item))\n",
        "\n",
        "def convert_text_to_ssml(text, selected_speaker):\n",
        "    return build_ssml(text, selected_speaker)\n",
        "\n",
        "\n",
        "def training_prepare(selected_step, num_text_generations, progress=gr.Progress(track_tqdm=True)):\n",
        "    if selected_step == prepare_training_list[0]:\n",
        "        prepare_semantics_from_text()\n",
        "    else:\n",
        "        prepare_wavs_from_semantics()\n",
        "    return None\n",
        "\n",
        "\n",
        "def start_training(save_model_epoch, max_epochs, progress=gr.Progress(track_tqdm=True)):\n",
        "    training_prepare_files(\"./training/data/\", \"./training/data/checkpoint/hubert_base_ls960.pt\")\n",
        "    train(\"./training/data/\", save_model_epoch, max_epochs)\n",
        "    return None\n",
        "\n",
        "\n",
        "\n",
        "def apply_settings(themes, input_server_name, input_server_port, input_server_public, input_desired_len, input_max_len, input_silence_break, input_silence_speaker):\n",
        "    settings.selected_theme = themes\n",
        "    settings.server_name = input_server_name\n",
        "    settings.server_port = input_server_port\n",
        "    settings.server_share = input_server_public\n",
        "    settings.input_text_desired_length = input_desired_len\n",
        "    settings.input_text_max_length = input_max_len\n",
        "    settings.silence_sentence = input_silence_break\n",
        "    settings.silence_speaker = input_silence_speaker\n",
        "    settings.save()\n",
        "\n",
        "def restart():\n",
        "    global restart_server\n",
        "    restart_server = True\n",
        "\n",
        "\n",
        "def create_version_html():\n",
        "    python_version = \".\".join([str(x) for x in sys.version_info[0:3]])\n",
        "    versions_html = f\"\"\"\n",
        "python: <span title=\"{sys.version}\">{python_version}</span>\n",
        "β€€β€’β€€\n",
        "torch: {getattr(torch, '__long_version__',torch.__version__)}\n",
        "β€€β€’β€€\n",
        "gradio: {gr.__version__}\n",
        "\"\"\"\n",
        "    return versions_html\n",
        "\n",
        "    \n",
        "\n",
        "logger = logging.getLogger(__name__)\n",
        "APPTITLE = \"Bark Voice Cloning UI\"\n",
        "\n",
        "\n",
        "autolaunch = False\n",
        "\n",
        "if len(sys.argv) > 1:\n",
        "    autolaunch = \"-autolaunch\" in sys.argv\n",
        "\n",
        "\n",
        "if torch.cuda.is_available() == False:\n",
        "    os.environ['BARK_FORCE_CPU'] = 'True'\n",
        "    logger.warning(\"No CUDA detected, fallback to CPU!\")\n",
        "\n",
        "print(f'smallmodels={os.environ.get(\"SUNO_USE_SMALL_MODELS\", False)}')\n",
        "print(f'enablemps={os.environ.get(\"SUNO_ENABLE_MPS\", False)}')\n",
        "print(f'offloadcpu={os.environ.get(\"SUNO_OFFLOAD_CPU\", False)}')\n",
        "print(f'forcecpu={os.environ.get(\"BARK_FORCE_CPU\", False)}')\n",
        "print(f'autolaunch={autolaunch}\\n\\n')\n",
        "\n",
        "#print(\"Updating nltk\\n\")\n",
        "#nltk.download('punkt')\n",
        "\n",
        "print(\"Preloading Models\\n\")\n",
        "preload_models()\n",
        "\n",
        "available_themes = [\"Default\", \"gradio/glass\", \"gradio/monochrome\", \"gradio/seafoam\", \"gradio/soft\", \"gstaff/xkcd\", \"freddyaboulton/dracula_revamped\", \"ysharma/steampunk\"]\n",
        "tokenizer_language_list = [\"de\",\"en\", \"pl\"]\n",
        "prepare_training_list = [\"Step 1: Semantics from Text\",\"Step 2: WAV from Semantics\"]\n",
        "\n",
        "seed = -1\n",
        "server_name = settings.server_name\n",
        "if len(server_name) < 1:\n",
        "    server_name = None\n",
        "server_port = settings.server_port\n",
        "if server_port <= 0:\n",
        "    server_port = None\n",
        "global run_server\n",
        "global restart_server\n",
        "\n",
        "run_server = True\n",
        "\n",
        "while run_server:\n",
        "    # Collect all existing speakers/voices in dir\n",
        "    speakers_list = []\n",
        "\n",
        "    for root, dirs, files in os.walk(\"./bark/assets/prompts\"):\n",
        "        for file in files:\n",
        "            if file.endswith(\".npz\"):\n",
        "                pathpart = root.replace(\"./bark/assets/prompts\", \"\")\n",
        "                name = os.path.join(pathpart, file[:-4])\n",
        "                if name.startswith(\"/\") or name.startswith(\"\\\\\"):\n",
        "                     name = name[1:]\n",
        "                speakers_list.append(name)\n",
        "\n",
        "    speakers_list = sorted(speakers_list, key=lambda x: x.lower())\n",
        "    speakers_list.insert(0, 'None')\n",
        "\n",
        "    print(f'Launching {APPTITLE} Server')\n",
        "\n",
        "    # Create Gradio Blocks\n",
        "\n",
        "    with gr.Blocks(title=f\"{APPTITLE}\", mode=f\"{APPTITLE}\", theme=settings.selected_theme) as barkgui:\n",
        "        with gr.Row():\n",
        "            with gr.Column():\n",
        "                gr.Markdown(f\"### [{APPTITLE}](https://github.com/KevinWang676/Bark-Voice-Cloning)\")\n",
        "            with gr.Column():\n",
        "                gr.HTML(create_version_html(), elem_id=\"versions\")\n",
        "\n",
        "        with gr.Tab(\"Clone Voice\"):\n",
        "            with gr.Row():\n",
        "                input_audio_filename = gr.Audio(label=\"Input audio.wav\", source=\"upload\", type=\"filepath\")\n",
        "            #transcription_text = gr.Textbox(label=\"Transcription Text\", lines=1, placeholder=\"Enter Text of your Audio Sample here...\")\n",
        "            with gr.Row():\n",
        "                with gr.Column():\n",
        "                    initialname = \"/content/Bark-Voice-Cloning/bark/assets/prompts/file\"\n",
        "                    output_voice = gr.Textbox(label=\"Filename of trained Voice (do not change the initial name)\", lines=1, placeholder=initialname, value=initialname)\n",
        "                with gr.Column():\n",
        "                    tokenizerlang = gr.Dropdown(tokenizer_language_list, label=\"Base Language Tokenizer\", value=tokenizer_language_list[1])\n",
        "            with gr.Row():\n",
        "                clone_voice_button = gr.Button(\"Create Voice\")\n",
        "            with gr.Row():\n",
        "                dummy = gr.Text(label=\"Progress\")\n",
        "                npz_file = gr.File(label=\".npz file\")\n",
        "            speakers_list.insert(0, npz_file) # add prompt\n",
        "\n",
        "        with gr.Tab(\"TTS\"):\n",
        "            with gr.Row():\n",
        "                with gr.Column():\n",
        "                    placeholder = \"Enter text here.\"\n",
        "                    input_text = gr.Textbox(label=\"Input Text\", lines=4, placeholder=placeholder)\n",
        "                with gr.Column():\n",
        "                        seedcomponent = gr.Number(label=\"Seed (default -1 = Random)\", precision=0, value=-1)\n",
        "                        batchcount = gr.Number(label=\"Batch count\", precision=0, value=1)\n",
        "            with gr.Row():\n",
        "                with gr.Column():\n",
        "                    examples = [\n",
        "                        \"Special meanings: [laughter] [laughs] [sighs] [music] [gasps] [clears throat] MAN: WOMAN:\",\n",
        "                       \"β™ͺ Never gonna make you cry, never gonna say goodbye, never gonna tell a lie and hurt you β™ͺ\",\n",
        "                       \"And now β€” a picture of a larch [laughter]\",\n",
        "                       \"\"\"\n",
        "                            WOMAN: I would like an oatmilk latte please.\n",
        "                            MAN: Wow, that's expensive!\n",
        "                       \"\"\",\n",
        "                       \"\"\"<?xml version=\"1.0\"?>\n",
        "    <speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\"\n",
        "             xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n",
        "             xsi:schemaLocation=\"http://www.w3.org/2001/10/synthesis\n",
        "                       http://www.w3.org/TR/speech-synthesis/synthesis.xsd\"\n",
        "             xml:lang=\"en-US\">\n",
        "    <voice name=\"/v2/en_speaker_9\">Look at that drunk guy!</voice>\n",
        "    <voice name=\"/v2/en_speaker_3\">Who is he?</voice>\n",
        "    <voice name=\"/v2/en_speaker_9\">WOMAN: [clears throat] 10 years ago, he proposed me and I rejected him.</voice>\n",
        "    <voice name=\"/v2/en_speaker_3\">Oh my God [laughs] he is still celebrating</voice>\n",
        "    </speak>\"\"\"\n",
        "                       ]\n",
        "                    examples = gr.Examples(examples=examples, inputs=input_text)\n",
        "                with gr.Column():\n",
        "                    convert_to_ssml_button = gr.Button(\"Convert Input Text to SSML\")\n",
        "\n",
        "            with gr.Row():\n",
        "                with gr.Column():\n",
        "                    gr.Markdown(\"[Voice Prompt Library](https://suno-ai.notion.site/8b8e8749ed514b0cbf3f699013548683?v=bc67cff786b04b50b3ceb756fd05f68c)\")\n",
        "                    speaker = gr.Dropdown(speakers_list, value=speakers_list[0], label=\"Voice\")\n",
        "                    \n",
        "                with gr.Column():\n",
        "                    text_temp = gr.Slider(0.1, 1.0, value=0.6, label=\"Generation Temperature\", info=\"1.0 more diverse, 0.1 more conservative\")\n",
        "                    waveform_temp = gr.Slider(0.1, 1.0, value=0.7, label=\"Waveform temperature\", info=\"1.0 more diverse, 0.1 more conservative\")\n",
        "\n",
        "            with gr.Row():\n",
        "                with gr.Column():\n",
        "                    quick_gen_checkbox = gr.Checkbox(label=\"Quick Generation\", value=True)\n",
        "                    settings_checkboxes = [\"Use last generation as history\", \"Save generation as Voice\"]\n",
        "                    complete_settings = gr.CheckboxGroup(choices=settings_checkboxes, value=settings_checkboxes, label=\"Detailed Generation Settings\", type=\"value\", interactive=True, visible=False)\n",
        "                with gr.Column():\n",
        "                    eos_prob = gr.Slider(0.0, 0.5, value=0.05, label=\"End of sentence probability\")\n",
        "\n",
        "            with gr.Row():\n",
        "                with gr.Column():\n",
        "                    tts_create_button = gr.Button(\"Generate\")\n",
        "                with gr.Column():\n",
        "                    hidden_checkbox = gr.Checkbox(visible=False)\n",
        "                    button_stop_generation = gr.Button(\"Stop generation\")\n",
        "            with gr.Row():\n",
        "                output_audio = gr.Audio(label=\"Generated Audio\", type=\"filepath\")\n",
        "\n",
        "        with gr.Tab(\"Swap Voice\"):\n",
        "            with gr.Row():\n",
        "                 swap_audio_filename = gr.Audio(label=\"Input audio.wav to swap voice\", source=\"upload\", type=\"filepath\")\n",
        "            with gr.Row():\n",
        "                 with gr.Column():\n",
        "                     swap_tokenizer_lang = gr.Dropdown(tokenizer_language_list, label=\"Base Language Tokenizer\", value=tokenizer_language_list[1])\n",
        "                     swap_seed = gr.Number(label=\"Seed (default -1 = Random)\", precision=0, value=-1)\n",
        "                 with gr.Column():\n",
        "                     speaker_swap = gr.Dropdown(speakers_list, value=speakers_list[0], label=\"Voice\")\n",
        "                     swap_batchcount = gr.Number(label=\"Batch count\", precision=0, value=1)\n",
        "            with gr.Row():\n",
        "                swap_voice_button = gr.Button(\"Swap Voice\")\n",
        "            with gr.Row():\n",
        "                output_swap = gr.Audio(label=\"Generated Audio\", type=\"filepath\")\n",
        "\n",
        "   \n",
        "        quick_gen_checkbox.change(fn=on_quick_gen_changed, inputs=quick_gen_checkbox, outputs=complete_settings)\n",
        "        convert_to_ssml_button.click(convert_text_to_ssml, inputs=[input_text, speaker],outputs=input_text)\n",
        "        gen_click = tts_create_button.click(generate_text_to_speech, inputs=[input_text, speaker, text_temp, waveform_temp, eos_prob, quick_gen_checkbox, complete_settings, seedcomponent, batchcount],outputs=output_audio)\n",
        "        button_stop_generation.click(fn=None, inputs=None, outputs=None, cancels=[gen_click])\n",
        "        \n",
        "\n",
        "\n",
        "        swap_voice_button.click(swap_voice_from_audio, inputs=[swap_audio_filename, speaker_swap, swap_tokenizer_lang, swap_seed, swap_batchcount], outputs=output_swap)\n",
        "        clone_voice_button.click(clone_voice, inputs=[input_audio_filename, output_voice], outputs=[dummy, npz_file])\n",
        "\n",
        "\n",
        "        restart_server = False\n",
        "        try:\n",
        "            barkgui.queue().launch(show_error=True)\n",
        "        except:\n",
        "            restart_server = True\n",
        "            run_server = False\n",
        "        try:\n",
        "            while restart_server == False:\n",
        "                time.sleep(1.0)\n",
        "        except (KeyboardInterrupt, OSError):\n",
        "            print(\"Keyboard interruption in main thread... closing server.\")\n",
        "            run_server = False\n",
        "        barkgui.close()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 981,
          "referenced_widgets": [
            "425505387f374468870cc4bcb52ea6c5",
            "9b039beb3d7c4bc59ab95bd5d8a7dfcc",
            "55bf104e557340e5a88962134a765f1b",
            "f0768ce2c3484c4583810f461a0b742e",
            "ff7dff340d9f41c29313ca68034be359",
            "77a54e634f0d44c080eb769a4d2921b0",
            "5584c9aaa4e04734bb6833cf7cf76534",
            "7a2e70b96a054cdd89f73edd2474e20c",
            "1120230111694b4d8e63d476b0a35454",
            "643343218af349aaa63afbcd3cbc8009",
            "dfb0df17546545a4b74ed7f5f10c7a9a"
          ]
        },
        "id": "jDsXfOlEnTO-",
        "outputId": "debf279f-7788-411f-ee2b-4a0522e20122"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "smallmodels=False\n",
            "enablemps=False\n",
            "offloadcpu=False\n",
            "forcecpu=False\n",
            "autolaunch=False\n",
            "\n",
            "\n",
            "Preloading Models\n",
            "\n",
            "Launching Bark Voice Cloning UI Server\n",
            "Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
            "\n",
            "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
            "Running on public URL: https://5fbed86c1148a1f8e5.gradio.live\n",
            "\n",
            "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ],
            "text/html": [
              "<div><iframe src=\"https://5fbed86c1148a1f8e5.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
            ]
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Downloading HuBERT base model from https://dl.fbaipublicfiles.com/hubert/hubert_base_ls960.pt\n",
            "Downloaded HuBERT\n",
            "en_tokenizer.pth not found. Downloading HuBERT custom tokenizer\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Downloading (…)rt_base_ls960_14.pth:   0%|          | 0.00/104M [00:00<?, ?B/s]"
            ],
            "application/vnd.jupyter.widget-view+json": {
              "version_major": 2,
              "version_minor": 0,
              "model_id": "425505387f374468870cc4bcb52ea6c5"
            }
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Downloaded tokenizer\n",
            "Loading Hubert ./models/hubert/hubert.pt\n",
            "\n",
            "Generating Text (1/1) -> file (Seed 529525761):`Authors are required to disclose financial or non-financial interests that are directly or indirectly related to`\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "Mt5lkF1gnX54"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}