We can write ".wav" audio files by using the MATLAB command "wavwrite". The command format is
wavwrite(y, fs, nbits, waveFile);where "y" is the audio data, "fs" is the sample rate, "nbits" is the bit resolution, and "waveFile" is the .wav file to be written to. For instance, we can follow the next example to write my recording to a file "test.wav".
(You need to execute the above example in order to experience the recording and the file saving.) In this example, we store the audio data in the data type 'uint8' and write the data to the wave file "test.wav". We then invoke the corresponding application for ".wav" for the playback of the file. Since the variable "y" for the command "wavwrite" should be a double within the range [-1, 1], we need to do some conversion if the recorded data is in other data types, such as 'single', 'int16', or 'uint8'. Here is the table for conversion.
MATLAB can also write other audio files, such as '.au', which is the audio files used in NeXT/Sun workstations. The corresponding command is "auwrite". Please type "help auwrite" within the MATLAB command windows for more information on using this command.
Data types of "y" How to convert it to 'double' within [-1, 1] double No conversion needed single y = double(y); int16 y = double(y)/32768; uint8 y = (double(y)-128)/128;
Audio Signal Processing and Recognition (音訊處理與辨識)