Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
ai-text-to-speech
Advanced tools
A powerful and straightforward Node.js module for generating AI speech audio files from text using the OpenAI API (support for other providers is in the works). ai-text-to-speech offers a simple and robust interface to convert text into high-quality speec
Simplify your AI text-to-speech integration!
A powerful and straightforward Node.js module for generating speech audio from text using the OpenAI API (support for other TTS providers in the works). ai-text-to-speech offers a simple and robust interface to convert text into high-quality speech audio files in various formats and voices.
Developed by Jerry Kapron for everyone to use freely 👍🏼
☕️ Buy me a coffee
Install ai-text-to-speech via NPM:
npm install ai-text-to-speech
// Use this import statement if your project supports ES Modules
import aiSpeech from 'ai-text-to-speech';
OR
// Use this require statement if your project uses CommonJS modules
const aiSpeech = require('ai-text-to-speech');
(async () => { // or nested inside another async function
try {
const audioFilePath = await aiSpeech({
input: 'Buy me a coffee if it works for you.'
// If the OPENAI_API_KEY environment variable is already set,
// you don't have to specify the api_key option
});
console.log(`Audio file saved at: ${audioFilePath}`);
} catch (error) {
console.error('Error generating speech audio:', error.message);
}
})();
// This approach can be useful if you prefer working with promises directly
// or if you're in an environment where async/await is not supported.
aiSpeech({
input: 'Buy me a coffee if it works for you.',
// You can explicitly provide your OpenAI API key here
api_key: 'YOUR_OPENAI_API_KEY', // if process.env.OPENAI_API_KEY is not set
})
.then((audioFilePath) => {
console.log(`Audio file saved at: ${audioFilePath}`);
})
.catch((error) => {
console.error('Error generating speech audio:', error.message);
});
(async () => { // or nested inside another async function
try {
const audioFilePath = await aiSpeech({
input: 'Buy me a coffee if it works for you.',
dest_dir: './audio',
file_name: 'welcome-message',
voice: 'echo',
model: 'tts-1-hd',
response_format: 'wav',
suffix_type: 'nano',
api_key: 'YOUR_OPENAI_API_KEY', // if process.env.OPENAI_API_KEY is not set
});
console.log(`Audio file saved at: ${audioFilePath}`);
} catch (error) {
console.error('Error generating speech audio:', error.message);
}
})();
// This approach can be useful if you prefer working with promises directly
// or if you're in an environment where async/await is not supported.
aiSpeech({
input: 'Buy me a coffee if it works for you.',
dest_dir: './audio',
file_name: 'welcome-message',
voice: 'echo',
model: 'tts-1-hd',
response_format: 'wav',
suffix_type: 'nano',
api_key: 'YOUR_OPENAI_API_KEY', // if process.env.OPENAI_API_KEY is not set
})
.then((audioFilePath) => {
console.log(`Audio file saved at: ${audioFilePath}`);
})
.catch((error) => {
console.error('Error generating speech audio:', error.message);
});
input
(string, required)The text to generate audio for. Maximum length is 4096 characters.
dest_dir
(string, optional)The destination directory to save the audio file. Default: './'
(current directory).
file_name
(string, optional)The base name of the output file. Default: 'speech-audio'
.
voice
(string, optional)The voice to use for speech synthesis. Default: 'nova'
.
model
(string, optional)The TTS model to use. Default: 'tts-1'
.
response_format
(string, optional)The audio format for the output file. Default: 'mp3'
.
suffix_type
(string, optional)The type of unique suffix used in the file name. Default: 'uuid'
.
api_key
(string, optional)Your OpenAI API key. Default: The value of the OPENAI_API_KEY
environment variable.
alloy
echo
fable
onyx
nova
(default)shimmer
tts-1
(default)tts-1-hd
mp3
(default)opus
aac
flac
wav
pcm
uuid
(default): A unique UUID string.milli
: Timestamp in milliseconds.micro
: Timestamp in microseconds.nano
: Timestamp in nanoseconds.none
: No suffix. Warning: May overwrite existing files if filenames collide.input
text must not exceed 4096 characters. Exceeding this limit will result in an error.suffix_type: 'none'
without specifying a unique file_name
may lead to overwriting existing files.dest_dir
exists and the application has write permissions. The module will throw an error if it cannot write to the directory.api_key
option or the OPENAI_API_KEY
environment variable.voice
, model
, response_format
, or suffix_type
will result in an error.This project is licensed under the MIT License.
For more information on voice options, see the OpenAI Text-to-Speech Voice Options.
Note: Ensure compliance with OpenAI's usage policies when integrating this module into your applications.
FAQs
A powerful and straightforward Node.js module for generating AI speech audio files from text using the OpenAI API (support for other providers is in the works). ai-text-to-speech offers a simple and robust interface to convert text into high-quality speec
We found that ai-text-to-speech demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.