sox はオーディオ操作のスイス アーミー ナイフで、同名のパッケージに収められています。インストールしたら、man ページを見てみましょう。ここでは、オーディオ ファイルを再生できるだけでなく、操作もできることが明らかにされています。コード行は次のとおりです:
SoX reads and writes audio files in most popular formats and can optionally apply effects to them. It can combine multiple input sources, synthesise audio, and, on many systems, act as a general purpose audio player or a multi-track audio recorder. It also has limited ability to split the input into multiple output files. All SoX functionality is available using just the sox command. To simplify playing and recording audio, if SoX is invoked as play, the output file is automatically set to be the default sound device, and if invoked as rec, the default sound device is used as an input source. Additionally, the soxi(1) command provides a convenient way to just query audio file header information. The heart of SoX is a library called libSoX. Those interested in extending SoX or using it in other programs should refer to the libSoX manual page: libsox(3). SoX is a command-line audio processing tool, particularly suited to making quick, simple edits and to batch processing. If you need an interactive, graphical audio editor, use audacity(1).
前の説明でわかるように、sox と soxi は、オーディオ ファイルの操作においてさまざまな用途に使用できます。
これらのコマンド ラインを使用するだけで、サポートされているオーディオ ファイル形式を再生できます。
# sox tone-sine-1000hz.wav -t alsa hw:2 tone-sine-1000hz.wav: File Size: 1.76M Bit Rate: 1.41M Encoding: Signed PCM Channels: 2 @ 16-bit Samplerate: 44100Hz Replaygain: off Duration: 00:00:10.00 In:78.9% 00:00:07.89 [00:00:02.11] Out:348k [====|====] Hd:2.4 Clip:0
関連するファイルに拡張子がまったくない場合は、次のように -t オプション引数を使用して音声ファイルを強制できます:
# sox tone-sine-1000hz.wav -t au tone-sine -1000hz # file tone-sine-1000hz tone-sine-1000hz: Sun/NeXT audio data: 16-bit linear PCM, stereo, 44100 Hz
soxi コマンドの実行中に以下のエラーが発生した場合:
soxi: command not found
選択したディストリビューションに従って、以下のパッケージをインストールしてみてください。
分布 | コマンド |
---|---|
OS X | brew install sox |
Debian | apt-get install sox |
Ubuntu | apt-get install sox |
アルパイン | apk add sox |
Arch Linux | パックマン -S ソックス |
カリ Linux | apt-get install sox |
CentOS | yum install sox |
Fedora | dnf インストール sox |
Raspbian | apt-get install sox |
sox コマンドの例
1. 2 つの音声ファイルを 1 つに結合:
$ sox -m input_audiofile1 input_audiofile2 output_audiofile
2. オーディオ ファイルを指定された時間にトリミングします。
$ sox input_audiofile output_audiofile trim start end
3. オーディオ ファイルを正規化します (クリッピングなしで音量を最大ピーク レベルに調整します):
$ sox --norm input_audiofile output_audiofile
4. オーディオ ファイルをリバースして保存する:
$ sox input_audiofile output_audiofile reverse
5. 音声ファイルの統計データを印刷:
$ sox input_audiofile -n stat
6. オーディオ ファイルの音量を 2 倍にします:
$ sox -v 2.0 input_audiofile output_audiofilesoxi:コマンドが見つかりません