/// Encdoes the waveform into a WAV-encoded byte array.
Encdoes the waveform into a WAV-encoded byte array.
Encdoes the waveform into a WAV - encoded byte array .
pub fn to_wav_buffer(&self) -> Result<Vec<u8>, Error> {
        let writer_spec = hound::WavSpec {
            channels: self.num_channels as u16,
            sample_rate: self.frame_rate_hz as u32,
            bits_per_sample: 32,
            sample_format: hound::SampleFormat::Float,
        };
        let mut cursor = std::io::Cursor::new(Vec::new());
        let mut writer = match hound::WavWriter::new(&mut cursor, writer_spec) {
            Ok(w) => w,
            Err(_) => return Err(Error::UnknownEncodeError),
        };
        for sample in &self.interleaved_samples {
            let sample_result = writer.write_sample(*sample);
            if sample_result.is_err() {
                return Err(Error::UnknownEncodeError);
            }
        }
        let finalize_result = writer.finalize();
        if finalize_result.is_err() {
            return Err(Error::UnknownEncodeError);
        }
        Ok(cursor.into_inner())
    }
pub fn to_wav_buffer ( & self ) -> Result < Vec < u8 > , Error > { let writer_spec = hound :: WavSpec { channels : self . num_channels as u16 , sample_rate : self . frame_rate_hz as u32 , bits_per_sample : 32 , sample_format : hound :: SampleFormat :: Float , } ; let mut cursor = std :: io :: Cursor :: new ( Vec :: new ( ) ) ; let mut writer = match hound :: WavWriter :: new ( & mut cursor , writer_spec ) { Ok ( w ) => w , Err ( _ ) => return Err ( Error :: UnknownEncodeError ) , } ; for sample in & self . interleaved_samples { let sample_result = writer . write_sample ( * sample ) ; if sample_result . is_err ( ) { return Err ( Error :: UnknownEncodeError ) ; } } let finalize_result = writer . finalize ( ) ; if finalize_result . is_err ( ) { return Err ( Error :: UnknownEncodeError ) ; } Ok ( cursor . into_inner ( ) ) }
Encdoes the waveform into a WAV-encoded byte array.
Encdoes the waveform into a WAV - encoded byte array .
&self