如何在R中连接两个.wav文件?

时间:2011-06-04 15:05:38

标签: r file

如何在R中连接两个.wav文件? 我已经检查了声音和音频包,但我仍然不知道该怎么做。

1 个答案:

答案 0 :(得分:9)

您是否在appendSample(s1, s2, ...)包裹(CRAN)中使用saveSample(s, filename, overwrite)尝试了sound

<强> appendSample:

Description:
    Append two or more Sample objects or wav files.
Usage:
    appendSample(s1, s2, ...)
Arguments:
    s1, s2, ... Sample objects, or the names of wav files.
Details:
    If the samples have different sample parameters (bits, rate and channels),
    the command fitSampleParameters is called to adjust them before the sample
    are appended.
Value:
    a Sample object with the samples played one after the other.

<强> saveSample:

Description:
    Save a Sample object to disk as a wav file.
Usage:
    saveSample(s, filename, overwrite=FALSE)
Arguments:
    s           a Sample object.
    filename    a string giving the path and the name of the destination file.
    overwrite   logical. If FALSE and filename already exists, an error
                will be reported. Otherwise the old file will be deleted.

示例命令:

> sample = appendSample('/home/grzegorz/file1.wav', '/home/grzegorz/file2.wav')
> saveSample(sample, '/home/grzegorz/output.wav', overwrite=FALSE)

我下载了两个sample wav文件,但它可以正常运行(wavs连接在一起)。当然你需要安装声音库才能做到这一点。