Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
cloud-text-to-speech
Advanced tools
Single interface to Google, Microsoft and Amazon Text-To-Speech.
Single interface to Google, Microsoft, and Amazon Text-To-Speech. NodeJS implementation of:
We welcome and value your ideas and suggestions to improve this project! To submit and vote for feature requests, please visit our Feature Requests Board.
On the board, you can:
Thank you for contributing to the development and improvement of Cloud Text-To-Speech!
There are essentially two ways to use Cloud Text-To-Speech:
TtsProviders.google
, TtsProviders.microsoft
, TtsProviders.amazon
to use the single provider at a time.TtsProviders.combine
to combine all providers and get all voices at once.To init configuration use:
//Do init once and run it before any other method
TtsUniversal.init({
provider: TtsProviders.amazon,
googleParams: { apiKey: "API-KEY" },
microsoftParams: { subscriptionKey: "SUBSCRIPTION-KEY", region: "eastus" },
amazonParams: { keyId: "KEY-ID", accessKey: "ACCESS-KEY", region: "us-east-1" },
withLogs: true
});
To change provider use:
TtsUniversal.setProvider(TtsProviders.microsoft);
To get the list of all voices use:
//Get voices
const voicesResponse = await TtsUniversal.getVoices();
const voices = voicesResponse.voices;
//Print all available voices
console.log(voices);
//Pick an English Voice
const voice = voices.find((voice) => voice.locale.code.startsWith('en-'));
To convert TTS and get audio use:
//Generate Audio for a text
const text = "Amazon, Microsoft and Google Text-to-Speech API are awesome";
const ttsParams = new TtsParamsUniversal({
voice: voice,
audioFormat: AudioOutputFormatUniversal.mp3_64k,
text: text,
rate: 'slow', //optional
pitch: 'default', //optional
});
const ttsResponse = await TtsUniversal.convertTts(ttsParams);
//Get the audio bytes.
const audioBytes = ttsResponse.audio;
To init configuration use:
//Do init once and run it before any other method
TtsUniversal.init({
provider: TtsProviders.combine,
googleParams: { apiKey: "API-KEY" },
microsoftParams: { subscriptionKey: "SUBSCRIPTION-KEY", region: "eastus" },
amazonParams: { keyId: "KEY-ID", accessKey: "ACCESS-KEY", region: "us-east-1" },
withLogs: true
});
To change provider use:
TtsUniversal.setProvider(TtsProviders.combine);
To get the list of all voices use:
//Get voices
const voicesResponse = await TtsUniversal.getVoices();
const voices = voicesResponse.voices;
//Print all available voices
console.log(voices);
//Pick an English Voice
const voice = voices.find((voice) => voice.locale.code.startsWith('en-'));
To convert TTS and get audio use:
//Generate Audio for a text
const text = "Amazon, Microsoft and Google Text-to-Speech API are awesome";
const ttsParams = new TtsParamsUniversal({
voice: voice,
audioFormat: AudioOutputFormatUniversal.mp3_64k,
text: text,
rate: 'slow', //optional
pitch: 'default', //optional
});
const ttsResponse = await TtsUniversal.convertTts(ttsParams);
//Get the audio bytes.
const audioBytes = ttsResponse.audio;
To init configuration use:
//Do init once and run it before any other method
TtsGoogle.init({
params: { apiKey: 'API-KEY' },
withLogs: true,
});
To get the list of all voices use:
//Get voices
const voicesResponse = await TtsGoogle.getVoices();
const voices = voicesResponse.voices;
//Print all voices
console.log(voices);
//Pick an English Voice
const voice = voices.find((voice) => voice.locale.code.startsWith('en-'));
To convert TTS and get audio use:
//Generate Audio for a text
const text = '<speak>Google<break time="2s"> Speech Service Text-to-Speech API is awesome!</speak>';
const ttsParams = new TtsParamsGoogle({
voice: voice,
audioFormat: AudioOutputFormatGoogle.mp3,
text: text,
rate: 'slow', //optional
pitch: 'default', //optional
});
const ttsResponse = await TtsGoogle.convertTts(ttsParams);
//Get the audio bytes.
const audioBytes = ttsResponse.audio;
To init configuration use:
//Do init once and run it before any other method
TtsMicrosoft.init({
params: { subscriptionKey: 'SUBSCRIPTION-KEY', region: 'eastus' },
withLogs: true,
});
To get the list of all voices use:
//Get voices
const voicesResponse = await TtsMicrosoft.getVoices();
const voices = voicesResponse.voices;
//Print all voices
console.log(voices);
//Pick an English Voice
const voice = voices.find((voice) => voice.locale.code.startsWith('en-'));
To convert TTS and get audio use:
//Generate Audio for a text
const text = '<speak>Microsoft<break time="2s"> Speech Service Text-to-Speech API is awesome!</speak>';
const ttsParams = new TtsParamsMicrosoft({
voice: voice,
audioFormat: AudioOutputFormatMicrosoft.audio48Khz192kBitrateMonoMp3,
text: text,
rate: 'slow', //optional
pitch: 'default', //optional
});
const ttsResponse = await TtsMicrosoft.convertTts(ttsParams);
//Get the audio bytes.
const audioBytes = ttsResponse.audio;
To init configuration use:
//Do init once and run it before any other method
TtsAmazon.init({
params: { keyId: 'KEY-ID', accessKey: 'ACCESS-KEY', region: 'us-east-1' },
withLogs: true,
});
To get the list of all voices use:
//Get voices
const voicesResponse = await TtsAmazon.getVoices();
const voices = voicesResponse.voices;
//Print all voices
console.log(voices);
//Pick an English Voice
const voice = voices.find((voice) => voice.locale.code.startsWith('en-'));
To convert TTS and get audio use:
//Generate Audio for a text
const text = '<speak>Amazon<break time="2s"> Speech Service Text-to-Speech API is awesome!</speak>';
const ttsParams = new TtsParamsAmazon({
voice: voice,
audioFormat: AudioOutputFormatAmazon.mp3,
text: text,
rate: 'slow', // optional
pitch: 'default', // optional
});
const ttsResponse = await TtsAmazon.convertTts(ttsParams);
//Get the audio bytes.
const audioBytes = ttsResponse.audio;
There are things you should take care of:
(new XMLSerializer()).serializeToString(new DOMParser().parseFromString(ssml, 'text/xml'))
.FAQs
Single interface to Google, Microsoft and Amazon Text-To-Speech.
We found that cloud-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 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.