audio_convert: Convert an Audio File

View source: R/convert.R

audio_convertR Documentation

Convert an Audio File

Description

Re-encode an audio (or A/V) file's audio to a new container, sample rate, channel count, or codec via ffmpeg. The output format is inferred from the output extension. With no optional arguments it is a straight transcode.

Usage

audio_convert(input, output, sample_rate = NULL, channels = NULL,
              bitrate = NULL, codec = NULL, overwrite = TRUE, dry_run = FALSE)

Arguments

input

Path to input audio (or A/V) file.

output

Path for output file; extension selects the format.

sample_rate

Output sample rate in Hz, or NULL to keep the source rate.

channels

Output channel count (1 = mono, 2 = stereo), or NULL to keep.

bitrate

Output audio bitrate (e.g. "192k"), or NULL for the encoder default. Ignored by lossless formats such as WAV.

codec

Explicit audio codec (e.g. "libmp3lame", "pcm_s16le"), or NULL to let ffmpeg pick from the output extension.

overwrite

If TRUE (default), overwrite the output file.

dry_run

If TRUE, return the ffmpeg command without executing.

Details

Resampling to 16 kHz mono is the usual preparation for speech-to-text: audio_convert("audio.mp3", "audio.wav", sample_rate = 16000).

Value

Invisibly returns the output path. If dry_run, returns the command string.

Examples

## Not run: 
audio_convert("audio.mp3", "speech.wav", sample_rate = 16000)
audio_convert("take.wav", "take.mp3", bitrate = "192k")

## End(Not run)


compost documentation built on Aug. 4, 2026, 5:11 p.m.