Actarus
Actarus
DIAdiscord.js - Imagine an app
Created by Actarus on 7/7/2023 in #djs-voice
Stop streaming audo after a short time
Hello I have a bot who stream audio in a channel but it work but in a coupe minute it will stop playing for no reason. There no visible erreur on the terminal...
this.on = true ;

// micro
this.arecord = spawn('arecord', ['-D', 'plughw:1', '-f', 'S16_LE', '-r', '48000', '-c', '2']);


this.player = createAudioPlayer();

// flux
this.audioStream = new Readable({
read() {},
});


this.connection = joinVoiceChannel({
channelId: this.message.member.voice.channel.id,
guildId: this.message.guild.id,
adapterCreator: this.message.guild.voiceAdapterCreator,
});

this.audioResource = createAudioResource( this.audioStream, {
inputType: StreamType.Raw,
});


this.player.play( this.audioResource ) ;

this.connection.subscribe( this.player );

// Redirige la sortie de l'enregistrement du microphone vers le tampon
this.arecord.stdout.on('data', (data) => {

this.audioStream.push(data); // Pousse les données dans le flux de lecture

});


this.arecord.on('error', (error) => {
console.error('Erreur lors de la capture de l\'audio du microphone:', error);
});

this.player.on('error', (error) => {
console.error('Erreur lors de la diffusion de l\'audio sur le canal vocal:', error);
});


this.connection_Handler = (oldState, newState) => {

if (newState.status === 'disconnected' && oldState.status !== 'disconnected') {

console.log('Le bot s\'est déconnecté du canal vocal.');

this.stop();

}
};

this.connection.on('stateChange', this.connection_Handler);
this.on = true ;

// micro
this.arecord = spawn('arecord', ['-D', 'plughw:1', '-f', 'S16_LE', '-r', '48000', '-c', '2']);


this.player = createAudioPlayer();

// flux
this.audioStream = new Readable({
read() {},
});


this.connection = joinVoiceChannel({
channelId: this.message.member.voice.channel.id,
guildId: this.message.guild.id,
adapterCreator: this.message.guild.voiceAdapterCreator,
});

this.audioResource = createAudioResource( this.audioStream, {
inputType: StreamType.Raw,
});


this.player.play( this.audioResource ) ;

this.connection.subscribe( this.player );

// Redirige la sortie de l'enregistrement du microphone vers le tampon
this.arecord.stdout.on('data', (data) => {

this.audioStream.push(data); // Pousse les données dans le flux de lecture

});


this.arecord.on('error', (error) => {
console.error('Erreur lors de la capture de l\'audio du microphone:', error);
});

this.player.on('error', (error) => {
console.error('Erreur lors de la diffusion de l\'audio sur le canal vocal:', error);
});


this.connection_Handler = (oldState, newState) => {

if (newState.status === 'disconnected' && oldState.status !== 'disconnected') {

console.log('Le bot s\'est déconnecté du canal vocal.');

this.stop();

}
};

this.connection.on('stateChange', this.connection_Handler);
This not a problem with the micro
2 replies