Socket
Socket
Sign inDemoInstall

@sefinek/google-tts-api

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sefinek/google-tts-api

Google TTS (Text-To-Speech) for Node.js without any vulnerabilities. For free without any API keys!


Version published
Maintainers
0
Created
Source

📢 Google TTS API

Google TTS (Text-To-Speech) for Node.js without any vulnerabilities. For free without any API keys!

@sefinek/google-tts-api.png @sefinek/google-tts-api.png @sefinek/google-tts-api.png

📥 Installation

$ npm install --save google-tts-api
$ npm install -D typescript @types/node # Only for TypeScript

🤔 Usage

MethodOptions (all optional)Return TypeHandle Long Text
getAudioUrllang, slow, hoststring
getAudioBase64lang, slow, host, timeoutPromise<string>
getAllAudioUrlslang, slow, host, splitPunct{ shortText: string; url: string; }[]
getAllAudioBase64lang, slow, host, timeout, splitPunctPromise<{ shortText: string; base64: string; }[]>

Options (all optional)

OptionTypeDefaultDescription
langstringenSee all available language code at https://cloud.google.com/speech/docs/languages
slowbooleanfalseUse the slow audio speed if set slow to true
hoststringhttps://translate.google.comYou can change the host if the default host could not work in your region (e.g. https://translate.google.com.cn).
timeoutnumber10000 (ms)(Only for getAudioBase64 and getAllAudioBase64) Set timeout for the HTTP request.
splitPunctstring(Only for getAllAudioUrls and getAllAudioBase64) Set the punctuation to split the long text to short text. (e.g. ",、。")

💻 Examples

1. getAudioUrl(text, [option])

import * as googleTTS from '@sefinek/google-tts-api'; // ES6 or TypeScript
const googleTTS = require('@sefinek/google-tts-api'); // CommonJS

// Get audio URL
const url = googleTTS.getAudioUrl('Hello world!', {
  lang: 'en',
  slow: false,
  host: 'https://translate.google.com',
});
console.log(url); // https://translate.google.com/translate_tts?...

2. getAudioBase64(text, [option])

import * as googleTTS from '@sefinek/google-tts-api'; // ES6 or TypeScript
const googleTTS = require('@sefinek/google-tts-api'); // CommonJS

// Get base64 text
googleTTS
  .getAudioBase64('Hello world!', {
    lang: 'en',
    slow: false,
    host: 'https://translate.google.com',
    timeout: 10000,
  })
  .then(console.log) // base64 text
  .catch(console.error);

3. getAllAudioUrls(text, [option]) (For text longer than 200 characters)

import * as googleTTS from '@sefinek/google-tts-api'; // ES6 or TypeScript
const googleTTS = require('@sefinek/google-tts-api'); // CommonJS

const results = googleTTS.getAllAudioUrls('LONG_TEXT_...', {
  lang: 'en',
  slow: false,
  host: 'https://translate.google.com',
  splitPunct: ',.?',
});
console.log(results);
// [
//   { shortText: '...', url: '...' },
//   { shortText: '...', url: '...' },
//   ...
// ];

4. getAllAudioBase64(text, [option]) (For text longer than 200 characters)

import * as googleTTS from '@sefinek/google-tts-api'; // ES6 or TypeScript
const googleTTS = require('@sefinek/google-tts-api'); // CommonJS

googleTTS
  .getAllAudioBase64('LONG_TEXT_...', {
    lang: 'en',
    slow: false,
    host: 'https://translate.google.com',
    timeout: 10000,
    splitPunct: ',.?',
  })
  .then(console.log)
  // [
  //   { shortText: '...', base64: '...' },
  //   { shortText: '...', base64: '...' },
  //   ...
  // ];
  .catch(console.error);
More examples

📑 License

MIT

Keywords

FAQs

Package last updated on 12 Sep 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc