Skip to content

Commit

Permalink
* Improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Jul 13, 2022
1 parent 3d5a60d commit e329085
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/main/java/de/presti/ree6/audio/AudioPlayerReceiveHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.presti.ree6.audio;

import de.presti.ree6.main.Main;
import de.presti.ree6.utils.data.AudioUtil;
import net.dv8tion.jda.api.audio.AudioReceiveHandler;
import net.dv8tion.jda.api.audio.CombinedAudio;
Expand Down Expand Up @@ -110,9 +111,17 @@ public void endReceiving() {
byteBuffer.put(data);
}

voiceChannel.sendMessage("Here is your audio!").addFile(AudioUtil.convert(byteBuffer), new SimpleDateFormat("dd.MM.yyyy HH/mm").format(System.currentTimeMillis()) + "-" + voiceChannel.getId() + ".wav").queue();
if (voiceChannel.canTalk()) {
voiceChannel.sendMessage("Here is your audio!")
.addFile(AudioUtil.convertPCMtoWAV(byteBuffer), new SimpleDateFormat("dd.MM.yyyy HH/mm").format(System.currentTimeMillis()) + "-" + voiceChannel.getId() + ".wav").queue();
}
// Find a way to still notify that the bot couldn't send the audio.
} catch (Exception ex) {
voiceChannel.sendMessage("Something went wrong while converting your audio!\nReason: " + ex.getMessage()).queue();
if (voiceChannel.canTalk()) {
voiceChannel.sendMessage("Something went wrong while converting your audio!\nReason: " + ex.getMessage()).queue();
}

Main.getInstance().getLogger().error("Something went wrong while converting a recording!", ex);
}

voiceChannel.getGuild().getAudioManager().closeAudioConnection();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/presti/ree6/utils/data/AudioUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private AudioUtil() {
* @return The WAV encoded byte array.
* @throws IOException If an error occurs.
*/
public static byte[] convert(ByteBuffer byteBuffer) throws IOException {
public static byte[] convertPCMtoWAV(ByteBuffer byteBuffer) throws IOException {
AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED,
new AudioInputStream(new ByteArrayInputStream(byteBuffer.array()),
Expand Down

0 comments on commit e329085

Please sign in to comment.