zlargon / google-tts

Google TTS (Text-To-Speech) for node.js
https://www.npmjs.com/package/google-tts-api
MIT License
279 stars 56 forks source link

tts with join channel #40

Closed Sophan-Developer closed 3 years ago

Sophan-Developer commented 3 years ago

I use it with discord.js v11.6.1 How to fix this with New version 2.0.0? Why you don't have discord server?


const tts = require("google-tts-api");

 // tts(tts1, `km`, 0.90) old version

tts.getAudioUrl("hello world", {
              lang: "en-US",
              slow: false,
              host: "https://translate.google.com"
            })
            .then(function(url) {
              voiceChannel.join().then(connection => {
                voice();

                function voice() {
                  const stream = connection.playStream(url);
                }
              });
zlargon commented 3 years ago

Hi @KimYou-Developer, the tts.getAudioUrl in version 2.0.0 is not a promise function.

Please see the README and CHANGELOG. Thanks

Sophan-Developer commented 3 years ago

Bot joined voice and not playstream


const tts = require("google-tts-api");

let tts1 = message.content.split(" ").slice(1).join(" ");

        const voiceChannel = message.member.voiceChannel;
        if (!voiceChannel) return message.channel.send('**Please be in a voice channel first!**');
        if (!client.voiceConnections.get(message.channel.guild.id)) {
        voiceChannel.join()
        .then(connnection => {
            tts.getAudioBase64(tts1, {

    lang: 'en-US',
    slow: false,
    host: 'https://translate.google.com',
    timeout: 10000,

  })
          .then((url) => {
            const dispatcher = connnection.playStream(url);
          })
          .catch((err) => {
            message.channel.send(':no_entry_sign: Something wen\'t wrong.\n' + err);
            voiceChannel.leave();
          });
        });
       } else {

       }
zlargon commented 3 years ago

Hi @KimYou-Developer,

getAudioBase64 is return a base64 encoded string but not the URL. (from new Google API)

You can try to use tts.getAudioUrl in this way.

const tts = require('google-tts-api');

const voiceChannel = message.member.voiceChannel;
if (!voiceChannel) return message.channel.send('**Please be in a voice channel first!**');
if (!client.voiceConnections.get(message.channel.guild.id)) {
  voiceChannel
    .join()
    .then((connnection) => {
      const url = tts.getAudioUrl(tts1);
      const dispatcher = connnection.playStream(url);
    })
    .catch((err) => {
      message.channel.send(":no_entry_sign: Something wen't wrong.\n" + err);
      voiceChannel.leave();
    });
}
Sophan-Developer commented 3 years ago

@zlargon thanks for helping 😍😍