UNPKG

10.3 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=36)}({10: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}))}},36:function(t,e,r){"use strict";r.r(e),r.d(e,"createEntityMap",(function(){return y}));var n=r(10);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))})),0<r.words.length&&(r.text=r.text.join(" "),e.push(r)),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],a=parseFloat(t);if(a>=n.start&a<n.end)return n.name}return"UNK"},c=function(t){var e,r,a=[];return e=t.words,r=[],e.forEach((function(t){/[.?!]/.test(t.name)?(r[r.length-1].name=r[r.length-1].name+t.name,r[r.length-1].duration=(parseFloat(r[r.length-1].duration)+parseFloat(t.duration)).toString()):r.push(t)})),function(t,e,r){var n,a=[],o={words:[],text:[],speaker:""},s=u(t[0].start,e),c=!1;return t.forEach((function(t){((n=u(t.start,e))!==s||o.words.length>r&&c)&&(o.speaker=s,a.push(o),s=n,o={words:[],text:[]}),o.words.push(t),o.text.push(t.punct),c=!!/[.?!]/.test(t.punct)})),o.speaker=s,a.push(o),a}(r.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}})),t.speakers.map((function(t){return{start:parseFloat(t.time),end:parseFloat(t.time)+parseFloat(t.duration),name:t.name}})),150).forEach((function(t){var e=t.words[0].start,r={text:t.text.join(" "),type:"paragraph",data:{speaker:t.speaker,words:t.words,start:e},entityRanges:Object(n.a)(t.words,"punct")};a.push(r)})),a},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,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function d(t){for(var e,r=1;r<arguments.length;r++)e=null==arguments[r]?{}:arguments[r],r%2?f(e,!0).forEach((function(r){l(t,r,e[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):f(e).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}));return t}function l(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var h=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}))},v=function(t){var e=h(t);return{start:parseFloat(t.start_time),end:parseFloat(t.end_time),text:e.content,confidence:parseFloat(e.confidence)}},x=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 d({},e,{alternatives:e.alternatives.map((function(t){return d({},t,{content:t.content+(e=r,e.replace(/^\s/,""))});var e}))})}(r,t[n-1])):r})).filter((function(t,r){return!e.includes(r)}))},w=function(t){var e=[],r=t.results.items,a=t.results.speaker_labels,o=x(r);return(void 0!==a?function(t,e){return p(t,e).map((function(t){return{words:t.words.map(v),text:t.words.map((function(t){return h(t).content})),speaker:t.speaker}}))}(o,a):function(t){var e=[],r={words:[],text:[]};return t.forEach((function(t){var n=h(t).content,a=v(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},m=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}))}))))},g=r(48),k=function(t){var e=t.words,r=t.paragraphs;return(r?Object(g.default)(e,r):function(t){var e=[],r={words:[],text:[]};return t.forEach((function(t){r.words.push(t),r.text.push(t.text),/[.?!]/.test(t.text)&&(r.text=r.text.join(" "),e.push(r),r={words:[],text:[]})})),e}(e)).map((function(t,e){return t.speaker||(t.speaker="TBC ".concat(e)),function(t){var e=t.words;return{text:t.text,type:"paragraph",data:{speaker:t.speaker,words:e,start:0<e.length?e[0].start:0},entityRanges:Object(n.a)(e,"text")}}(t)}))},b=function(t){return t.reduce((function(t,e){return t.concat(Array.isArray(e)?b(e):e)}),[])},y=function(t){var e=t.map((function(t){return t.entityRanges})),r=b(e),n={};return r.forEach((function(t){n[t.key]={type:"WORD",mutability:"MUTABLE",data:t}})),n},j=function(t,e){var r=parseFloat(t);return void 0!==e&&(r+=parseFloat(e/1e9)),r},O=function(t){var e=[],r={words:[],text:[]};return t.forEach((function(t){var n=function(t){return 0===t.alternatives.length?t[0]:t.alternatives.reduce((function(t,e){return parseFloat(t.confidence)>parseFloat(e.confidence)?t:e}))}(t);r.text.push(n.transcript.trim()),n.words.forEach((function(t){var e,a;r.words.push((e=t,a=n.confidence,{start:j(e.startTime.seconds,e.startTime.nanos),end:j(e.endTime.seconds,e.endTime.nanos),text:e.word,confidence:a}))})),e.push(r),r={words:[],text:[]}})),e},E=function(t){var e=[];return O(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};e.default=function(t,e){var r;switch(e){case"bbckaldi":return{blocks:r=o(t),entityMap:y(r)};case"autoedit2":return{blocks:r=s(t),entityMap:y(r)};case"speechmatics":return{blocks:r=c(t),entityMap:y(r)};case"ibm":return{blocks:r=m(t),entityMap:y(r)};case"draftjs":return t;case"amazontranscribe":return{blocks:r=w(t),entityMap:y(r)};case"digitalpaperedit":return{blocks:r=k(t),entityMap:y(r)};case"google-stt":return{blocks:r=E(t),entityMap:y(r)};default:console.error("Did not recognize the stt engine.")}}},48: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