gpt4 book ai didi

java - 通过 GSM 调制解调器播放 WAV 文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:25:46 27 4
gpt4 key购买 nike

我想通过 GSM 调制解调器播放 WAV 文件。这是我的示例代码

private final int BUFFER_SIZE = 8;
private File soundFile;
private AudioInputStream audioStream;
private AudioFormat audioFormat;
public void playSound(String filename) throws IOException{

String strFilename = filename;

try {
soundFile = new File(strFilename);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}

try {
audioStream = AudioSystem.getAudioInputStream(soundFile);
} catch (Exception e){
e.printStackTrace();
System.exit(1);
}

audioFormat = audioStream.getFormat();

DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);

int nBytesRead = 0;
byte[] abData = new byte[BUFFER_SIZE];
while (nBytesRead != -1) {
try {
nBytesRead = audioStream.read(abData);
} catch (IOException e) {
e.printStackTrace();
}
if (nBytesRead >= 0) {
outputStream.write(abData, 0, nBytesRead);
outputStream.flush();
}
}
}

但问题是通过串口发送的WAV文件播放速度非常快。我不知道出了什么问题。这是我的 WAV 文件描述:

ULAW 8000.0 Hz,8 位,单声道,1 字节/帧,音频采样率 8Khz

谁能帮我解决这个问题?

最佳答案

我会检查以下内容 - 特别是 #3。

  1. Synchronization
  2. AudioFormat
  3. JSSRC Resampling Library

关于java - 通过 GSM 调制解调器播放 WAV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19768031/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com