UNPKG

@jackdbd/eleventy-plugin-text-to-speech

Version:
40 lines 1.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.listVoices = exports.synthesizeSpeech = void 0; const debug_1 = __importDefault(require("debug")); const constants_js_1 = require("./constants.js"); const debug = (0, debug_1.default)(`${constants_js_1.DEBUG_PREFIX}/text-to-speech`); const synthesizeSpeech = async ({ audioEncoding, client, text, voice }) => { const request = { audioConfig: { audioEncoding }, input: { text }, voice }; // the Cloud Text-to-Speech API has a limit of 5000 characters debug(`try converting text => ${audioEncoding} using this voice: %O`, voice); try { const [response] = await client.synthesizeSpeech(request); if (response.audioContent) { return { value: response.audioContent }; } else { return { error: new Error(`the call to the Cloud Text-to-Speech API was succesfull but there is no audio content`) }; } } catch (err) { return { error: new Error(err.message) }; } }; exports.synthesizeSpeech = synthesizeSpeech; // https://cloud.google.com/text-to-speech/docs/voices const listVoices = async ({ client, languageCode }) => { const [result] = await client.listVoices({ languageCode }); return result.voices; }; exports.listVoices = listVoices; //# sourceMappingURL=text-to-speech.js.map