从 wav 和 aiff 文件创建 mp3 预览

发布于 2024-08-27 12:23:42 字数 216 浏览 9 评论 0原文

我想创建一个程序来制作 aiff 或 wav 文件前 30 秒的 mp3。我还希望能够选择位置和长度,例如 2:12 到 2:42 之间的音频。有没有任何工具可以让我做到这一点?

脱壳就OK了。该应用程序将在 Linux 服务器上运行,因此它必须是一个可以在 Linux 上运行的工具。

我不介意分两步完成——即首先创建 aiff/wav 剪切图的工具,然后将其传递给 mp3 编码器。

I would like to create a program that makes mp3s of the first 30 seconds of an aiff or wav file. I would also like to be able to choose location and length, such as the audio between 2:12 and 2:42. Are there any tools that lets me do this?

Shelling out is OK. The application will run on a linux server, so it would have to be a tool that works on linux.

I don't mind doing it in two steps - i.e. a tool that first creates the cutout of the aiff/wav, then pass it to a mp3 encoder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

萌逼全场 2024-09-03 12:23:42

SoXtrim 谓词可以做到这一点。如果您的 sox 没有构建 MP3 支持,那么您必须在之后将输出通过管道传输到 lame,或者找到一个支持 MP3 的。

SoX with the trim predicate can do this. If your sox is not built with MP3 support then you'll have to pipe the output to lame after, or find one that is.

叫嚣ゝ 2024-09-03 12:23:42

我想使用尽可能低级别的东西,所以我最终使用了 RubyAudio libsndfile 的包装器。

require "rubygems"
require "ruby-audio"

EXTRACT_BEGIN = 11.2
EXTRACT_LENGTH = 3.5

RubyAudio::Sound.open("/home/augustl/sandbox/test.aif") do |snd|
  info = snd.info
  ["channels", "format", "frames", "samplerate", "sections", "seekable"].each do |key|
    puts "#{key}: #{info.send(key)}"
  end

  # TODO: should we use a 1000 byte buffer? Does it matter? See RubyAudio::Sound rdocs.
  bytes_to_read = (info.samplerate * EXTRACT_LENGTH).to_i
  buffer = RubyAudio::Buffer.new("float", bytes_to_read, info.channels)

  snd.seek(info.samplerate * EXTRACT_BEGIN)
  snd.read(buffer, bytes_to_read)

  out = RubyAudio::Sound.open("/home/augustl/sandbox/out.aif", "w", info.clone)
  out.write(buffer)
end

I wanted to use something as low level as possible, so I ended up using RubyAudio, a wrapper for libsndfile.

require "rubygems"
require "ruby-audio"

EXTRACT_BEGIN = 11.2
EXTRACT_LENGTH = 3.5

RubyAudio::Sound.open("/home/augustl/sandbox/test.aif") do |snd|
  info = snd.info
  ["channels", "format", "frames", "samplerate", "sections", "seekable"].each do |key|
    puts "#{key}: #{info.send(key)}"
  end

  # TODO: should we use a 1000 byte buffer? Does it matter? See RubyAudio::Sound rdocs.
  bytes_to_read = (info.samplerate * EXTRACT_LENGTH).to_i
  buffer = RubyAudio::Buffer.new("float", bytes_to_read, info.channels)

  snd.seek(info.samplerate * EXTRACT_BEGIN)
  snd.read(buffer, bytes_to_read)

  out = RubyAudio::Sound.open("/home/augustl/sandbox/out.aif", "w", info.clone)
  out.write(buffer)
end
四叶草在未来唯美盛开 2024-09-03 12:23:42

使用 LAME 作为 mp3 编码部分。使用 shntplit 分割文件。您需要将分割点放入提示文件中,但这很容易。

Use LAME for the mp3 encoding part. Use shntplit to split the file. You will need to put your split points in a cue file, but that is easy.

笑,眼淚并存 2024-09-03 12:23:42

在包含 *.wav 文件的目录中运行此 Bash 单行代码。

for wavfile in *.wav; do \
  sox "${wavfile}" "preview-${wavfile}" trim 0 60 fade 3 57 3; \
  lame --preset standard "preview-${wavfile}" \
    "preview-`basename ${wavfile} .wav`".mp3; \
  rm "preview-${wavfile}"; \
done

第一个 60 秒。 3 秒淡入和 3 秒淡出。原始 wav 文件保持不变。预览文件带有“preview-”前缀。您可以通过更改“trim 0 60”来选择位置和长度以满足您的需求。
需要:sox、lame

如果您有一个包含 mp3 文件的目录并且需要创建预览,请运行以下命令:

for mp3file in *.mp3; do \
  mpg123 -w "${mp3file}.wav" "${mp3file}"; \
  sox "${mp3file}.wav" "preview-${mp3file}.wav" trim 0 60 fade 3 57 3; \
  rm "${mp3file}.wav"; \
  lame --preset standard "preview-${mp3file}.wav" "preview-${mp3file}"; \
  rm -v "preview-${mp3file}.wav"; \
done

需要:mpg123、sox、lame

Run this Bash one-liner in a directory with *.wav files.

for wavfile in *.wav; do \
  sox "${wavfile}" "preview-${wavfile}" trim 0 60 fade 3 57 3; \
  lame --preset standard "preview-${wavfile}" \
    "preview-`basename ${wavfile} .wav`".mp3; \
  rm "preview-${wavfile}"; \
done

First 60 seconds. 3 seconds fade-in and 3 seconds fade-out. Original wav files stay untouched. Preview files come with a "preview-" prefix. You'll be able to choose location and length by changing "trim 0 60" to fit Your needs.
Requires: sox, lame

If You have a directory with mp3 files and need to create previews, run this:

for mp3file in *.mp3; do \
  mpg123 -w "${mp3file}.wav" "${mp3file}"; \
  sox "${mp3file}.wav" "preview-${mp3file}.wav" trim 0 60 fade 3 57 3; \
  rm "${mp3file}.wav"; \
  lame --preset standard "preview-${mp3file}.wav" "preview-${mp3file}"; \
  rm -v "preview-${mp3file}.wav"; \
done

Requires: mpg123, sox, lame

十秒萌定你 2024-09-03 12:23:42

我写了一个 python 库 pydub,这使得这变得微不足道,尽管它使用 ffmpeg 来进行转换以支持更多格式...

from pydub import AudioSegment

sound = AudioSegment.from_file("/input/file.aiff", format="aif")

# 2 min and 12 sec, them convert to milliseconds
start = (2*60 + 12) * 1000
end = start +  (30 * 1000)
snip = sound[start:end]

# add 3 second fade in and fade out
snip = snip.fadeIn(3000).fadeOut(3000)

# save as mp3
snip.export("/output/file.mp3", format="mp3")

I wrote a python library, pydub, that makes this trivial, though it uses ffmpeg in to do the conversions in order to support more formats…

from pydub import AudioSegment

sound = AudioSegment.from_file("/input/file.aiff", format="aif")

# 2 min and 12 sec, them convert to milliseconds
start = (2*60 + 12) * 1000
end = start +  (30 * 1000)
snip = sound[start:end]

# add 3 second fade in and fade out
snip = snip.fadeIn(3000).fadeOut(3000)

# save as mp3
snip.export("/output/file.mp3", format="mp3")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文