1.0.2 • Published 3 years ago

tts-simple v1.0.2

Weekly downloads
5
License
ISC
Repository
github
Last release
3 years ago

What is this?

This is a simple and light weight package for turning text into a .mp3 file

Installation

npm i tts-simple

Paramaters

const tts = require('tts-simple')

tts({
  text: "The text you want it to say",
  fileName: "The name of this file (make this unique)"
})

None of these params are optional


Simple Example

const tts = require('tts-simple)

tts({
  text: "Hello there",
  fileName: "greeting"
})

This will create a mp3 file name greeting with the audio saying Hello there


Example text to speech command in discordjs

const tts = require('tts-simple')
const text = message.content.split(/ +/g).slice(1).join(" ")
const fileName = `tts_${message.id}`

if (!message.member.voice.channel) return message.channel.send("You need to be in a voice channel")

let res = tts({text: text, fileName: fileName})
if (res.type == "error") return message.channel.send(res.message)

const connection = await message.member.voice.channel.join()

const dispatcher = await connection.play(fileName)

dispatcher.on('finish', () => {
        dispatcher.destroy();
        connection.disconnect();
        try {
            fs.unlinkSync(`tts_${message.id}.mp3`)
        } catch(err) {
            console.error(err)
        }
    });

dispatcher.on('error', console.error);