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 bit, mono, 1 bytes/frame, Audio Sample Rate 8Khz
.
誰でも問題を解決するのを手伝ってもらえますか?