-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
640 lines (460 loc) · 20.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<html><head><title>Nepali Text to Speech</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.jplayer.min.js"></script>
<script type="text/javascript" src="js/jplayer.playlist.min.js"></script>
<script>
/* ------------------------------------------------------------------------------------------------------------------------------------------- */ // array with names of files of pronounciations containing mp3 voice files
// global
var nepali = new Array();
function process_text(){
var str = document.form.entity.value; // collect the text (encoded HTML)
var str_length = str.length; // length of string
//alert(str_length); // debug mode
var eHu = new Array(); // eHu = encoded_HTML_unicode
var array_index = 0;
// we'll be checking each character to detect that if the string has proper encoded HTML
for(x=0; x < str_length; x++){
var seventh = x + 6; // counter for seventh character which is semicolon
// if the first two characters are &# and seventh character is a semicolon then the numbers between them contains value for encoded HTML
if( (str.substr(x,2) == "&#") && (str.substr(seventh,1) == ";") ){
var x_plus2 = x + 2;
var encoded_HTML = str.substr(x_plus2,4); // this variable encoded_HTML holds the HTML encoded (numeric only) value of Unicode
// assign the values into array
eHu [array_index] = encoded_HTML;
array_index++;
}
if(str.substr(x,1) == " ") {
// we are supposing that the converted string is in pure HTML encoded string
// this is either space or newline hence assign a space.mp3
eHu[array_index] = "_"; // underscore here represents space
array_index++
}
} /* --------- /for loop ------------- */
assign_voice(eHu); // assign_voice
// this function should be returing assign_voice(eHu);
//return assign_voice(eHu);
} /* ----- /process_text -------- */
/* -------------------------------------------------------------------------------------------------------------------------------------------
convert unicode into HTML encoded values
*/
function doh(d) {
return d;
}
function hoj(d,tags) {
/* HTML entity */
if (d == '<')
return '<';
if (d == '>')
return '>';
if (d == '&')
return '&';
if (d.charCodeAt(0) > 127)
return '&#' + doh(d.charCodeAt(0)) + ';';
return d;
}
function htmlEntity(tags) {
var aa = document.form.symb.value;
var bb = '';
for (i = 0; i < aa.length; i++)
bb += hoj(aa.charAt(i),tags);
document.form.entity.value = bb;
process_text(); // further process text to separate numeric values of encoded HTML
}
/*
/ convert unicode into HTML encoded values
------------------------------------------------------------------------------------------------------------------------------------------- */
// now the Array eHu contains all the encoded html of unicode
// we are ready to process
/* ----------------------------------------------------------------------------------------------------------------------------------------------------------
HTML encoded values processing for pronounciation
---------------------------------------------------------------------------------------------------------------------------------------------------------- */
function assign_voice(eHu){
clean_tray();
var eHu_length = eHu.length; // count elements in array eHu (encoded_HTML_unicode)
for(x = 0; x < eHu_length ; x++){
var encoded_HTML_unicode = eHu[x];
if(is_swar(encoded_HTML_unicode)){
// original
if(is_tray_empty()){
store_html_encode_of_nepali(encoded_HTML_unicode);
}else{
// tray is not empty hence
var tray = get_tray();
store_html_encode_of_nepali(tray);
//alert(tray);
store_html_encode_of_nepali(encoded_HTML_unicode);
clean_tray();
}
// original
/*
if(is_tray_empty()){
store_html_encode_of_nepali(encoded_HTML_unicode);
}else{
// tray is not empty hence
var tray = get_tray();
store_html_encode_of_nepali(tray);
store_html_encode_of_nepali(encoded_HTML_unicode);
clean_tray();
}
*/
/*
// copied
// is temproary tray empty
if(is_tray_empty()){
// yes Tray is empty hence keep is in tray
var keep_in_tray_value = encoded_HTML_unicode;
keep_in_tray(keep_in_tray_value);
}else{
// Tray is not empty hence
// 1 get values of tray in a variable
// 2 empty the tray
// 3 place the new value in tray (not tray's value but array)
// 4 process the value retrieved from tray to find proper pronounciation
var tray = get_tray();
store_html_encode_of_nepali(tray);
clean_tray();
var keep_in_tray_value = encoded_HTML_unicode;
keep_in_tray(keep_in_tray_value);
}
*/
}else if(is_wyanjan(encoded_HTML_unicode)){
// is temproary tray empty
if(is_tray_empty()){
// yes Tray is empty hence keep is in tray
var keep_in_tray_value = encoded_HTML_unicode;
keep_in_tray(keep_in_tray_value);
}else{
// Tray is not empty hence
// 1 get values of tray in a variable
// 2 empty the tray
// 3 place the new value in tray (not tray's value but array)
// 4 process the value retrieved from tray to find proper pronounciation
var tray = get_tray();
store_html_encode_of_nepali(tray);
clean_tray();
var keep_in_tray_value = encoded_HTML_unicode;
keep_in_tray(keep_in_tray_value);
}
}else if(is_helper(encoded_HTML_unicode)){
// yes it is helper stuff
// aakar, eekar, ookar, aikar, okar, aukar, sirbindhu, ha
if(is_tray_empty()){
// yes tray is empty
// helpers are not supposed to appear before wyanjan_warna hence trash it or add space
// trashing
// do nothing
// add space
// I'll do it later hai
alert(" helper ko palo ma kasari empty : bad html encoding");
}else{
// no tray is not empty hence keep it in tray
var tray = get_tray();
tray = tray + "," + encoded_HTML_unicode;
keep_in_tray(tray);
}
}else{
// add space for non recognized stuffs
}
} // ---- /for loop ----
// after the for loop ends
// tray still holds last encoded HTML hence get_tray assign it in array.
var tray = get_tray();
store_html_encode_of_nepali(tray);
nepali_bola();
}
/*
---------------------------this function is for debug mode only (for development environment)
remove this function on production environment
*/
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;
//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += " ";
if(typeof(arr) == 'object') { //Array/Hashes/Objects
for(var item in arr) {
var value = arr[item];
if(typeof(value) == 'object') { //If it is an array,
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += dump(value,level+1);
} else {
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}
/*
---------------/ this function is for debug mode only
*/
function nepali_bola(){
// array nepali has all values
// assign file name on those values of each element
// create playlist as document's inner javascript { $("#inner").html("<script> ... </scrip"+"t>")}
var nepaliplaylist = new Array(); // contains file_mp3 and title
var count_nepali = nepali.length;
// from the array variable "nepali" ,
// generate title and mp3 file for playlist
var title_mp3file = new Array(); // array containing title and mp3 file
for(x=0; x<count_nepali; x++){
var count_nepali_element = nepali[x].length; // count element only
// the array "nepali" has either
// one value in one element > which returns length of 4 characters (there are 4 characters in encoded HTML of unicode)
// or
// x values in x elements
if(count_nepali_element == 4){
// this is single element
// hence add it accordingly
var utf_8 = "&#" + nepali[x] + ";";
var file_mp3 = "sound/" + nepali[x] + ".mp3";
var title = utf_8;
}else{
file_mp3 = nepali[x].join("_");
file_mp3 = "sound/" + file_mp3 + ".mp3";
title = "&#" + nepali[x].join(";&#") + ";";
}
// the array title_mp3file contains title and mp3 file location for playlist
title_mp3file[x] = new Array(title,file_mp3);
} // --------/ for loop -------------
// generate playlist
var no_of_list = title_mp3file.length;
var play_list = "";
for(y=0; y<no_of_list; y++){
if(y==0){
// first on play list
play_list = play_list + '{ title:"' + title_mp3file[y][0] + '", mp3:"' + title_mp3file[y][1] + '"}';
}else{
// not first on list
play_list = play_list + ',{ title:"' + title_mp3file[y][0] + '", mp3:"' + title_mp3file[y][1] + '"}';
}
} // ---/ for loop ---
$("#inner").html("<script>myPlaylist.setPlaylist([" + play_list + "]);</scrip"+"t>")
// clean/reset array named nepali so that whenever HTML encoding is done, new set of pronounciation replaces values in old array
// the following line prevents to store the same data over again
nepali = new Array(); // destroy this array
}
/* actually sets the values of tray in array
it is assumed that the values in tray has proper formation, which is good to pronounce
*/
function store_html_encode_of_nepali(tray){
/*
*/
var nepali_count = nepali.length;
if(!nepali[nepali_count]){
// check if the tray has comma
if((tray.split(",").length - 1) == 0){
// no comma hence assign it
nepali[nepali_count] = tray;
}else if((tray.split(",").length - 1) >= 1){
// tray has comma hence split it onto array
nepali[nepali_count] = tray.split(',');
}
}
}
/* is_swar do the value represents swar varna */
function is_swar(value){
/* data of swar varnas */
var swar = new Array();
swar[0] = 2309; // a
swar[1] = 2310; // aa
swar[2] = 2311; // i
swar[3] = 2312; // ii
swar[4] = 2313; // u
swar[5] = 2314; // oo
swar[6] = 2319; // e
swar[7] = 2320; // ai
swar[8] = 2323; // o
swar[9] = 2324; // au
/*
Dangerous
swar[] = 2309,2306 // a*
swar[] = 2309,2307 // a:
*/
// compare the value with our swar varnas
if(in_array(value,swar,true)){
alert('swar warna');
exit;
return true; // the value represents swar_varna
}else{
return false; // not swar_varna
}
}
/* is_wyanjan do the value represents wyanjan warna */
function is_wyanjan(value){
/* data of wyanjan varna */
var wyanjan = new Array();
wyanjan[0] = 2325; // kapuri > ka
wyanjan[1] = 2326; // kharaayo > kha
wyanjan[2] = 2327; // gaigode > ga
wyanjan[3] = 2328; // ghar jasto > gha
wyanjan[4] = 2329; // naka thopli > nga
wyanjan[5] = 2330; // chari chhuchhe > cha
wyanjan[6] = 2331; // chhataa > chha
wyanjan[7] = 2332; // jaraayo > ja
wyanjan[8] = 2333; // jharana > jha
wyanjan[9] = 2334; // goru singe > ya
wyanjan[10] = 2335; // topi > ta
wyanjan[11] = 2336; //
wyanjan[12] = 2337; //
wyanjan[13] = 2338; //
wyanjan[14] = 2339; // tin dharke > ana
wyanjan[15] = 2340; // tara > ta
wyanjan[16] = 2341; //
wyanjan[17] = 2342; //
wyanjan[18] = 2343; //
wyanjan[19] = 2344; // naam > na
wyanjan[20] = 2346; // paati > pa
wyanjan[21] = 2347; //
wyanjan[22] = 2348; //
wyanjan[23] = 2349; //
wyanjan[24] = 2350; // mero > ma
wyanjan[25] = 2351; // yaatra > ya
wyanjan[26] = 2352; // raato > ra
wyanjan[27] = 2354; // lamkhutte > la
wyanjan[28] = 2357; // wakil > wa
wyanjan[29] = 2358; // moto > sa
wyanjan[30] = 2359; // pet chiryo > sa
wyanjan[31] = 2360; // patalo > sa
wyanjan[32] = 2361; // halo > ha
/*
Dangerous (kshya, tra, gya)
wyanjan[33] =2325,2381,2359; // kshyetri > kshya
wyanjan[34] =2340,2381,2352; // tra > tra
wyanjan[35] = 2332,2381,2334; // gyani > gya
*/
// compare the value with our wyanjan varnas
if(in_array(value,wyanjan)){
return true; // the value represents wyanjan_varna
}else{
return false; // not wyanjan_varna
}
}
/* is_helper do the value represents aakar, eekar, ..., ookaar, ..., ekaar, okaar, aukaar, ... */
function is_helper(value){
/* data of helpers */
var helper = new Array();
helper[0] = 2366; // aakar
helper[1] = 2367; // eekaar (rashwa)
helper[2] = 2368; // eekaar (dirga)
helper[3] = 2369; // ookaar (rashwa)
helper[4] = 2370; // ookaar (dirga)
helper[5] = 2375; // ekaar
helper[6] = 2376; // aikaar
helper[7] = 2379; // ookaar
helper[8] = 2380; // aukaar
/* ang, aha*/
helper[9] = 2306; // sirbindhu
helper[10] = 2307; // dui wota thopla (tala mathi)
// compare the value with our helpers
if(in_array(value,helper)){
return true; // the value represents helpers
}else{
return false; // not helpers
}
}
/* is tray empty */
function is_tray_empty(){
var tray = document.form.tray.value;
if(tray.length<=0){
return true;
}else{
return false;
}
}
/* get the values of tray*/
function get_tray(){
return document.form.tray.value;
}
/* keep the values in tray */
function keep_in_tray(values){
//alert(values);
document.form.tray.value = values;
}
/* empty tray */
function clean_tray(){
document.form.tray.value ="";
}
/* ----------------------------------------------------------------------------------------------------------------------------------------------------------
/ HTML encoded values processing for pronunciation
---------------------------------------------------------------------------------------------------------------------------------------------------------- */
function in_array (needle, haystack, argStrict) {
var key = '', strict = !! argStrict;
if (strict) {
for (key in haystack) {
if (haystack[key] === needle) { return true;
}
}
} else {
for (key in haystack) {
if (haystack[key] == needle) {
return true;
}
}
}
return false;
}
</script>
<style>
.jp-playlist{display:none;}
</style>
</head>
<body>
<table>
<tr><td valign="top">
<form method="post" name="form" action="">
<textarea name="symb" id="symb" rows="3" cols="70" style="height:500px;width:500px;"></textarea>
<!-- input name="convert" value="Convert" onclick="htmlEntity(1)" style="width:85px;padding-left:8px;" type="button" class="button" -->
<br>
<textarea name="entity" rows="3" cols="70" id="output" style="display:none;"></textarea>
<br />
<input type="text" name="tray" id="tray" style ="display:none;" />
<br />
<textarea name="temp" rows="3" cols="70" style="display:none;" ></textarea>
</form>
</td>
<td valign="top">
<img id="playlist-play" src="play.png" />
<div id="jpid"></div>
<div id="jp_container_N" class="jp-video jp-video-270p">
<div class="jp-type-playlist">
<div id="jquery_jplayer_N" class="jp-jplayer"></div>
<div class="jp-playlist">
<ul>
<!-- The method Playlist.displayPlaylist() uses this unordered list -->
<li></li>
</ul>
</div>
</div>
</div>
</td>
</tr>
</table>
<script>
var myPlaylist = new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_N",
cssSelectorAncestor: "#jp_container_N"
}, [
{
title:"Blank",
mp3:"sound/blank.mp3"
}
], {
playlistOptions: {
enableRemoveControls: true
},
swfPath: "js",
supplied: "mp3"
});
// The play commands
$("#playlist-play").click(function() {
myPlaylist.remove();
htmlEntity(1);
myPlaylist.play();
});
</script>
<div id="inner"></div>
</body>
</html>