Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate long texts #30

Closed
chayleaf opened this issue Feb 18, 2020 · 1 comment
Closed

Translate long texts #30

chayleaf opened this issue Feb 18, 2020 · 1 comment

Comments

@chayleaf
Copy link

chayleaf commented Feb 18, 2020

  1. Split text to parts of max 200 chars
  2. Add parameters: q=<part>&total=<total parts>&idx=<part index>&textlen=<part length>
@zlargon
Copy link
Owner

zlargon commented Dec 9, 2020

Version 2.0.0 supports the long texts now. Please see the usage in README:

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

  • Available options: lang, slow, host, splitPunct
  • Example:
    const googleTTS = require('google-tts-api');
    
    const results = googleTTS.getAllAudioUrls('LONG_TEXT_...', {
      lang: 'en-US',
      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)

  • This is a promise function
  • Available options: lang, slow, host, timeout, splitPunct
  • Example:
    const googleTTS = require('google-tts-api');
    
    googleTTS
      .getAllAudioBase64('LONG_TEXT_...', {
        lang: 'en-US',
        slow: false,
        host: 'https://translate.google.com',
        timeout: 10000,
        splitPunct: ',.?',
      })
      .then(console.log)
      // [
      //   { shortText: '...', base64: '...' },
      //   { shortText: '...', base64: '...' },
      //   ...
      // ];
      .catch(console.error);

@chayleaf chayleaf closed this as completed Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants