@bbc/stt-align-node
Advanced tools
Comparing version 1.4.1 to 1.4.3
@@ -75,3 +75,3 @@ "use strict"; | ||
function interpolate(wordsList) { | ||
function interpolate(wordsList, start, end) { | ||
var words = interpolationOptimization(wordsList); | ||
@@ -91,2 +91,7 @@ | ||
} | ||
} | ||
if (start && indiciesWithStart[0] !== 0) { | ||
indiciesWithStart = [0].concat(_toConsumableArray(indiciesWithStart)); | ||
startTimes = [start].concat(_toConsumableArray(startTimes)); | ||
} // interpolate times for end | ||
@@ -100,2 +105,7 @@ | ||
} | ||
} | ||
if (end && indiciesWithEnd[indiciesWithEnd.length - 1] !== indicies[indicies.length - 1]) { | ||
indiciesWithEnd.push(indicies[indicies.length - 1]); | ||
endTimes.push(end); | ||
} // http://borischumichev.github.io/everpolate/#linear | ||
@@ -120,3 +130,3 @@ | ||
function alignRefTextWithSTT(opCodes, sttWords, transcriptWords) { | ||
function alignRefTextWithSTT(opCodes, sttWords, transcriptWords, start, end) { | ||
// # create empty list to receive data | ||
@@ -147,5 +157,5 @@ // transcriptData = [{} for _ in range(len(transcriptWords))] | ||
return interpolate(transcriptData); | ||
return interpolate(transcriptData, start, end); | ||
} | ||
module.exports = alignRefTextWithSTT; |
55
index.js
"use strict"; | ||
var difflib = require('difflib'); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
var normaliseWord = require('./normalise-word/index.js'); | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
var countDiffs = require('./count-diffs/index.js'); | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
var getDiffsList = require('./diffs-list/index.js'); | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
var alignRefTextWithSTT = require('./align/index.js'); | ||
var difflib = require("difflib"); | ||
var calculateWordDuration = require('./calculate-word-duration/index.js'); | ||
var normaliseWord = require("./normalise-word/index.js"); | ||
var diffsListToHtml = require('./diffs-list-to-html/index.js').diffsListToHtml; | ||
var countDiffs = require("./count-diffs/index.js"); | ||
var getDiffsList = require("./diffs-list/index.js"); | ||
var alignRefTextWithSTT = require("./align/index.js"); | ||
var calculateWordDuration = require("./calculate-word-duration/index.js"); | ||
var diffsListToHtml = require("./diffs-list-to-html/index.js").diffsListToHtml; | ||
/** | ||
* | ||
* | ||
* @param {array} sttData - array of STT words | ||
@@ -40,3 +48,3 @@ * @param {array} transcriptWords - array of base text accurate words | ||
function removeNewLinesFromRefText(refText) { | ||
return refText.trim().replace(/\n\n/g, ' ').replace(/\n/g, ' '); | ||
return refText.trim().replace(/\n\n/g, " ").replace(/\n/g, " "); | ||
} | ||
@@ -46,7 +54,7 @@ | ||
var transcriptTextWithoutLineBreaks = removeNewLinesFromRefText(refText); | ||
var transcriptTextArray = transcriptTextWithoutLineBreaks.split(' '); | ||
var transcriptTextArray = transcriptTextWithoutLineBreaks.split(" "); | ||
return transcriptTextArray; | ||
} | ||
/** | ||
* | ||
* | ||
* @param {json} sttWords - stt transcript json | ||
@@ -91,12 +99,33 @@ * @param {array} sttWords.words | ||
function alignSTT(sttWords, transcriptText) { | ||
function alignSTT(sttWords, transcriptText, start, end) { | ||
var sttWordsList = sttWords.words; | ||
var opCodes = diff(sttWordsList, transcriptText); | ||
var transcriptWords = convertRefTextToList(transcriptText); | ||
var alignedResults = alignRefTextWithSTT(opCodes, sttWordsList, transcriptWords); | ||
var alignedResults = alignRefTextWithSTT(opCodes, sttWordsList, transcriptWords, start, end); | ||
return alignedResults; | ||
} | ||
function alignSTTwithPadding(sttWords, transcriptText, start, end, padLeft, padRight) { | ||
var PADLEFT = padLeft ? padLeft : "Nwxskfsxn HHLPdJNbX KRrdghXzJ"; | ||
var PADRIGHT = padRight ? padRight : "XxjzKsmwK pHcdxnFch LmLXFdCVr"; | ||
return alignSTT({ | ||
words: [].concat(_toConsumableArray(PADLEFT.split(" ").map(function (text) { | ||
return { | ||
start: start, | ||
end: start, | ||
text: text | ||
}; | ||
})), _toConsumableArray(sttWords.words), _toConsumableArray(PADRIGHT.split(" ").map(function (text) { | ||
return { | ||
start: end, | ||
end: end, | ||
text: text | ||
}; | ||
}))) | ||
}, "".concat(PADLEFT, " ").concat(transcriptText, " ").concat(PADRIGHT), start, end).slice(PADLEFT.split(" ").length, -PADRIGHT.split(" ").length); | ||
} | ||
module.exports = alignSTT; | ||
module.exports.alignSTT = alignSTT; | ||
module.exports.alignSTTwithPadding = alignSTTwithPadding; | ||
module.exports.diffsList = diffsList; | ||
@@ -103,0 +132,0 @@ module.exports.diffsCount = diffsCount; |
{ | ||
"name": "@bbc/stt-align-node", | ||
"version": "1.4.1", | ||
"version": "1.4.3", | ||
"description": "", | ||
"main": "index.js", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
@@ -10,19 +10,21 @@ "start": "node lib/index.js", | ||
"test:watch": "jest --watchAll", | ||
"example": "node lib/example-usage.js", | ||
"example": "node example-usage/example-usage-align-stt.js", | ||
"build": "babel src -d build", | ||
"build:lib": "webpack --config ./webpack.config.lib.js --mode production", | ||
"build:demo": "webpack --mode production", | ||
"publish:public": "npm run build && /bin/cp -rf package.json build/ && /bin/cp -rf README.md build/README.md && npm publish build --access public", | ||
"publish:dry:run": "npm publish --dry-run", | ||
"publish:dry:run": "npm run build && /bin/cp -rf package.json build/ && /bin/cp -rf README.md build/README.md && npm publish build --dry-run --access public", | ||
"deploy:ghpages": "npm run build:demo && gh-pages -d demo" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@babel/cli": "^7.2.0", | ||
"@babel/core": "^7.2.0", | ||
"@babel/node": "^7.2.0", | ||
"@babel/preset-env": "^7.5.5", | ||
"@babel/cli": "^7.7.7", | ||
"@babel/core": "^7.7.7", | ||
"@babel/node": "^7.7.7", | ||
"@babel/preset-env": "^7.7.7", | ||
"jest": "^25.0.0", | ||
"webpack": "^4.39.1", | ||
"webpack-cli": "^3.3.6" | ||
"gh-pages": "^2.2.0", | ||
"webpack": "^4.41.5", | ||
"webpack-cli": "^3.3.10" | ||
}, | ||
@@ -33,5 +35,4 @@ "dependencies": { | ||
"everpolate": "0.0.3", | ||
"gh-pages": "^2.0.1", | ||
"number-to-words": "^1.2.4" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4
1
34919
8
10
791
1
- Removedgh-pages@^2.0.1
- Removedarray-union@1.0.2(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedasync@2.6.4(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedemail-addresses@3.1.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfilename-reserved-regex@1.0.0(transitive)
- Removedfilenamify@1.2.1(transitive)
- Removedfilenamify-url@1.0.0(transitive)
- Removedfs-extra@8.1.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedgh-pages@2.2.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedglobby@6.1.0(transitive)
- Removedhumanize-url@1.0.1(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedjsonfile@4.0.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedminimatch@3.1.2(transitive)
- Removednormalize-url@1.9.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedquery-string@4.3.4(transitive)
- Removedsort-keys@1.1.2(transitive)
- Removedstrict-uri-encode@1.1.0(transitive)
- Removedstrip-outer@1.0.1(transitive)
- Removedstrip-url-auth@1.0.1(transitive)
- Removedtrim-repeated@1.0.0(transitive)
- Removeduniversalify@0.1.2(transitive)
- Removedwrappy@1.0.2(transitive)