@fonos/tts
Advanced tools
Comparing version 0.0.87 to 0.0.88
@@ -7,32 +7,32 @@ /** | ||
export default abstract class AbstractTTS { | ||
name: string; | ||
/** | ||
* Constructs a new AbstractTTS object. | ||
* | ||
* @param {string} name friendly name for the TTS engine | ||
* @see module:tts:MaryTTS | ||
*/ | ||
constructor(name: string); | ||
/** | ||
* Converts a text to audio. | ||
* | ||
* @param {string} text - Text to convert to a audio sound | ||
* @param {Object} options - An object pass to the final implementation with | ||
* settings for the TTS engine | ||
* @returns {string} The path to the synthesized audio | ||
*/ | ||
synthesizeSync(text: string, options: any): string; | ||
/** | ||
* Converts a text to audio. | ||
* | ||
* @param {string} text - Text to convert to a audio sound | ||
* @param {Object} options - An object pass to the final implementation with | ||
* settings for the TTS engine | ||
* @returns {string} The path to the synthesized audio | ||
*/ | ||
abstract synthesize(text: string, options?: any): Promise<string>; | ||
/** | ||
* Gets the name of the TTS engine | ||
*/ | ||
getName(): string; | ||
name: string; | ||
/** | ||
* Constructs a new AbstractTTS object. | ||
* | ||
* @param {string} name friendly name for the TTS engine | ||
* @see module:tts:MaryTTS | ||
*/ | ||
constructor(name: string); | ||
/** | ||
* Converts a text to audio. | ||
* | ||
* @param {string} text - Text to convert to a audio sound | ||
* @param {Object} options - An object pass to the final implementation with | ||
* settings for the TTS engine | ||
* @returns {string} The path to the synthesized audio | ||
*/ | ||
synthesizeSync(text: string, options: any): string; | ||
/** | ||
* Converts a text to audio. | ||
* | ||
* @param {string} text - Text to convert to a audio sound | ||
* @param {Object} options - An object pass to the final implementation with | ||
* settings for the TTS engine | ||
* @returns {string} The path to the synthesized audio | ||
*/ | ||
abstract synthesize(text: string, options?: any): Promise<string>; | ||
/** | ||
* Gets the name of the TTS engine | ||
*/ | ||
getName(): string; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", {value: true}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -9,37 +9,39 @@ * @classdesc A building block for new TTS engines. You might use this class | ||
class AbstractTTS { | ||
/** | ||
* Constructs a new AbstractTTS object. | ||
* | ||
* @param {string} name friendly name for the TTS engine | ||
* @see module:tts:MaryTTS | ||
*/ | ||
constructor(name) { | ||
this.name = name; | ||
} | ||
/** | ||
* Converts a text to audio. | ||
* | ||
* @param {string} text - Text to convert to a audio sound | ||
* @param {Object} options - An object pass to the final implementation with | ||
* settings for the TTS engine | ||
* @returns {string} The path to the synthesized audio | ||
*/ | ||
synthesizeSync(text, options) { | ||
const sleep = require("sync").sleep; | ||
let result; | ||
let error; | ||
this.synthesize(text, options) | ||
.then((r) => (result = r)) | ||
.catch((e) => (error = e)); | ||
while (result === undefined && error === undefined) sleep(100); | ||
if (error) throw error; | ||
return result; | ||
} | ||
/** | ||
* Gets the name of the TTS engine | ||
*/ | ||
getName() { | ||
return this.name; | ||
} | ||
/** | ||
* Constructs a new AbstractTTS object. | ||
* | ||
* @param {string} name friendly name for the TTS engine | ||
* @see module:tts:MaryTTS | ||
*/ | ||
constructor(name) { | ||
this.name = name; | ||
} | ||
/** | ||
* Converts a text to audio. | ||
* | ||
* @param {string} text - Text to convert to a audio sound | ||
* @param {Object} options - An object pass to the final implementation with | ||
* settings for the TTS engine | ||
* @returns {string} The path to the synthesized audio | ||
*/ | ||
synthesizeSync(text, options) { | ||
const sleep = require("sync").sleep; | ||
let result; | ||
let error; | ||
this.synthesize(text, options) | ||
.then((r) => (result = r)) | ||
.catch((e) => (error = e)); | ||
while (result === undefined && error === undefined) | ||
sleep(100); | ||
if (error) | ||
throw error; | ||
return result; | ||
} | ||
/** | ||
* Gets the name of the TTS engine | ||
*/ | ||
getName() { | ||
return this.name; | ||
} | ||
} | ||
exports.default = AbstractTTS; |
import AbstractTTS from "./abstract_tts"; | ||
export * from "./utils"; | ||
export {AbstractTTS}; | ||
export { AbstractTTS }; |
"use strict"; | ||
var __createBinding = | ||
(this && this.__createBinding) || | ||
(Object.create | ||
? function (o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { | ||
enumerable: true, | ||
get: function () { | ||
return m[k]; | ||
} | ||
}); | ||
} | ||
: function (o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
}); | ||
var __exportStar = | ||
(this && this.__exportStar) || | ||
function (m, exports) { | ||
for (var p in m) | ||
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) | ||
__createBinding(exports, m, p); | ||
}; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : {default: mod}; | ||
}; | ||
Object.defineProperty(exports, "__esModule", {value: true}); | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AbstractTTS = void 0; | ||
@@ -32,0 +17,0 @@ const abstract_tts_1 = __importDefault(require("./abstract_tts")); |
@@ -10,7 +10,3 @@ /** | ||
*/ | ||
declare const computeFilename: ( | ||
text: string, | ||
options?: any, | ||
format?: string | ||
) => string; | ||
declare const computeFilename: (text: string, options?: any, format?: string) => string; | ||
/** | ||
@@ -41,2 +37,2 @@ * Takes a json object and creates a query formatted string | ||
declare const transcodeSync: (fileIn: string, fileOut: string) => string; | ||
export {computeFilename, transcode, transcodeSync, optionsToQueryString}; | ||
export { computeFilename, transcode, transcodeSync, optionsToQueryString }; |
"use strict"; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : {default: mod}; | ||
}; | ||
Object.defineProperty(exports, "__esModule", {value: true}); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.optionsToQueryString = exports.transcodeSync = exports.transcode = exports.computeFilename = void 0; | ||
@@ -20,16 +18,12 @@ const crypto_1 = __importDefault(require("crypto")); | ||
const computeFilename = (text, options = {}, format = "wav") => { | ||
const flat = require("flat"); | ||
let c = text; | ||
if (options.cachingFields) { | ||
const flatObj = flat(options); | ||
c = options.cachingFields | ||
.map((opt) => flatObj[opt]) | ||
.sort() | ||
.join(); | ||
} | ||
return ( | ||
crypto_1.default.createHash("md5").update(`${text},${c}`).digest("hex") + | ||
"." + | ||
format | ||
); | ||
const flat = require("flat"); | ||
let c = text; | ||
if (options.cachingFields) { | ||
const flatObj = flat(options); | ||
c = options.cachingFields | ||
.map((opt) => flatObj[opt]) | ||
.sort() | ||
.join(); | ||
} | ||
return (crypto_1.default.createHash("md5").update(`${text},${c}`).digest("hex") + "." + format); | ||
}; | ||
@@ -43,4 +37,3 @@ exports.computeFilename = computeFilename; | ||
*/ | ||
const optionsToQueryString = (obj) => | ||
Object.keys(obj) | ||
const optionsToQueryString = (obj) => Object.keys(obj) | ||
.map((key) => `${key}=${obj[key].toString()}`) | ||
@@ -57,9 +50,6 @@ .join("&"); | ||
*/ | ||
const transcode = (fileIn, fileOut) => | ||
new Promise((resolve, reject) => { | ||
const transcode = (fileIn, fileOut) => new Promise((resolve, reject) => { | ||
// We need a new instance to avoid collisions | ||
const sox = require("sox-audio")(); | ||
sox.on("error", (err, stdout, stderr) => | ||
reject(`Cannot process audio: ${err.message}`) | ||
); | ||
sox.on("error", (err, stdout, stderr) => reject(`Cannot process audio: ${err.message}`)); | ||
sox.input(fileIn); | ||
@@ -70,3 +60,3 @@ // TODO: Investigate other formats that can produce a better audio quality | ||
sox.on("end", () => resolve(fileOut)); | ||
}); | ||
}); | ||
exports.transcode = transcode; | ||
@@ -82,12 +72,14 @@ /** | ||
const transcodeSync = (fileIn, fileOut) => { | ||
const sleep = require("sync").sleep; | ||
let result; | ||
let error; | ||
transcode(fileIn, fileOut) | ||
.then((r) => (result = r)) | ||
.catch((e) => (error = e)); | ||
while (result === undefined && error === undefined) sleep(100); | ||
if (error) throw error; | ||
return result; | ||
const sleep = require("sync").sleep; | ||
let result; | ||
let error; | ||
transcode(fileIn, fileOut) | ||
.then((r) => (result = r)) | ||
.catch((e) => (error = e)); | ||
while (result === undefined && error === undefined) | ||
sleep(100); | ||
if (error) | ||
throw error; | ||
return result; | ||
}; | ||
exports.transcodeSync = transcodeSync; |
{ | ||
"name": "@fonos/tts", | ||
"version": "0.0.87", | ||
"version": "0.0.88", | ||
"description": "Fonos TTS module", | ||
@@ -32,3 +32,7 @@ "author": "Pedro Sanders <psanders@fonoster.com>", | ||
"dependencies": { | ||
"chai": "^4.3.4", | ||
"chai-as-promised": "^7.1.1", | ||
"flat": "^5.0.2", | ||
"sinon": "^10.0.0", | ||
"sinon-chai": "^3.6.0", | ||
"sox-audio": "^0.3.0", | ||
@@ -39,6 +43,5 @@ "sync": "^0.2.5" | ||
"dotenv": "^8.2.0", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.1.5" | ||
"rimraf": "^3.0.2" | ||
}, | ||
"gitHead": "f432bd97cab50bfebfe2be9847cc5e2ff890c750" | ||
"gitHead": "cb5c86eae9d3982c4ec62d0faa33c085eb9141e8" | ||
} |
10379
2
7
221
+ Addedchai@^4.3.4
+ Addedchai-as-promised@^7.1.1
+ Addedsinon@^10.0.0
+ Addedsinon-chai@^3.6.0
+ Added@sinonjs/commons@1.8.63.0.1(transitive)
+ Added@sinonjs/fake-timers@11.3.17.1.2(transitive)
+ Added@sinonjs/samsam@6.1.3(transitive)
+ Added@sinonjs/text-encoding@0.7.3(transitive)
+ Addedassertion-error@1.1.0(transitive)
+ Addedchai@4.5.0(transitive)
+ Addedchai-as-promised@7.1.2(transitive)
+ Addedcheck-error@1.0.3(transitive)
+ Addeddeep-eql@4.1.4(transitive)
+ Addeddiff@4.0.2(transitive)
+ Addedget-func-name@2.0.2(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedjust-extend@6.2.0(transitive)
+ Addedlodash.get@4.4.2(transitive)
+ Addedloupe@2.3.7(transitive)
+ Addednise@5.1.9(transitive)
+ Addedpath-to-regexp@6.3.0(transitive)
+ Addedpathval@1.1.1(transitive)
+ Addedsinon@10.0.1(transitive)
+ Addedsinon-chai@3.7.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtype-detect@4.0.84.1.0(transitive)