# $$\text{SaveAudio}$$¶

You can use the $$\text{SaveAudio}$$ function to save audio content to an audio file. Note that this function is included as part of the audiofile plug-in and requires the supplied libaudiofile library to operate.

You can use the \saveaudio backslash command to insert this function.

The following variants of this function are available:

• $$\text{boolean } \text{SaveAudio} \left ( \text{<filename>}, \text{<audio data>} \right )$$

• $$\text{boolean } \text{SaveAudio} \left ( \text{<filename>}, \text{<encoding>}, \text{<audio data>} \right )$$

• $$\text{boolean } \text{SaveAudio} \left ( \text{<filename>}, \text{<sample rate>}, \text{<c0 sample data>}, \ldots \right )$$

• $$\text{boolean } \text{SaveAudio} \left ( \text{<filename>}, \text{<encoding>}, \text{<sample rate>}, \text{<c0 sample data>}, \ldots \right )$$

The $$\text{SaveAudio}$$ function currently supports the following formats:

• MPEG 1/2 Audio Layer III

• Microsoft WAV format

• Multiple raw audio formats

The $$\text{<filename>}$$ parameter should be a text string holding the name of the audio file to be saved.

The $$\text{<encoding>}$$ parameter is used to specify a raw encoding format and any of the keywords listed in Table 38 and Table 39. The $$\text{SaveAudio}$$ function will attempt to guess the encoding from the extension on the filename if no encoding is explicitly specified.

The $$\text{<audio data>}$$ parameter is a tuple containing the sample rate followed by one or more channels of audio data. This parameter is useful when you wish to simply save off audio read using the $$\text{LoadAudio}$$.

The $$\text{<sample rate>}$$ parameter is a scalar value holding the sample rate, in Hertz.

The $$\text{<co sample data>}, \ldots$$ parameters represent the audio sample data stored in either integer or real matrices. The $$\text{SaveAudio}$$ function will rescale and convert the data to an appropriate format prior to saving.

The $$\text{SaveAudio}$$ function returns a boolean value indicating true on success or false on error.

Figure 200 shows the basic use of the $$\text{SaveAudio}$$ function.

Figure 200 Example Use Of The SaveoAudio Function