Say smthing in vocal to text.

Hi I want to keep the text that i said in vocale with this code :
joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
})
const connection = client.voice.connections.get(message.guild.id);
if (!connection) return; // bot is not connected to the voice channel

const receiver = connection.receiver;
const readable = new Readable();

const audioStream = receiver.createStream(message.member, {
mode: 'pcm'
});

audioStream.on('error', console.error);
audioStream.on('end', () => {
console.log('Audio stream ended');
});

readable._read = () => {};
readable.pipe(audioStream);

// handle audio data as you wish
// for example, you could use a speech-to-text API to transcribe the audio
readable.on('data', (chunk) => {
console.log('Received audio data:', chunk);
});
}
joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
})
const connection = client.voice.connections.get(message.guild.id);
if (!connection) return; // bot is not connected to the voice channel

const receiver = connection.receiver;
const readable = new Readable();

const audioStream = receiver.createStream(message.member, {
mode: 'pcm'
});

audioStream.on('error', console.error);
audioStream.on('end', () => {
console.log('Audio stream ended');
});

readable._read = () => {};
readable.pipe(audioStream);

// handle audio data as you wish
// for example, you could use a speech-to-text API to transcribe the audio
readable.on('data', (chunk) => {
console.log('Received audio data:', chunk);
});
}
but I have this error :
node:events:368
throw er; // Unhandled 'error' event
^

TypeError: Cannot read properties of undefined (reading 'get')
at Client.<anonymous> (C:\Users\manou\OneDrive\Bureau\hahaha\index.js:103:49)
node:events:368
throw er; // Unhandled 'error' event
^

TypeError: Cannot read properties of undefined (reading 'get')
at Client.<anonymous> (C:\Users\manou\OneDrive\Bureau\hahaha\index.js:103:49)
please help me thanks
9 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
dx0_
dx0_OP2y ago
I have tried to declarated connection as
joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
})
joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
})
but U had an another error
duck
duck2y ago
const connection = client.voice.connections.get(message.guild.id);
<ClientVoiceManager>.connections doesn't exist if you're new to @discordjs/voice, you should read the whole voice guide https://discordjs.guide/voice/ but in particular this section covers accessing existing voice connections https://discordjs.guide/voice/voice-connections.html#access though of course joinVoiceChannel returns the connection created
I have tried to declarated connection as joinVoiceChannel({ but U had an another error
what other error?
dx0_
dx0_OP2y ago
const connection = await joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
})
// console.log(client.voice)
// const connection = client.voice.connections.get(message.guild.id);
// if (!connection) return; // bot is not connected to the voice channel

const receiver = connection.receiver;
const readable = new Readable();

const audioStream = receiver.createStream(newState.member, { mode: 'pcm' });

audioStream.on('error', console.error);
audioStream.on('end', () => {
console.log('Audio stream ended');
});

readable._read = () => {};
readable.pipe(audioStream);

// handle audio data as you wish
// for example, you could use a speech-to-text API to transcribe the audio
readable.on('data', (chunk) => {
console.log('Received audio data:', chunk);
});
const connection = await joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
})
// console.log(client.voice)
// const connection = client.voice.connections.get(message.guild.id);
// if (!connection) return; // bot is not connected to the voice channel

const receiver = connection.receiver;
const readable = new Readable();

const audioStream = receiver.createStream(newState.member, { mode: 'pcm' });

audioStream.on('error', console.error);
audioStream.on('end', () => {
console.log('Audio stream ended');
});

readable._read = () => {};
readable.pipe(audioStream);

// handle audio data as you wish
// for example, you could use a speech-to-text API to transcribe the audio
readable.on('data', (chunk) => {
console.log('Received audio data:', chunk);
});
With this code and this declaration for connection, I have this error :
TypeError: receiver.createStream is not a function**
TypeError: receiver.createStream is not a function**
duck
duck2y ago
It's true, that's not a function Were you looking for <VoiceReceiver>.subscribe()?
d.js docs
d.js docs2y ago
method VoiceReceiver#subscribe() Creates a subscription for the given user id.
dx0_
dx0_OP2y ago
I want to that the bot hear me and write what I say Its this ?
duck
duck2y ago
yes, as documented it returns an opus packet stream this can be decoded to pcm with an instance of prism-media's opus.Decoder (@discordjs/voice depends on prism-media so it should already be installed)
dx0_
dx0_OP2y ago
Thx
Want results from more Discord servers?
Add your server