UNPKG

9.92 kBJavaScriptView Raw
1module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var a=e[n]={i:n,l:!1,exports:{}};return t[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)r.d(n,a,function(e){return t[e]}.bind(null,a));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=39)}({12:function(t,e,r){"use strict";e.a=function(t,e){var r=0;return t.map(function(t){var n={start:t.start,end:t.end,confidence:t.confidence,text:t[e],offset:r,length:t[e].length,key:Math.random().toString(36).substring(6)};return r=r+t[e].length+1,n})}},39:function(t,e,r){"use strict";r.r(e);var n=r(12);var a=function(t,e){return function(t){var e=t[0].speaker,r=[],n={words:[],text:"",speaker:""};return t.forEach(function(t){e===t.speaker?(n.words.push(t),n.text+=t.punct+" ",n.speaker=e):(e=t.speaker,n.text=n.text.trim(),r.push(n),(n={words:[],text:"",speaker:"U_UKN"}).words.push(t),n.text+=t.punct+" ")}),r.push(n),r}(function(t,e){var r=[];return t.forEach(function(t){var n,a=function(t,e){var r=e.find(function(e){var r=e.start+e.duration;return t.start>=e.start&&t.end<=r});return void 0===r?{"@type":"Segment",speaker:{"@id":"UKN",gender:"U"}}:r}(t,e);t.speaker=(n=a.speaker).gender+"_"+n["@id"],r.push(t)}),r}(t,e.segments))},o=function(t){var e,r=[],o=null;return void 0===t.retval?(e=t.words,void 0!==t.segmentation&&(o=t.segmentation)):(e=t.retval.words,void 0!==t.retval.segmentation&&(o=t.retval.segmentation)),(null===o?function(t){var e=[],r={words:[],text:[]};return t.forEach(function(t){/[.?!]/.test(t.punct)?(r.words.push(t),r.text.push(t.punct),r.text=r.text.join(" "),e.push(r),r={words:[],text:[]}):(r.words.push(t),r.text.push(t.punct))}),e}(e):a(e,o)).forEach(function(t,e){if(void 0!==t.words[0]){var a="TBC ".concat(e);null!==o&&(a=t.speaker);var s={text:t.text,type:"paragraph",data:{speaker:a,words:t.words,start:t.words[0].start},entityRanges:Object(n.a)(t.words,"punct")};r.push(s)}}),r},s=function(t){var e=[];return function(t){var e=[],r={words:[],text:[]};return t.forEach(function(t){t.paragraph.forEach(function(t){t.line.forEach(function(t){var n={text:t.text,start:t.startTime,end:t.endTime};/[.?!]/.test(t.text)?(r.words.push(n),r.text.push(t.text),e.push(r),r={words:[],text:[]}):(r.words.push(n),r.text.push(t.text))})})}),e}(t.text).forEach(function(t,r){var a={text:t.text.join(" "),type:"paragraph",data:{speaker:"TBC ".concat(r),words:t.words,start:t.words[0].start},entityRanges:Object(n.a)(t.words,"text")};e.push(a)}),e},u=function(t,e){for(var r in e){var n=e[r];if(t>=n.start&t<n.end)return n.name}return"UNK"},c=function(t){var e,r,a,o,s=[];return r=t.words,a=[],r.forEach(function(t){/[.?!]/.test(t.name)?(a[a.length-1].name=a[a.length-1].name+t.name,a[a.length-1].duration=(parseFloat(a[a.length-1].duration)+parseFloat(t.duration)).toString()):a.push(t)}),e=(e=a).map(function(t,e){return{start:t.time,end:(parseFloat(t.time)+parseFloat(t.duration)).toString(),confidence:t.confidence,word:t.name.toLowerCase().replace(/[.?!]/g,""),punct:t.name,index:e}}),o=(o=t.speakers).map(function(t){return{start:t.time,end:(parseFloat(t.time)+parseFloat(t.duration)).toString(),name:t.name}}),function(t){var e=[],r={words:[],text:[]};return t.forEach(function(t){/[.?!]/.test(t.punct)?(r.words.push(t),r.text.push(t.punct),e.push(r),r={words:[],text:[]}):(r.words.push(t),r.text.push(t.punct))}),e}(e).forEach(function(t){var e=t.words[0].start,r={text:t.text.join(" "),type:"paragraph",data:{speaker:u(e,o),words:t.words,start:e},entityRanges:Object(n.a)(t.words,"punct")};s.push(r)}),s},i=function(t,e){var r=parseFloat(t.start_time),n=parseFloat(t.end_time),a=e.find(function(t){return r>=parseFloat(t.start_time)&&n<=parseFloat(t.end_time)});return void 0===a?"UKN":a.speaker_label.replace("spk_","")},p=function(t,e){return function(t){var e=[],r="";return t.forEach(function(t){t.speaker_label===r?e[e.length-1].words.push(t):(r=t.speaker_label,e.push({speaker:t.speaker_label,words:[t]}))}),e}(function(t,e){return t.map(function(t){return Object.assign(t,{speaker_label:i(t,e)})})}(t,e.segments))};function f(t){for(var e=1;e<arguments.length;e++){var r=null==arguments[e]?{}:arguments[e],n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(e){d(t,e,r[e])})}return t}function d(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var l=function(t){return/punctuation/.test(t.type)?Object.assign(t.alternatives[0],{confidence:1}):t.alternatives.reduce(function(t,e){return parseFloat(t.confidence)>parseFloat(e.confidence)?t:e})},h=function(t){var e=l(t);return{start:parseFloat(t.start_time),end:parseFloat(t.end_time),text:e.content,confidence:parseFloat(e.confidence)}},v=function(t){var e=[];return t.map(function(r,n){return"punctuation"===r.type?(e.push(n-1),function(t,e){var r=t.alternatives[0].content;return f({},e,{alternatives:e.alternatives.map(function(t){return f({},t,{content:t.content+(e=r,e.replace(/^\s/,""))});var e})})}(r,t[n-1])):r}).filter(function(t,r){return!e.includes(r)})},x=function(t){var e=[],r=t.results.items,a=t.results.speaker_labels,o=v(r);return(void 0!==a?function(t,e){return p(t,e).map(function(t){return{words:t.words.map(h),text:t.words.map(function(t){return l(t).content}),speaker:t.speaker}})}(o,a):function(t){var e=[],r={words:[],text:[]};return t.forEach(function(t){var n=l(t).content,a=h(t);/[.?!]/.test(n)?(r.words.push(a),r.text.push(n),e.push(r),r={words:[],text:[]}):(r.words.push(a),r.text.push(n))}),e}(o)).forEach(function(t,r){var a={text:t.text.join(" "),type:"paragraph",data:{speaker:t.speaker?"Speaker ".concat(t.speaker):"TBC ".concat(r),words:t.words,start:parseFloat(t.words[0].start)},entityRanges:Object(n.a)(t.words,"text")};e.push(a)}),e},w=function(t){var e,r,a,o,s=(a=t.results[0].results,o=[],a.forEach(function(t){o.push(t.alternatives[0].timestamps.map(function(t){return{text:t[0],start:t[1],end:t[2]}}))}),o);return function(t){var e=[];return t.forEach(function(t){var r={text:t.map(function(t){return t.text}).join(" "),type:"paragraph",data:{speaker:t[0].speaker,words:t,start:t[0].start},entityRanges:Object(n.a)(t,"text")};e.push(r)}),e}((e=s,r=t.results[0].speaker_labels,e.map(function(t){return t.map(function(t){return t.speaker=function(t,e){var r=e.find(function(e){var r=e.from,n=e.to;return t.start===r&&t.end===n});return void 0===r?"UKN":"S_".concat(r.speaker)}(t,r),t})})))},m=r(49),g=function(t){var e=[],r=null,a=t.words;return t.paragraphs&&(r=t.paragraphs),(r?Object(m.default)(a,t.paragraphs):function(t){var e=[],r={words:[],text:[]};return t.forEach(function(t){/[.?!]/.test(t.text)?(r.words.push(t),r.text.push(t.text),r.text=r.text.join(" "),e.push(r),r={words:[],text:[]}):(r.words.push(t),r.text.push(t.text))}),e}(a)).forEach(function(t,a){if(t.words[0]){var o="TBC ".concat(a);r&&(o=t.speaker);var s={text:t.text,type:"paragraph",data:{speaker:o,words:t.words,start:t.words[0].start},entityRanges:Object(n.a)(t.words,"text")};e.push(s)}}),e},k=function(t){return t.reduce(function(t,e){return t.concat(Array.isArray(e)?k(e):e)},[])},b=function(t){var e=t.map(function(t){return t.entityRanges}),r=k(e),n={};return r.forEach(function(t){n[t.key]={type:"WORD",mutability:"MUTABLE",data:t}}),n},y=function(t,e){var r=parseFloat(t);return void 0!==e&&(r+=parseFloat(e/1e9)),r},j=function(t){var e=[],r={words:[],text:[]};return t.forEach(function(t){var n,a=0===(n=t).alternatives.length?n[0]:n.alternatives.reduce(function(t,e){return parseFloat(t.confidence)>parseFloat(e.confidence)?t:e});r.text.push(a.transcript.trim()),a.words.forEach(function(t){var e,n;r.words.push((e=t,n=a.confidence,{start:y(e.startTime.seconds,e.startTime.nanos),end:y(e.endTime.seconds,e.endTime.nanos),text:e.word,confidence:n}))}),e.push(r),r={words:[],text:[]}}),e},O=function(t){var e=[];return j(t.results).forEach(function(t,r){var a={text:t.text.join(" "),type:"paragraph",data:{speaker:t.speaker?"Speaker ".concat(t.speaker):"TBC ".concat(r),words:t.words,start:parseFloat(t.words[0].start)},entityRanges:Object(n.a)(t.words,"text")};e.push(a)}),e};r.d(e,"createEntityMap",function(){return b});e.default=function(t,e){var r;switch(e){case"bbckaldi":return{blocks:r=o(t),entityMap:b(r)};case"autoedit2":return{blocks:r=s(t),entityMap:b(r)};case"speechmatics":return{blocks:r=c(t),entityMap:b(r)};case"ibm":return{blocks:r=w(t),entityMap:b(r)};case"draftjs":return t;case"amazontranscribe":return{blocks:r=x(t),entityMap:b(r)};case"digitalpaperedit":return{blocks:r=g(t),entityMap:b(r)};case"google-stt":return{blocks:r=O(t),entityMap:b(r)};default:console.error("Did not recognize the stt engine.")}}},49:function(t,e,r){"use strict";r.r(e),e.default=function(t,e){return function(t,e){var r=[],n="UKN",a=0,o=0,s={words:[],text:"",speaker:""};return t.forEach(function(t){(n=function(t,e){return e.find(function(e){if(t.start>=e.start&&t.end<=e.end)return e})}(t,e))&&((a=e.indexOf(n))===o?(s.words.push(t),s.text+=t.text+" ",s.speaker=n.speaker):(o=a,s.text.trim(),r.push(s),(s={words:[],text:"",speaker:""}).words.push(t),s.text+=t.text+" ",s.speaker=n.speaker))}),r.push(s),r}(t,e)}}});
2//# sourceMappingURL=sttJsonAdapter.js.map
\No newline at end of file