Playing Base64 Through Voice

How can I play base64 data through voice?
3 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Avery
AveryOP6mo ago
Code:
const { EmbedBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder, Colors } = require("discord.js");
const gtts = require("google-tts-api");
const voice = require("@discordjs/voice");
const { Buffer } = require("buffer");

const RTO = {
TEXT: "1244815994623492127",
VC: "1244816012994416680"
};

const emergency = interaction.options.getString("emergency");
const location = interaction.options.getString("location");
const user = interaction.member.nickname || interaction.user.username;

const textChannel = interaction.guild.channels.cache.get(RTO.TEXT);
const voiceChannel = interaction.guild.channels.cache.get(RTO.VC);

const tts = await gtts.getAudioBase64(
`911 call from ${user}. ${emergency}. Location: ${location}`
);

console.log(tts);

await interaction.reply({
embeds: [
new EmbedBuilder()
.setColor(Colors.Green)
.setTitle("Your call has been dispatched")
.setDescription(
`Your emergency has been dispatched to RTO. Officers will be enroute shortly.`
)
],
ephemeral: true
});

await textChannel.send({
embeds: [
new EmbedBuilder()
.setColor(Colors.Blurple)
.setTitle("Incoming 911 Call")
.setDescription(
`**Caller:** ${user}\n**Emergency:** ${emergency}\n**Location:** ${location}`
)
.setFooter({
text: "Emergency has also been dispatched to the voice channel."
})
]
});

voice.joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});

const player = voice.createAudioPlayer();

const resource = voice.createAudioResource(tts, {
inputType: voice.StreamType.Arbitrary
});

player.play(resource);
}
const { EmbedBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder, Colors } = require("discord.js");
const gtts = require("google-tts-api");
const voice = require("@discordjs/voice");
const { Buffer } = require("buffer");

const RTO = {
TEXT: "1244815994623492127",
VC: "1244816012994416680"
};

const emergency = interaction.options.getString("emergency");
const location = interaction.options.getString("location");
const user = interaction.member.nickname || interaction.user.username;

const textChannel = interaction.guild.channels.cache.get(RTO.TEXT);
const voiceChannel = interaction.guild.channels.cache.get(RTO.VC);

const tts = await gtts.getAudioBase64(
`911 call from ${user}. ${emergency}. Location: ${location}`
);

console.log(tts);

await interaction.reply({
embeds: [
new EmbedBuilder()
.setColor(Colors.Green)
.setTitle("Your call has been dispatched")
.setDescription(
`Your emergency has been dispatched to RTO. Officers will be enroute shortly.`
)
],
ephemeral: true
});

await textChannel.send({
embeds: [
new EmbedBuilder()
.setColor(Colors.Blurple)
.setTitle("Incoming 911 Call")
.setDescription(
`**Caller:** ${user}\n**Emergency:** ${emergency}\n**Location:** ${location}`
)
.setFooter({
text: "Emergency has also been dispatched to the voice channel."
})
]
});

voice.joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});

const player = voice.createAudioPlayer();

const resource = voice.createAudioResource(tts, {
inputType: voice.StreamType.Arbitrary
});

player.play(resource);
}
Why isn't this working? Nvm, new code: doesn't work!!!
const { EmbedBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder, Colors } = require("discord.js");
const ttsBot = require("discord-tts");
const voice = require("@discordjs/voice");
const { Buffer } = require("buffer");
const ffmpeg = require("fluent-ffmpeg");

const RTO = {
TEXT: "1244815994623492127",
VC: "1244816012994416680"
};

let voiceConnection;
let audioPlayer = new voice.createAudioPlayer();

const emergency = interaction.options.getString("emergency");
const location = interaction.options.getString("location");
const user = interaction.member.nickname || interaction.user.username;

const textChannel = interaction.guild.channels.cache.get(RTO.TEXT);
const voiceChannel = interaction.guild.channels.cache.get(RTO.VC);

const stream = ttsBot.getVoiceStream(emergency);
const audioResource = voice.createAudioResource(stream, {
inputType: voice.StreamType.Arbitrary,
inlineVolume: true
});

if (
!voiceConnection ||
voiceConnection?.status === voice.VoiceConnectionStatus.Disconnected
) {
voiceConnection = voice.joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator
});
console.debug(voiceConnection);

voiceConnection = await voice.entersState(
voiceConnection,
voice.VoiceConnectionStatus.Connecting,
5_000
);
console.debug(voiceConnection);
}

if (voiceConnection.status === voice.VoiceConnectionStatus.Ready) {
voiceConnection.subscribe(player);
player.play(audioResource);
console.debug(voiceConnection);
}
}
};
const { EmbedBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder, Colors } = require("discord.js");
const ttsBot = require("discord-tts");
const voice = require("@discordjs/voice");
const { Buffer } = require("buffer");
const ffmpeg = require("fluent-ffmpeg");

const RTO = {
TEXT: "1244815994623492127",
VC: "1244816012994416680"
};

let voiceConnection;
let audioPlayer = new voice.createAudioPlayer();

const emergency = interaction.options.getString("emergency");
const location = interaction.options.getString("location");
const user = interaction.member.nickname || interaction.user.username;

const textChannel = interaction.guild.channels.cache.get(RTO.TEXT);
const voiceChannel = interaction.guild.channels.cache.get(RTO.VC);

const stream = ttsBot.getVoiceStream(emergency);
const audioResource = voice.createAudioResource(stream, {
inputType: voice.StreamType.Arbitrary,
inlineVolume: true
});

if (
!voiceConnection ||
voiceConnection?.status === voice.VoiceConnectionStatus.Disconnected
) {
voiceConnection = voice.joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator
});
console.debug(voiceConnection);

voiceConnection = await voice.entersState(
voiceConnection,
voice.VoiceConnectionStatus.Connecting,
5_000
);
console.debug(voiceConnection);
}

if (voiceConnection.status === voice.VoiceConnectionStatus.Ready) {
voiceConnection.subscribe(player);
player.play(audioResource);
console.debug(voiceConnection);
}
}
};
the bot isn’t speaking
duck
duck6mo ago
instead of waiting for your connection to enter the Connecting state and then checking if it's Ready, you may want to wait for it to enter the Ready state
Want results from more Discord servers?
Add your server