Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

playing WAV file over GSM modem

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?

like image 345
Shantanu Banerjee Avatar asked Nov 04 '13 12:11

Shantanu Banerjee


People also ask

How do I watch WAV files?

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.

What are GSM modems used for?

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.

How is data stored in WAV?

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.

How do I import WAV files?

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.


2 Answers

I would check the following - especially #3.

  1. Synchronization
  2. AudioFormat
  3. JSSRC Resampling Library
like image 74
Elliott Frisch Avatar answered Oct 03 '22 11:10

Elliott Frisch


How about sleeping a while after "outputStream.flush();"
might be Thread.sleep(50)

like image 40
goodsong Avatar answered Oct 03 '22 09:10

goodsong