-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparser.html
177 lines (169 loc) · 6.09 KB
/
parser.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
<!doctype html>
<html>
<head>
<title>
AWS Transcript JSON to Blog Format
</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.inlineEdit.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<style>
textarea{
width:100%;
height:100%;
}
</style>
</head>
<body>
<div class="container">
<div id="AWSTranscribeJobname">JobName:</div>
<div id="AWSTranscribejobStatus">Job Status:</div>
<div id="AWSTranscribeaccountId">Account ID:</div>
<div id="AWSTranscribenumberOfSpeakers">Number of Speakers:</div>
<div id="AWSTranscribenumberOfSpeakersNames">Name of Speakers:</div>
<div id="AWSTranscriberesults">Raw Results:</div>
<div id="AWSTranscribeSpeakers">Raw Speakers:</div>
<div id="content">
<div id="AWSTranscribeTextItems">Raw Text Items:</div>
</div>
</div>
<BR>
</body>
<script>
/*Set speaker names */
var speakerNames = {};
speakerNames['spk_0'] = "Speaker #1";
speakerNames['spk_1'] = "Speaker #2";
<!-- Example from http://api.jquery.com/jQuery.getJSON/--->
$.getJSON( "ajax/asrOutput.json", function( data ) {
var items = [];
$.each( data, function( key, val ) {
items.push( "<li id='" + key + "'>" + val + "</li>" );
switch(key)
{
case "jobName":
$( "<span>"+val+"</span>" ).appendTo( "#AWSTranscribeJobname");
break;
case "accountId":
$( "<span>"+val+"</span>" ).appendTo( "#AWSTranscribeaccountId");
break;
case "status":
$( "<span>"+val+"</span>" ).appendTo( "#AWSTranscribejobStatus");
break;
case "results":
/*$( "<span>"+val+"</span>" ).appendTo( "#AWSTranscriberesults");*/
/*This is going to be everything else. Like text, speaker stuff, etc*/
/*For starters, there is a transcriptsobject. shown below
["transcripts":[{"transcript":"lots and lots of text"}]]
*/
$( "<span>"+JSON.stringify(val.transcripts[0].transcript)+"</span>" ).appendTo( "#AWSTranscriberesults");
/* Speaker Information*/
/***********************/
$( "<span>"+JSON.stringify(val.speaker_labels.speakers)+"</span>" ).appendTo( "#AWSTranscribenumberOfSpeakers");
/*Loop through the speakers.segments array*/
var speakers = [];
var current_speaker ="";
$.each( val.speaker_labels.segments, function( keySpeaker, valSpeaker ) {
if(valSpeaker.speaker_label != current_speaker)
{
speakers.push(JSON.stringify(valSpeaker.speaker_label) + " " + JSON.stringify(valSpeaker.start_time) + " " + JSON.stringify(valSpeaker.end_time));
/*START: Pull all words/items until next speaker */
/* Items Information*/
/*Loop through the items array*/
var textItems = [];
var textString ="";
textString += "<p> Speaker Change @ "+parseFloat(valSpeaker.start_time)+"s: " + speakerNames[valSpeaker.speaker_label] + "</p>";
/*start off with p tag*/
textString += "<p>";
var textfound = 0;
$.each( val.items, function( keyItems, valItems ) {
if(parseFloat(valSpeaker.start_time)<=parseFloat(valItems.start_time) && parseFloat(valItems.end_time)<=parseFloat(valSpeaker.end_time))
{
textfound++;
/*textItems.push(JSON.stringify(valItems.alternatives[0].content) + " " + JSON.stringify(valItems.start_time) + " " + JSON.stringify(valItems.end_time));*/
/*word boundary*/
var wordBoundary ="";
switch(valItems.type)
{
case "pronunciation":
wordBoundary = " ";
break;
case "punctuation":
wordBoundary = "";
break;
default:
wordBoundary = "";
}
/*Fixing some simple errors
Reasoning: Seems like the i noun is not capitalized in the result from trascribe*/
switch(valItems.alternatives[0].content)
{
case "i":
valItems.alternatives[0].content = "I";
break;
case "i'm":
valItems.alternatives[0].content = "I'm";
break;
case "i'd":
valItems.alternatives[0].content = "I'd";
break;
case "i've":
valItems.alternatives[0].content = "I've";
break;
default:
}
/* Push to two vars. One being array other being formatted text*/
textItems.push(JSON.stringify(valItems.alternatives[0].content) + wordBoundary);
textString += wordBoundary + JSON.stringify(valItems.alternatives[0].content).replace(/\"/g, "") ;
}
})
/*end with p tag */
textString += "</p>";
if(textfound != 0)
{
$( "<span class=\"editable\">"+textString+"</span>" ).appendTo( "#AWSTranscribeTextItems");
}
/*END : Pull all words/items until next speaker */
}
})
$( "<span>"+speakers+"</span>" ).appendTo( "#AWSTranscribeSpeakers");
break;
default:
/*Not sure what to do here */
break;
}
});
$( "<ul/>", {
"class": "my-new-list",
html: items.join( "" )
}).appendTo( "body" );
});
</script>
<script type="text/javascript">
$(function() {
$('.editable').inlineEdit({
control: 'textarea',
});
});
</script>
<button onclick="copyToClipboard('AWSTranscribeTextItems'); alert('COPIED')">Copy AWSTranscribeTextItems</button>
<!--- see solution from Alvaro Montoro on https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery --->
<script>
function copyToClipboard(elementId) {
// Create a "hidden" input
var aux = document.createElement("input");
//TODO: Find and replace any of the spans used for the inline formatter
var tmpText = document.getElementById(elementId).innerHTML
// Assign it the value of the specified element
aux.setAttribute("value", tmpText);
// Append it to the body
document.body.appendChild(aux);
// Highlight its content
aux.select();
// Copy the highlighted text
document.execCommand("copy");
// Remove it from the body
document.body.removeChild(aux);
}
</script>
</html>