Have ideas to improve npm?Join in the discussion! »

    google-translate-tts

    0.4.0-dev • Public • Published

    google-translate-tts

    This package is for using Google Translate to create audio clips in node js.

    This library has been updated to work with the new changes to the Translate API introduced by Google in November 2020.

    A spiritual successor to google-tts-api which worked with the previous Translate API.

    Installation

    npm install google-translate-tts
    

    or

    yarn add google-translate-tts
    

    Usage

    Find a voice to use:

    const tts = require('google-translate-tts');
    
    // lookup by name
    const voice = tts.voices.findByName('English (United States)');
    
    // lookup by code
    const voice = tts.voices.findByCode('en-US');
    
    // an array of all voices
    console.log(tts.voices);
    
    /* Voice example:
     * {
     *   code: 'en-US',
     *   name: 'English (United States)'
     * }
     */

    Download an audio clip:

    const fs = require('fs');
    const tts = require('google-translate-tts');
    
    // notice that `tts.synthesize` returns a Promise<Buffer>
    const saveFile = async () => {
        const buffer = await tts.synthesize({
            text: 'Hello, world!',
            voice: 'en-US',
            slow: false // optional
        });
    
        fs.writeFileSync('hello-world.mp3', buffer);
    };
    
    saveFile();

    Install

    npm i google-translate-tts

    DownloadsWeekly Downloads

    3,142

    Version

    0.4.0-dev

    License

    MIT

    Unpacked Size

    15.1 kB

    Total Files

    12

    Last publish

    Collaborators

    • avatar