Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
eleventy-plugin-text-to-speech
Advanced tools
Generate audio versions of your Eleventy content using Azure text to speech
This is a plugin for Eleventy that generates audio versions of your page content using Microsoft's Cognitive Services Speech API.
This plugin is based on the example project here: https://11ty-text-to-mp3.netlify.app/
.env
file with the following variables:AZURE_SPEECH_RESOURCE_KEY=<API KEY FOR YOUR AZURE SPEECH SERVICE>
AZURE_SPEECH_REGION=<SHORT NAME FOR THE RESOURCE REGION>
npm install eleventy-plugin-text-to-speech
OR
yarn add eleventy-plugin-text-to-speech
.eleventy.js
file:const { TextToSpeechPlugin } = require("eleventy-plugin-text-to-speech");
// inside your eleventyConfig function
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(TextToSpeechPlugin, {
textToSpeech: {
voiceName: "en-US-JennyNeural", // see below for voice options
},
});
};
mp3-version.11ty.js
(you can name this whatever you want) to your input directory with this code:const { AudioVersionTemplate } = require("eleventy-plugin-text-to-speech");
// see below for options to extend the default template class
module.exports = AudioVersionTemplate;
On the pages that you want to generate a MP3 from, add mp3Url
to the frontmatter, pointing to the desired permalink of the generated MP3 file, eg. /mp3/blog-post-1.mp3
. See below for more configuration options.
Run your Eleventy build and it will generate audio versions of your content. Then, you can refer to the mp3Url
in your templates to point to the generated MP3 file.
If you're using Netlify to host your Eleventy site, it's a great idea to use the netlify-plugin-cache
package to cache the generated audio between Netlify builds. This will help you save on your Azure API free tier quota, and will keep your builds fast.
To cache between Netlify builds:
npm install netlify-plugin-cache
netlify.toml
to your base directory with:[[plugins]]
package = "netlify-plugin-cache"
[plugins.inputs]
paths = [ ".cache" ]
Below are the default options when adding the plugin to your .eleventy.js
file:
eleventyConfig.addPlugin(TextToSpeechPlugin, {
// data key that the plugin uses to create a custom collection, and creates MP3 files for each page
// when it creates the MP3 file, the value for this key becomes the permalink
// for example, a page with mp3Url: /mp3/page1.mp3 would generate an MP3 file at that path.
mp3UrlDataKey: `mp3Url`,
// voice name to use for text to speech. see below to find list of voices
voiceName: "en-AU-WilliamNeural",
// Azure resource key. By default it will look for this environment variable
resourceKey: process.env.AZURE_SPEECH_RESOURCE_KEY,
// Azure region. By default it will look for this environment variable
region: process.env.AZURE_SPEECH_REGION,
});
You can try out the API's different voice options on the Azure site: Text to Speech - Microsoft Azure
Once you've found a voice you like, you can find the 'short name' on this page: Language support - Speech service. The short name is the string that starts with a language code, followed by the character name, for example: en-GB-LibbyNeural
.
By default, the plugin creates a collection of pages that have mp3Url
set in the data cascade. The value of the mp3Url
key becomes the permalink of the generated MP3. This could be set in Markdown frontmatter, or set in any other way that Eleventy supports. If you'd like to use a different key instead of mp3Url
, you can set the mp3UrlDataKey
option when adding the plugin.
If you need more flexibility, you can extend the AudioVersionTemplate
class in your input directory.
The options here make it possible to:
Here's an example of how you could extend the AudioVersionTemplate
class:
const { AudioVersionTemplate } = require("eleventy-plugin-text-to-speech");
const {removeCodeBlocks, convertContentToPlainText} = require('../imaginary-utils')
Class CustomAudioVersionTemplate extends AudioVersionTemplate {
// string pointing to data in the Eleventy data cascade
mp3PagesArray = `myGlobalDataVariable` // Default = `collections.textToSpeechPluginPages`
// function that gets the content from the page data
getContentFromData = (mp3Page) => mp3Page.content // Default = (mp3Page) => mp3Page.templateContent
// function that gets the desired MP3 url (permalink) from the page data
getMp3UrlFromData = (mp3Page) => `/mp3/${mp3Page.slug}` // Default = (mp3Page) => mp3Page.data[mp3Page.data.textToSpeechPluginOptions.mp3UrlDataKey]
// optional function to do something with the content before converting to plain text
preprocessContent = async (content) => await removeCodeBlocks(content) // Default = (content) => content
// function that converts your content to plain text, ready for text to speech
convertContentToPlainText = async (content) => await convertContentToPlainText(content) // default = (content) => htmlToText.convert(content, {wordwrap: 0}) (from html-to-text library)
}
module.exports = CustomAudioVersionTemplate;
FAQs
Generate audio versions of your Eleventy content using Azure text to speech
The npm package eleventy-plugin-text-to-speech receives a total of 0 weekly downloads. As such, eleventy-plugin-text-to-speech popularity was classified as not popular.
We found that eleventy-plugin-text-to-speech demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.