コード例 #1
0
        /// <summary>
        /// Encodes a signal from the specified file.
        /// </summary>
        ///
        /// <param name="fileName">File name to save the signal to.</param>
        /// <param name="signal">The audio signal that should be saved to disk.</param>
        ///
        public static void EncodeToFile(string fileName, Signal signal)
        {
            string fileExtension = FormatHandlerAttribute.GetNormalizedExtension(fileName);

            IAudioEncoder encoder = FormatEncoderAttribute.GetEncoder(fileExtension, encoderTypes, encoders.Value);

            if (encoder != null)
            {
                // open stream
                using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                {
                    // open decoder
                    encoder.Open(stream);

                    // write all audio frames
                    encoder.Encode(signal);

                    encoder.Close();
                }

                return;
            }

            throw new ArgumentException(String.Format("No suitable encoder has been found for the file format {0}. If ", fileExtension) +
                                        "you are trying to encode .wav files, please add a reference to Accord.Audio.DirectSound, and make sure you " +
                                        "are using at least one type from assembly in your code (to make sure the assembly is loaded).", "fileName");
        }
コード例 #2
0
 public void OnDestroy()
 {
     audioEncoder.Close();
 }