最近更新したページ
2013-10-20
2013-09-29
2013-09-23
2012-01-07
2011-11-09
2011-10-23
2011-10-09
2011-10-01
2011-09-29
2011-09-03
2011-08-07
2011-08-02
2011-07-29
2011-07-10
2011-05-05
2011-05-04
2011-04-24
2011-04-13
2011-04-05
2011-03-26
2011-02-18
2011-02-15
2010-12-26
2010-12-07
2010-12-05
2010-11-23
2010-09-28
2010-09-23
2010-08-26
2010-08-22
2010-07-16
2010-01-17
2010-01-11
2009-10-04
2009-08-21
2009-08-13
2009-06-18
2009-06-01
2009-04-29
2009-02-16
2009-02-11
2009-02-03
2008-07-22
2008-07-21
2008-07-15
2008-07-14
2008-07-13
2008-07-12
2008-07-08
2008-07-05
2008-06-28
2008-06-17
2008-06-05
2008-06-02
2008-06-01
2008-05-29
2008-05-26
2008-05-21
2008-05-19
2008-05-18
2007-10-31
2007-10-27
2007-09-28
2007-09-23
2007-09-17
2007-09-16
2007-09-14
2007-09-11
2007-06-18
2007-04-15
2006-12-21
2006-11-30
2006-11-22
2006-08-17
2006-03-29
2006-03-28
2006-03-27

SoX の使い方 :: 音源変換


SoX の概要


 SoX は linux に標準で入っている(らしい?) Cli(Command line interface) ベースの音源(音楽)再生・編集・変換・結合・・・ツール(Digital audio editor)である。

 公式サイト:http://sox.sourceforge.net/

 $ sox input.wav output.au

 で簡単にファイル変換されるが、細かい option を指定し使いこなすのは容易では無い。
 (音源ファイルの「うんちく」が必要)

 SoX は、Cross-platform で動き GPL で提供され au , wav , mp3(LAME encoder) , ogg , flac などに対応する。多機能だが、当 wiki ではファイル変換機能にのみ着目している。

 また、mid はサポート外と思われるが、---> TiMidity で解決する。


編集

変換方法


40M(wav) -> 完成サイズ 約2M(au)
 $ sox input.wav -b 8 -r 8000 -U -c 1 output.au     

 Sox で何とか 8bit 8000hz mn-law(u-law ってナニ?)へ苦労して変換した。40M の wav を option 指定で変換したら 2M 足らずに圧縮された。java で再生したところ音飛びしなかった。サイズが小さいので音飛び回避しただけとも思われるが・・・

40m(wav) -> 変換後 au 約4M wav 約4M
SoX で flac 変換でエラー -U option が問題みたい。約2M
 $ sox input.wav -b 8 -r 8000 -U -c 2 output.au
 $ sox input.wav -b 8 -r 8000 -U -c 2 output.wav

 約 4M となったが .au .wav 共に java で問題なく再生されました。エラーながら .flac にも変換されたが再生されず。flac はそもそも未対応


編集





SoX の使い方

(以下抜粋放置)

Sox 音源変換

 $ man sox
 〜
 SYNOPSIS
   sox [global-options] [format-options] infile1
                       [[format-options] infile2] ...
                        [format-options] outfile
                        [effect [effect-options]] ...
 〜
 要するに (wav->au を例として)
 $ sox "infile.wav" [out-option] "outfile.au" [effect [options]]
 こんな感じ?かも。

 man sox から Output File Format Options を調べるということになります。

 ・・・エラーで help が出た。

Usage summary: [gopts] [[fopts] infile]... [fopts] outfile [effect [effopts]]...

SPECIAL FILENAMES (infile, outfile):
  • Pipe/redirect input/output (stdin/stdout); may need -t
  • d, --default-device Use the default audio device (where available)
  • n, --null Use the `null' file handler; e.g. with synth effect
  • p, --sox-pipe Alias for `-t sox -'

SPECIAL FILENAMES (infile only):
"|program [options] ..." Pipe input from external program (where supported)
http://server/file Use the given URL as input file (where supported)

GLOBAL OPTIONS (gopts) (can be specified at any point before the first effect):
    • buffer BYTES Set the size of all processing buffers (default 8192)
    • clobber Don't prompt to overwrite output file (default)
    • combine concatenate Concatenate multiple input files (default for sox, rec)
    • combine sequence Sequence multiple input files (default for play)
  • D, --no-dither Don't dither automatically
    • effects-file FILENAME File containing effects and options
  • G, --guard Use temporary files to guard against clipping
  • h, --help Display version number and usage information
    • help-effect NAME Show usage of effect NAME, or NAME=all for all
    • help-format NAME Show info on format NAME, or NAME=all for all
    • i, --info Behave as soxi(1)
    • input-buffer BYTES Override the input buffer size (default: as --buffer)
    • no-clobber Prompt to overwrite output file
  • m, --combine mix Mix multiple input files (instead of concatenating)
  • M, --combine merge Merge multiple input files (instead of concatenating)
    • magic Use `magic' file-type detection
    • norm Guard (see --guard) & normalise
    • play-rate-arg ARG Default `rate' argument for auto-resample with `play'
    • plot gnuplot|octave Generate script to plot response of filter effect
  • q, --no-show-progress Run in quiet mode; opposite of -S
    • replay-gain track|album|off Default: off (sox, rec), track (play)
  • R Use default random numbers (same on each run of SoX)
  • S, --show-progress Display progress while processing audio data
    • single-threaded Disable parallel effects channels processing
    • temp DIRECTORY Specify the directory to use for temporary files
    • version Display version number of SoX and exit
  • V[LEVEL] Increment or set verbosity level (default 2); levels:
1: failure messages 2: warnings 3: details of processing 4-6: increasing levels of debug messages
FORMAT OPTIONS (fopts):
Input file format options need only be supplied for files that are headerless.
Output files will have the same format as the input file where possible and not
overriden by any of various means including providing output format options.

  • v|--volume FACTOR Input file volume adjustment factor (real number)
    • ignore-length Ignore input file length given in header; read to EOF
  • t|--type FILETYPE File type of audio
  • s/-u/-f/-U/-A/-i/-a/-g Encoding type=signed-integer/unsigned-integer/floating-
point/mu-law/a-law/ima-adpcm/ms-adpcm/gsm-full-rate
  • e|--encoding ENCODING Set encoding (ENCODING in above list)
  • b|--bits BITS Encoded sample size in bits
  • 1/-2/-3/-4/-8 Encoded sample size in bytes
  • N|--reverse-nibbles Encoded nibble-order
  • X|--reverse-bits Encoded bit-order
    • endian little|big|swap Encoded byte-order; swap means opposite to default
  • L/-B/-x Short options for the above
  • c|--channels CHANNELS Number of channels of audio data; e.g. 2 = stereo
  • r|--rate RATE Sample rate of audio
  • C|--compression FACTOR Compression factor for output format
    • add-comment TEXT Append output file comment
    • comment TEXT Specify comment text for the output file
    • comment-file FILENAME File containing comment text for the output file
    • no-glob Don't `glob' wildcard match the following filename

AUDIO FILE FORMATS: 8svx aif aifc aiff aiffc al amb au avi avr caf cdda cdr cvs cvsd cvu dat dvms f32 f4 f64 f8 fap ffmpeg flac fssd gsm hcom htk ima ircam la lpc lpc10 lu m4a mat mat4 mat5 maud mp2 mp3 mp4 mpg nist ogg paf prc pvf raw s1 s16 s2 s24 s3 s32 s4 s8 sb sd2 sds sf sl smp snd sndfile sndr sndt sou sox sph sw txw u1 u16 u2 u24 u3 u32 u4 u8 ub ul uw vms voc vorbis vox w64 wav wavpcm wmv wv wve xa xi
PLAYLIST FORMATS: m3u pls
AUDIO DEVICE DRIVERS: alsa ao oss ossdsp pulseaudio

EFFECTS: allpass band bandpass bandreject bass bend biquad chorus channels compand contrast crop+ dcshift deemph delay dither divide+ earwax echo echos equalizer fade filter* fir firfit+ flanger gain highpass input# key* ladspa loudness lowpass mcompand mixer noiseprof noisered norm oops output# overdrive pad pan* phaser pitch polyphase* rabbit* rate remix repeat resample* reverb reverse riaa silence sinc spectrogram speed splice stat stats stretch swap synth tempo treble tremolo trim vad vol
* Deprecated effect + Experimental effect # LibSoX-only effect
EFFECT OPTIONS (effopts): effect dependent; see --help-effect


編集

SoX man 抜粋

http://sox.sourceforge.net/sox.html
http://sox.sourceforge.net/sox.pdf

-b option

 sox infile -b 8 outfile
8bit にする場合?

-u option

−s/−u/−f/−A/−U/−o/−i/−a/−g
Deprecated aliases for specifying the encoding types signed-integer, unsigned-integer, floatingpoint,
mu-law, a-law, oki-adpcm, ima-adpcm, ms-adpcm, gsm-full-rate respectively (see −e above).

-r option

−r, −−rate RATE[k]
Gives the sample rate in Hz (or kHz if appended with ‘k’) of the file.
For an input file, the most common use for this option is to inform SoX of the sample rate of a
‘raw’ (‘headerless’) audio file (see the examples in −b and −c above). Occasionally it may be useful
to use this option with a ‘headered’ file, in order to override the (presumably incorrect) value in
the header―note that this is only supported with certain file types. For example, if audio was
recorded with a sample-rate of say 48k from a source that played back a little, say 1.5%, too
slowly, then
sox −r 48720 input.wav output.wav
effectively corrects the speed by changing only the file header (but see also the speed effect for the
more usual solution to this problem).
For an output file, this option provides a shorthand for specifying that the rate effect should be
invoked in order to change (if necessary) the sample rate of the audio signal to the given value.
For example, the following two commands are equivalent:
sox input.wav −r 48k output.wav bass −3
sox input.wav output.wav bass −3 rate 48k
though the second form is more flexible as it allows rate options to be given, and allows the
effects to be ordered arbitrarily.

 sox infile -r 8000 outfile  // 8000Hz

−e ENCODING

sox ・・・ -e float / signed ・・・


u-law, mu-law
North American telephony standard for logarithmic encoding to 8 bits per sample. A.k.a.
m-law. It has a precision equivalent to roughly 14-bit PCM and is sometimes encoded
with reversed bit-ordering (see the −X option).

  • man 抜粋
Note however, that on the SoX command line, the positions of the Output(s) and the Effects are swapped
w.r.t. the logical flow just shown. Note also that whilst options pertaining to files are placed before their
respective file name, the opposite is true for effects. To show how this works in practice, here is a selection
of examples of how SoX might be used. The simple
sox recital.au recital.wav
translates an audio file in Sun AU format to a Microsoft WAV file, whilst
sox recital.au −b 16 recital.wav channels 1 rate 16k fade 3 norm
performs the same format translation, but also applies four effects (down-mix to one channel, sample rate
change, fade-in, nomalize), and stores the result at a bit-depth of 16.
sox −r 16k −e signed −b 8 −c 1 voice-memo.raw voice-memo.wav
converts ‘raw’ (a.k.a. ‘headerless’) audio to a self-describing file format,
sox slow.aiff fixed.aiff speed 1.027
adjusts audio speed,
sox short.wav long.wav longer.wav
concatenates two audio files, and
sox −m music.mp3 voice.wav mixed.flac
mixes together two audio files.
play "The Moonbeams/Greatest/*.ogg" bass +3
plays a collection of audio files whilst applying a bass boosting effect,
play −n −c1 synth sin %−12 sin %−9 sin %−5 sin %−2 fade h 0.1 1 0.1
plays a synthesised ‘A minor seventh’ chord with a pipe-organ sound,
rec −c 2 radio.aiff trim 0 30:00
sox February19, 2011 1
SoX(1) SoundeXchange SoX(1)
records half an hour of stereo audio, and
play −q take1.aiff & rec −M take1.aiff take1-dub.aiff
(with POSIX shell and where supported by hardware) records a new track in a multi-track recording.
Finally,
rec −r 44100 −b 16 −s −p silence 1 0.50 0.1% 1 10:00 0.1% | \
sox −p song.ogg silence 1 0.50 0.1% 1 2.0 0.1% : \
newfile : restart
records a stream of audio such as LP/cassette and splits in to multiple audio files at points with 2 seconds of
silence. Also, it does not start recording until it detects audio is playing and stops after it sees 10 minutes
of silence.
N.B. The above is just an overview of SoX’s capabilities; detailed explanations of how to use all SoX
parameters, file formats, and effects can be found below in this manual, in soxformat(7), and in soxi(1).


関連ページ




▲上へ [ 編集 ]
2011年04月05日(火) 09:23:30 Modified by sakura_momo2




スマートフォン版で見る