com.speech4j.sound
Class Util

java.lang.Object
  |
  +--com.speech4j.sound.Util

public class Util
extends java.lang.Object

Utility class

Version:
1.2
Author:
Pavel Vlasov

Method Summary
static double bytes2sec(javax.sound.sampled.AudioFormat format, long size)
          Converts length in bytes to length in seconds given particular AudioFormat
static java.lang.String bytes2String(byte[] ba)
          Converts byte array to human readable string by converting each byte to two chars, example 3D
static byte[] convertSound(AudioBuffer buffer, javax.sound.sampled.AudioFormat targetFormat)
           
static byte[] convertSound(byte[] sound, javax.sound.sampled.AudioFormat sourceFormat, javax.sound.sampled.AudioFormat targetFormat)
           
static byte[] convertSound(byte[] sound, int offset, int length, javax.sound.sampled.AudioFormat sourceFormat, javax.sound.sampled.AudioFormat targetFormat)
           
static void createWavHeader(java.io.DataOutput out, int dataSize, javax.sound.sampled.AudioFormat format)
           
static void createWavHeader(java.io.RandomAccessFile raf, javax.sound.sampled.AudioFormat format)
           
static double fileLength(java.lang.String fileName)
          Calculates duration of audio file
static AudioBuffer merge(javax.sound.sampled.AudioFormat format, AudioBuffer[] sourceBuffers)
          Merges array of audio buffers into one audio buffer.
static void merge(javax.sound.sampled.AudioFormat format, AudioBuffer[] sourceBuffers, java.lang.String fileName)
          Merges array of AudioBuffers and outputs to file.
static void merge(javax.sound.sampled.AudioFormat format, java.lang.String[] sourceFiles, java.lang.String fileName)
          Merges array of audio files and outputs to file.
static void mergeAudio(java.lang.String fileName, javax.sound.sampled.AudioFormat format, java.lang.String[] sourceFiles)
          Merges audio files
static java.lang.String randomString()
          Generates pseudo-random string.
static AudioBuffer silence(double sec, javax.sound.sampled.AudioFormat format)
          Generates AudioBuffer of silence.
static byte[] string2Bytes(java.lang.String s)
          Converts string to byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bytes2String

public static java.lang.String bytes2String(byte[] ba)
Converts byte array to human readable string by converting each byte to two chars, example 3D

Parameters:
ba - Array of bytes
Returns:
String of bytes converted to hex notation

string2Bytes

public static byte[] string2Bytes(java.lang.String s)
Converts string to byte array.

Parameters:
s - String where every byte is represented by 2 chars, example: 3D
Returns:
Byte array

mergeAudio

public static void mergeAudio(java.lang.String fileName,
                              javax.sound.sampled.AudioFormat format,
                              java.lang.String[] sourceFiles)
                       throws java.io.IOException,
                              javax.sound.sampled.UnsupportedAudioFileException,
                              SoundException
Merges audio files

Parameters:
fileName - Name of the output file.
format - Output format.
sourceFiles - Array of source files.
Throws:
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException
SoundException

randomString

public static java.lang.String randomString()
Generates pseudo-random string.

Returns:
Pseudo-random string.

silence

public static AudioBuffer silence(double sec,
                                  javax.sound.sampled.AudioFormat format)
Generates AudioBuffer of silence. Useful for inserting pauses into audiofiles.

Parameters:
sec - Duration of silence in seconds
format - AudioFormat
Returns:
AudioBuffer with silence.

fileLength

public static double fileLength(java.lang.String fileName)
                         throws java.io.IOException,
                                javax.sound.sampled.UnsupportedAudioFileException
Calculates duration of audio file

Parameters:
fileName - Audio file
Returns:
file length in seconds.
Throws:
java.io.IOException
javax.sound.sampled.UnsupportedAudioFileException

bytes2sec

public static double bytes2sec(javax.sound.sampled.AudioFormat format,
                               long size)
Converts length in bytes to length in seconds given particular AudioFormat

Parameters:
format - AudioFormat
size - Size in bytes
Returns:
Duration in seconds

merge

public static AudioBuffer merge(javax.sound.sampled.AudioFormat format,
                                AudioBuffer[] sourceBuffers)
                         throws java.io.IOException,
                                SoundException
Merges array of audio buffers into one audio buffer. Audio formats of all buffers can be different. If format parameter is null then format of the resulting buffer is "maximum" of input buffers, for example if there are two input buffers, one is 16kHz 16bit Stereo and the other is 44kHz 8bit Mono then the resuting buffer will be 44kHz 16bit Stereo

Parameters:
format - Format of output buffer. Can be null.
sourceBuffers - Array of input audio buffers.
Returns:
AudioBuffer
Throws:
java.io.IOException
SoundException

merge

public static void merge(javax.sound.sampled.AudioFormat format,
                         AudioBuffer[] sourceBuffers,
                         java.lang.String fileName)
                  throws java.io.IOException,
                         SoundException
Merges array of AudioBuffers and outputs to file. Good for processing big amounts of data to save memory. Audio formats of all buffers and output format can be different. If format parameter is null then format of the resulting buffer is "maximum" of input buffers, for example if there are two input buffers, one is 16kHz 16bit Stereo and the other is 44kHz 8bit Mono then the resuting buffer will be 44kHz 16bit Stereo

Parameters:
format - Output format. Can be null.
sourceBuffers - input audio buffers.
fileName - output file name.
Throws:
java.io.IOException
SoundException

createWavHeader

public static void createWavHeader(java.io.RandomAccessFile raf,
                                   javax.sound.sampled.AudioFormat format)
                            throws java.io.IOException
java.io.IOException

createWavHeader

public static void createWavHeader(java.io.DataOutput out,
                                   int dataSize,
                                   javax.sound.sampled.AudioFormat format)
                            throws java.io.IOException
java.io.IOException

merge

public static void merge(javax.sound.sampled.AudioFormat format,
                         java.lang.String[] sourceFiles,
                         java.lang.String fileName)
                  throws java.io.IOException,
                         SoundException,
                         javax.sound.sampled.UnsupportedAudioFileException
Merges array of audio files and outputs to file. Good for processing big amounts of data to save memory. Audio formats of all buffers and output format can be different. If format parameter is null then format of the resulting buffer is "maximum" of input buffers, for example if there are two input buffers, one is 16kHz 16bit Stereo and the other is 44kHz 8bit Mono then the resuting buffer will be 44kHz 16bit Stereo

Parameters:
format - Output format. Can be null.
fileName - output file name.
Throws:
java.io.IOException
SoundException
javax.sound.sampled.UnsupportedAudioFileException

convertSound

public static byte[] convertSound(AudioBuffer buffer,
                                  javax.sound.sampled.AudioFormat targetFormat)
                           throws SoundException
SoundException

convertSound

public static byte[] convertSound(byte[] sound,
                                  javax.sound.sampled.AudioFormat sourceFormat,
                                  javax.sound.sampled.AudioFormat targetFormat)
                           throws SoundException
SoundException

convertSound

public static byte[] convertSound(byte[] sound,
                                  int offset,
                                  int length,
                                  javax.sound.sampled.AudioFormat sourceFormat,
                                  javax.sound.sampled.AudioFormat targetFormat)
                           throws SoundException
SoundException


Copyright © 2003 Pavel Vlasov. All Rights Reserved.