I want to play a WAV file over GSM modem. Here is my sample code
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();
}
}
}
But the problem is the WAV file sending through serial port is playing very fast. I don't know what's the problem . Here is my WAV file description:
ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, Audio Sample Rate 8Khz
.
Can anyone help me to solve the issue?
Since WAV is quite a popular format, almost all devices today support it using built-in media players. On Windows, the Windows Media Player is capable of playing WAV files. On MacOS, iTunes or QuickTime can play WAV files. On Linux, your basic ALSA system can play these files.
A GSM modem or GSM module is a device that uses GSM mobile telephone technology to provide a wireless data link to a network. GSM modems are used in mobile telephones and other equipment that communicates with mobile telephone networks. They use SIMs to identify their device to the network.
The WAV format is one of the simplest for storing audio information. The data is stored "in the raw" with no preprocessing. The WAV format is a Microsoft proprietary format, and is a special case of the RIFF (Resource Interchange File Format) format.
Windows and Mac are both capable of opening WAV files. For Windows, if you double-click a WAV file, it will open using Windows Media Player. For Mac, if you double-click a WAV, it will open using iTunes or Quicktime. If you're on a system without these programs installed, then consider third-party software.
I would check the following - especially #3.
How about sleeping a while after "outputStream.flush();"
might be Thread.sleep(50)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With