Represents a digitized acoustic signal (a Praat Sound object).
Details
A Sound holds one or more channels of audio sampled at regular intervals. It is the starting point for most acoustic analyses in pladdrr: pitch, formants, intensity, and spectral measures all begin from a Sound.
File I/O
The constructor tries two readers in order:
The native Praat reader, which handles WAV, AIFF, AIFC, NIST, and NeXT/Sun files without extra packages, and is the fastest path.
The
avpackage, used as a fallback for everything else, including FLAC, MP3, and OGG Vorbis. The FLAC and MP3 decoder sources were dropped from the vendored Praat tree in v4.9.5 to keep the CRAN tarball within limits, so those formats needavinstalled (install.packages("av")). Without it, reading a FLAC or MP3 file raises an error naming the missing package.
Convert to WAV up front if you want to avoid the av dependency
entirely.
Usage
# From file
sound <- Sound(path = "audio.wav")
# From numeric data
sound <- Sound$from_values(values, sampling_rate = 44100)
# Synthetic tone
sound <- Sound$create_tone(frequency = 440, duration = 1.0)Query methods
get_duration()- duration in secondsget_sampling_frequency()- sampling rate in Hzget_number_of_samples()- number of samplesget_number_of_channels()- number of channelsget_value_at_time()- amplitude at a given timeget_rms(),get_energy(),get_power()- energy measuresget_intensity_db()- intensity in dBget_minimum(),get_maximum(),get_mean()- amplitude statisticsget_values(channel)- sample values as a numeric vectorget_sample_times()- sample times as a numeric vector
Analysis methods
to_pitch()- extract pitch contour (F0)to_formant_burg()- extract formants (F1, F2, F3, ...)to_intensity()- extract intensity contourto_harmonicity_cc()- harmonics-to-noise ratioto_harmonicity_gne()- glottal-to-noise excitation ratio (GNE)extract_electroglottogram(channel, invert)- extract an electroglottogram (EGG) from a channelto_spectrum()- frequency spectrumto_spectrogram()- time-frequency representationto_ltas()- long-term average spectrumto_ltas_pitch_corrected()- pitch-corrected LTAS (voice quality)to_formant_robust()- outlier-resistant formant trackingto_mel_spectrogram()- mel-scale spectrogramto_bark_spectrogram()- Bark-scale spectrogramto_point_process_periodic_cc()- extract glottal pulses
Signal processing
lengthen()- time-stretch using overlap-addautocorrelate()- autocorrelation functionconvolve()- convolve with another soundcross_correlate()- cross-correlate with another sounddeepen_band_modulation()- hearing enhancementfilter_by_formant()- filter with a Formant objectfilter_by_formant_noscale()- filter without scaling
Extraction
extract_channel()- extract a single channelextract_part(from, to, window_shape, relative_width, preserve_times)- extract a time range, with optional windowing. Supports 12 window shapes (rectangular, triangular, parabolic, hanning, hamming, gaussian1-5, kaiser1-2); see https://www.fon.hum.uva.nl/praat/manual/Sound__Extract_part___.html.
Modification
scale_intensity()- scale to a target dB level (in place)scale_peak()- scale peak amplitude (in place)pre_emphasize()- high-pass filter (in place)de_emphasize()- low-pass filter (in place)resample()- resample to a different rate (returns a new object)convert_to_mono()- average channels to mono (returns a new object)concatenate()- append another sound (returns a new object)mix()- mix with another sound (returns a new object)
Export
as_matrix()- export as a numeric matrixas_data_frame()- export as a data.framesave()- save to an audio file
Examples
# Synthetic tone, no external file needed
sound <- Sound$create_tone(frequency = 440, duration = 1.0)
pitch <- sound$to_pitch()
formants <- sound$to_formant_burg()
cat("Duration:", sound$get_duration(), "s\n")
#> Duration: 1 s
cat("Sample rate:", sound$get_sampling_frequency(), "Hz\n")
#> Sample rate: 44100 Hz
part <- sound$extract_part(0.2, 0.5)