Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

speak-tts

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

speak-tts - npm Package Compare versions

Comparing version 2.0.6 to 2.0.7

93

lib/speak-tts.js

@@ -8,30 +8,4 @@ "use strict";

var _trim = _interopRequireDefault(require("lodash/trim"));
var _size = _interopRequireDefault(require("lodash/size"));
var _get = _interopRequireDefault(require("lodash/get"));
var _toPairs = _interopRequireDefault(require("lodash/toPairs"));
var _isNil = _interopRequireDefault(require("lodash/isNil"));
var _isObject = _interopRequireDefault(require("lodash/isObject"));
var _isString = _interopRequireDefault(require("lodash/isString"));
var _isFinite = _interopRequireDefault(require("lodash/isFinite"));
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -55,5 +29,6 @@

key: "init",
value: function init(conf) {
value: function init() {
var _this = this;
var conf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return new Promise(function (resolve, reject) {

@@ -64,14 +39,12 @@ if (!_this.browserSupport) {

var listeners = (0, _get.default)(conf, 'listeners', {});
var splitSentences = (0, _get.default)(conf, 'splitSentences', true);
var lang = (0, _get.default)(conf, 'lang');
var volume = (0, _get.default)(conf, 'volume', 1);
var rate = (0, _get.default)(conf, 'rate', 1);
var pitch = (0, _get.default)(conf, 'pitch', 1);
var voice = (0, _get.default)(conf, 'voice'); // Attach event listeners
var listeners = (0, _utils.isNil)(conf.listeners) ? {} : conf.listeners;
var splitSentences = (0, _utils.isNil)(conf.splitSentences) ? true : conf.splitSentences;
var lang = (0, _utils.isNil)(conf.lang) ? undefined : conf.lang;
var volume = (0, _utils.isNil)(conf.volume) ? 1 : conf.volume;
var rate = (0, _utils.isNil)(conf.rate) ? 1 : conf.rate;
var pitch = (0, _utils.isNil)(conf.pitch) ? 1 : conf.pitch;
var voice = (0, _utils.isNil)(conf.voice) ? undefined : conf.voice; // Attach event listeners
(0, _toPairs.default)(listeners).forEach(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
listener = _ref2[0],
fn = _ref2[1];
Object.keys(listeners).forEach(function (listener) {
var fn = listeners[listener];

@@ -91,8 +64,8 @@ var newListener = function newListener(data) {

!(0, _isNil.default)(lang) && _this.setLanguage(lang);
!(0, _isNil.default)(voice) && _this.setVoice(voice);
!(0, _isNil.default)(volume) && _this.setVolume(volume);
!(0, _isNil.default)(rate) && _this.setRate(rate);
!(0, _isNil.default)(pitch) && _this.setPitch(pitch);
!(0, _isNil.default)(splitSentences) && _this.setSplitSentences(splitSentences);
!(0, _utils.isNil)(lang) && _this.setLanguage(lang);
!(0, _utils.isNil)(voice) && _this.setVoice(voice);
!(0, _utils.isNil)(volume) && _this.setVolume(volume);
!(0, _utils.isNil)(rate) && _this.setRate(rate);
!(0, _utils.isNil)(pitch) && _this.setPitch(pitch);
!(0, _utils.isNil)(splitSentences) && _this.setSplitSentences(splitSentences);
resolve({

@@ -108,4 +81,4 @@ voices: voices,

});
}).catch(function () {
reject();
}).catch(function (e) {
reject(e);
});

@@ -121,3 +94,3 @@ });

if ((0, _size.default)(voices) > 0) {
if ((0, _utils.size)(voices) > 0) {
return resolve(voices);

@@ -152,3 +125,3 @@ } else {

if ((0, _isString.default)(voice)) {
if ((0, _utils.isString)(voice)) {
synthesisVoice = voices.find(function (v) {

@@ -160,3 +133,3 @@ return v.name === voice;

if ((0, _isObject.default)(voice)) {
if ((0, _utils.isObject)(voice)) {
synthesisVoice = voice;

@@ -187,3 +160,3 @@ }

if ((0, _isFinite.default)(volume) && volume >= 0 && volume <= 1) {
if (!(0, _utils.isNan)(volume) && volume >= 0 && volume <= 1) {
this.volume = volume;

@@ -199,3 +172,3 @@ } else {

if ((0, _isFinite.default)(rate) && rate >= 0 && rate <= 10) {
if (!(0, _utils.isNan)(rate) && rate >= 0 && rate <= 10) {
this.rate = rate;

@@ -210,4 +183,5 @@ } else {

pitch = parseFloat(pitch);
console.log("debug pitch", pitch);
if ((0, _isFinite.default)(pitch) && pitch >= 0 && pitch <= 2) {
if (!(0, _utils.isNan)(pitch) && pitch >= 0 && pitch <= 2) {
this.pitch = pitch;

@@ -234,4 +208,4 @@ } else {

queue = _data$queue === void 0 ? true : _data$queue;
var msg = (0, _trim.default)(text);
if ((0, _isNil.default)(msg)) resolve(); // Stop current speech
var msg = (0, _utils.trim)(text);
if ((0, _utils.isNil)(msg)) resolve(); // Stop current speech

@@ -243,3 +217,3 @@ !queue && _this3.cancel(); // Split into sentences (for better result and bug with some versions of chrome)

sentences.forEach(function (sentence, index) {
var isLast = index === (0, _size.default)(sentences) - 1;
var isLast = index === (0, _utils.size)(sentences) - 1;
var utterance = new SpeechSynthesisUtterance();

@@ -254,8 +228,7 @@ if (_this3.synthesisVoice) utterance.voice = _this3.synthesisVoice;

utterance.text = sentence; // Attach event listeners
utterance.text = sentence;
console.log("debug utterance", _this3.volume, utterance); // Attach event listeners
(0, _toPairs.default)(listeners).forEach(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
listener = _ref4[0],
fn = _ref4[1];
Object.keys(listeners).forEach(function (listener) {
var fn = listeners[listener];

@@ -262,0 +235,0 @@ var newListener = function newListener(data) {

@@ -6,15 +6,9 @@ "use strict";

});
exports.validateLocale = exports.splitSentences = void 0;
exports.trim = exports.isObject = exports.isNil = exports.isNan = exports.size = exports.isString = exports.validateLocale = exports.splitSentences = void 0;
var _trim = _interopRequireDefault(require("lodash/trim"));
var _compact = _interopRequireDefault(require("lodash/compact"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var splitSentences = function splitSentences() {
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
return (0, _compact.default)(text.replace(/\.+/g, '.|').replace(/\?/g, '?|').replace(/\!/g, '!|').split("|").map(function (sentence) {
return (0, _trim.default)(sentence);
}));
return text.replace(/\.+/g, '.|').replace(/\?/g, '?|').replace(/\!/g, '!|').split("|").map(function (sentence) {
return trim(sentence);
}).filter(Boolean);
};

@@ -35,2 +29,38 @@

exports.validateLocale = validateLocale;
exports.validateLocale = validateLocale;
var isString = function isString(value) {
return typeof value === 'string' || value instanceof String;
};
exports.isString = isString;
var size = function size(value) {
return value && Array.isArray(value) && value.length ? value.length : 0;
};
exports.size = size;
var isNan = function isNan(value) {
return typeof value === "number" && isNaN(value);
};
exports.isNan = isNan;
var isNil = function isNil(value) {
return value === null || value === undefined;
};
exports.isNil = isNil;
var isObject = function isObject(value) {
return Object.prototype.toString.call(value) === '[object Object]';
};
exports.isObject = isObject;
var trim = function trim(value) {
return isString(value) ? value.trim() : '';
};
exports.trim = trim;
{
"name": "speak-tts",
"version": "2.0.6",
"version": "2.0.7",
"description": "Browser TTS (using Web speech API) made easy",

@@ -34,6 +34,3 @@ "main": "lib/speak-tts.js",

"webpack-dev-server": "^3.1.9"
},
"dependencies": {
"lodash": "^4.17.11"
}
}

@@ -17,3 +17,3 @@ Speech synthesis made easy - Browser based text to speech (TTS)

- handling the fact that Chrome load voices in an asynchronous manner when others browsers don't
-> onvoicesloaded listener gets triggered in all browsers
-> onvoiceschanged listener gets triggered in all browsers
- handling some quirks and bugs of IOS/android devices and some chrome/firefox versions

@@ -44,3 +44,3 @@ - splitting sentences into several speeches to make it sound more natural, especially for older versions of Chrome (can be disabled)

const speech = new Speech() // will throw an exception if not browser supported
if(speech.browserSupport()) { // returns a boolean
if(speech.hasBrowserSupport()) { // returns a boolean
console.log("speech synthesis supported")

@@ -47,0 +47,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc