修剪SoX中的输入以避免生成中间文件

huangapple go评论80阅读模式
英文:

Trim inputs in SoX to avoid making intermediate files

问题

I'm trying to write a single SoX command to concatenate 2 files while avoiding making intermediate files.

我的目标是编写一个SoX命令,将两个文件连接起来,同时避免生成中间文件。

My 2 input files are both 1 second long.

我的两个输入文件都是1秒长。

I want to concatenate the first 0.5 seconds of input1.aif with all of input2.aif then pad with 1s silence at the end.

我想将input1.aif的前0.5秒与input2.aif的全部连接起来,然后在末尾填充1秒的静音。

The correct syntax for your required behavior is:

你所需的正确语法是:

$ sox input1.aif -p trim 0 0.5 | sox -p input2.aif output.aif pad 0 1

This command will trim the first 0.5 seconds from input1.aif, concatenate it with input2.aif, and then pad the output with 1 second of silence, all without creating intermediate files.

这个命令将从input1.aif中裁剪出前0.5秒,将其与input2.aif连接起来,然后在输出中填充1秒的静音,所有操作都不会创建中间文件。

英文:

I'm trying to write a single SoX command to concatenate 2 files while avoiding making intermediate files.

My 2 input files are both 1 second long.

I want to concatenate the first 0.5 seconds of input1.aif with all of input2.aif then pad with 1s silence at the end.

I can't work out the order of options and/or chaining methods. Can't find in docs either. What I've tried so far:

$ sox input1.aif input2.aif output.aif
> input1 then input2, as expected

$ sox input1.aif input2.aif output.aif pad 0 1
> input1 then input2 then 1s silence, as expected

$ sox input1.aif input2.aif output.aif trim 0 0.5 pad 0 1
> 0.5s of input1 (as desired) but none of input2 then 1s silence

$ sox input1.aif input2.aif output.aif trim 0 0.5 trim 0 1 pad 0 1
> "sox WARN trim: End position is after expected end of audio."
> "sox WARN trim: Last 1 position(s) not reached."

$ sox input1.aif input2.aif output.aif trim 0 0.5 : trim 0 1 pad 0 1
> input 1 then input2 then 1s silence

$ sox input1.aif input2.aif output.aif trim 0 0.5 : trim 0 0.5 pad 0 1
> input 1, none of input2 then 1s silence

$ sox input1.aif input2.aif output.aif trim 0 0.5 : trim 0 1 : pad 0 1
> input 1 then input2 then 1s silence

$ sox input1.aif trim 0 0.5 : input2.aif output.aif pad 0 1           
> sox FAIL sox: Not enough input filenames specified

What is the correct syntax for my required behavior?

答案1

得分: 1

使用管道选项 (-p) 来修剪第一个输入,然后将其传递给第二个命令来进行后续处理。

$ sox input1.aif -p trim 0 0.5 | sox - input2.aif output.aif pad 0 1

这会取第一个输入并将其修剪为前0.5秒,然后将其作为第一个参数 (-) 传递给第二个命令,并与第二个输入连接起来,最后用1秒的静音填充结果。

可能还有其他方法来实现这个目标,但对于我的需求来说,这已经足够简单了。

英文:

Found an answer.

Use the pipe option (-p) to trim the first input then pipe it to the second command for the rest of the process.

$ sox input1.aif -p trim 0 0.5 | sox - input2.aif output.aif pad 0 1

The takes the first input and trims it to the first 0.5 seconds, then pipes it to the second command as the first argument (-) and concatenates it with the second input, then finally padding the result with 1 second of silence.

There may be other ways to do this without piping but this is simple enough for my needs.

huangapple
  • 本文由 发表于 2023年6月12日 06:27:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452755.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定