修补:mp3文件未能正确播放

main
lensfrex 3 years ago
parent 3ecee380a9
commit 1a091588f5
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 6
      Dogename/pom.xml
  2. 10
      Dogename/src/main/java/me/lensferno/dogename/voice/VoicePlayer.java

@ -65,6 +65,12 @@
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>mp3spi</artifactId>
<version>1.9.5.4</version>
</dependency>
</dependencies>
<repositories>

@ -1,5 +1,6 @@
package me.lensferno.dogename.voice;
import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.utils.FilePath;
import me.lensferno.dogename.utils.IOUtil;
@ -92,8 +93,13 @@ public class VoicePlayer {
private void playSound(File file) {
try {
AudioInputStream sourceAudioInputStream = AudioSystem.getAudioInputStream(file);
AudioInputStream sourceAudioInputStream;
if (voiceConfig.getAudioFormat() == VoiceConfig.AUDIO_FORMAT_WAV) {
sourceAudioInputStream = AudioSystem.getAudioInputStream(file);
} else {
sourceAudioInputStream = new MpegAudioFileReader().getAudioInputStream(file);
}
AudioFormat sourceFormat = sourceAudioInputStream.getFormat();
AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
sourceFormat.getSampleRate(), 16, sourceFormat.getChannels(),

Loading…
Cancel
Save