text to speech

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.5 kB
1
Indexable
Never
if (input.toLowerCase().includes("/say")) {
                        let userLanguage = input.split(" ");
                        let toSpeech = input.toLowerCase().replace("/say " + userLanguage[1] + " ", "");
            
                        function sayCommand(convertSpeech, decideLanguage) {
                          let file = fs.createWriteStream("say.mp3");
                          let targetUrl = "https://translate.google.com.vn/translate_tts?ie=UTF-8&q=" + convertSpeech + "+&tl=" + decideLanguage + "&client=tw-ob";
                          let gifRequest = http.get(targetUrl, function(gifResponse) {
                            gifResponse.pipe(file);
                            file.on('finish', function() {
                              console.log('Finishing Downloading Text to MP3!')
                              let message = {
                                body: "Successfully Converted using Messenger bot by Ken Cas",
                                attachment: fs.createReadStream(__dirname + '/say.mp3')
                              }
                              api.sendMessage(message, event.threadID);
                              api.setMessageReaction("✅", event.messageID, (err) => {}, true);
                            });
                          });
                        }
                        switch (userLanguage[1]) {
                          case "kor":
                          case "korea":
                          case "korean":
                            sayCommand(toSpeech, "ko")
                            break;
                          case "fil":
                          case "filipino":
                          case "tag":
                          case "tagalog":
                            sayCommand(toSpeech, "tl")
                            break;
                          case "spanish":
                          case "spa":
                            sayCommand(toSpeech, "es-ES")
                            break;
                          case "hindi":
                          case "hin":
                            sayCommand(toSpeech, "hi-IN")
                            break;
                          case "indo":
                          case "indonesian":
                          case "indonesia":
                            sayCommand(toSpeech, "in")
                            break;
                          case "arab":
                          case "arabic":
                            sayCommand(toSpeech, "ar")
                            break;
                          case "eng":
                          case "english":
                            sayCommand(toSpeech, "en")
                            break;
                          case "jap":
                          case "japanese":
                          case "japan":
                            sayCommand(toSpeech, "ja")
                            break;
                          case "latin":
                          case "lat":
                            sayCommand(toSpeech, "la")
                            break;
                          default:
                            api.sendMessage("No language injected or invalid format\nUsage: /say <eng,tag,jap,indo,hindi,arab> <text>\n\nMessenger bot by Ken Cas", event.threadID, event.messageID);
                        }
                    }