sphオーディオを他の形式に変換し、soxツールと組み合わせて適切なwavオーディオに変換します-省略形



Convert Sph Audio Other Formats



SPHERE変換ツール:sphオーディオファイルを他の形式に変換するためのプログラム

ツールダウンロードリンク

  • ツールの紹介:
    sph2pipe缶:



  • UNIXシステムで実行します(UNIXを介してMacOSXでも動作するはずです)
    「ターミナル」ユーティリティを使用したシェル/コマンドラインインターフェイス)

  • SPHERE形式の出力だけでなく、RIFF、AU、AIFF、およびrawを提供します



  • に格納されているSPHEREヘッダーを使用して、生のサンプルデータを入力として処理します。
    別のファイル。

  • 入力データの最初または最後、あるいはその両方をトリミングして、
    時間またはサンプルオフセットのいずれかに基づくユーザー指定のセグメント
    (sph_convertは常にファイル全体を出力します)

  • 名前付きファイルにリダイレクトするために、出力データをstdoutに書き込みます。
    またはパイプラインプロセスに(sph_convertは常にデータを
    入力ファイルから自動的に派生した名前の新しいファイル)



  • A-law音声データの入力と出力をサポートします

Hello my friends !
  1. インストール:

対応するソースコードをダウンロードして解凍すると、3つの* .cファイルと3つの* .hがあります。
ファイル、実行可能ファイルをコンパイルおよび生成します sph2pipe そして、実行可能ファイルを追加します
コンパイルには標準のgcc環境が必要です。元のテキストは次のとおりです。すべてreadmeファイルからのものです。

-- then: cd sph2pipe_v2.4 gcc -o sph2pipe *.c -lm ## on unix or gcc -o sph2pipe.exe *.c -lm ## on wintel, using the djgpp compiler That's it -- no configuration scripts, makefiles or special libraries are needed (the source code consists of just 3 *.c files, and 3 *.h files the standard math library is needed for compilation). Put the resulting 'sph2pipe' executable in your path and start using it. If you don't have gcc, try whatever C compiler you do have you might need to change a few details in sph_convert.h, but we hope the code is generic enough (POSIX compliant) to work anywhere.
  1. 生成される実行可能ファイル sph2pipe コマンドをどこでも使用できるように、現在のユーザーの環境変数を追加します。
vim .bashrc Add a path to: export PATH=/home/zql/soft/pythonsoft/sph2pipe_v2.5:$PATH Then the source command makes the command take effect immediately source .bashrc
  1. 入力 sph2pipe コマンド表示コマンドの形式は次のとおりです。
sph2pipe Usage: sph2pipe [-h hdr] [-t|-s b:e] [-c 1|2] [-p|-u|-a] [-f typ] infile [outfile] default conditions (for 'sph2pipe infile'): * input file contains sphere header * output full duration of input file * output all channels from input file * output same sample coding as input file * output format is WAV on Wintel machines, SPH elsewhere * output is written to stdout optional controls (items bracketed separately above can be combined): -h hdr -- treat infile as headerless, get sphere info from file 'hdr' -t b:e -- output portion between b and e sec (floating point) -s b:e -- output portion between b and e samples (integer) -c 1 -- only output first channel -c 2 -- only output second channel -p -- force conversion to 16-bit linear pcm -u -- force conversion to 8-bit ulaw -a -- force conversion to 8-bit alaw -f typ -- select alternate output header format 'typ' five types: sph, raw, au, rif(wav), aif(mac)

私が使用するコマンドは次のように要約されます(上記のコマンド形式の場合、自分で組み合わせることができます。次のコマンドは私のデータのバッチに適用されます)。

  • 出力サフィックスwavにもかかわらず、直接変換は失敗しましたが、次の理由により、その出力はデフォルトでsphのままです。
  • 出力形式は、WintelマシンではWAV、その他の場所ではSPHです。
sph2pipe test.sph 1.wav Then use the sox tool to view the wav header information and find that sox does not support the sph of the alaw encoding format. soxi 1.wav soxi FAIL formats: can't open input file `1.wav': sph: unsupported coding `alaw'
  • -f typ –代替出力ヘッダー形式「typ」を選択します
    5つのタイプ:sph、raw、au、rif(wav)、aif(mac)
sph2pipe -f rif test.sph 2.wav soxi 2.wav Input File : '2.wav' Channels : 2 Sample Rate : 8000 Precision : 13-bit Duration : 00:09:59.48 = 4795872 samples ~ 44961.3 CDDA sectors File Size : 9.59M Bit Rate : 128k Sample Encoding: 8-bit A-law
  • -p –16ビット線形pcmへの強制変換
sph2pipe -p -f rif test.sph 3.wav soxi 3.wav Input File : '3.wav' Channels : 2 Sample Rate : 8000 Precision : 16-bit Duration : 00:09:59.48 = 4795872 samples ~ 44961.3 CDDA sectors File Size : 19.2M Bit Rate : 256k Sample Encoding: 16-bit Signed Integer PCM
  • -c 1 –最初のチャネルのみを出力します
  • -c 2 –2番目のチャネルのみを出力します
The specified channel of sph2pipe outputs only the sound of the first channel, so the wav in this way is not what I want. sph2pipe -c 1 -f rif test.sph c1.wav sph2pipe -c 2 -f rif test.sph c2.wav sph2pipe -c 1 -p -f rif test.sph c1_16k.wav sph2pipe -c 2 -p -f rif test.sph c2_16k.wav

必要なオーディオ形式は次のとおりです。 シングルチャンネル16k / 8k16 / 8ビット

  1. したがって、sph2pipeは最初に16ビットのデュアルチャネルwavに変換されます。これは、デフォルトでA-law圧縮形式になり、量子化の精度は要件を満たしていません。デフォルトのサンプリングレートは8kです
  2. 次に、wavツールを使用して、単一チャネルの8kWavまたは単一チャネルの16kWavに変換します。 3つのコマンドは次のとおりです。
sph2pipe -p -f rif test.sph 3.wav sox 3.wav -c 1 3-1.wav sox 3.wav -r 16000 -c 1 3-1_16k.wav

バッチ変換オーディオトラバーサルスクリプトは次のとおりです。

最初の一歩: sph2pipe sphオーディオをに変換する デュアルチャネル8k16ビット PCM形式のWav

# # Run example: ./c1_16bit_16k.sh /home/zql/project/data/myTestdata/test1 /home/zql/project/data/myTestdata/test2 # #!/bin/bash sph(){ echo 'first arg is $1' echo 'second arg is $2' for file in $1/*.sph do echo $file filename=$(basename $file .sph) #echo ${filename} sph2pipe -p -f rif $file $2/${filename}.wav done } sph $1 $2

ステップ2:デュアルチャネル8k16ビット変換 シングルチャンネル8k16ビット

# # cmd example: ./sox_channel_1.sh /home/zql/project/data/myTestdata/c2_16bit_8k /home/zql/project/data/myTestdata/c1_16bit_8k # #!/bin/bash sox_precision(){ echo 'first arg is $1' echo 'second arg is $2' for file in $1/*.wav do echo $file filename=${file##*/} echo $filename sox $file -c 1 $2/$filename done } sox_precision $1 $2

ステップ3:デュアルチャネル8k16ビット変換 シングルチャネル16k16ビット

# # cmd example: ./sox_channel_1_16k.sh /home/data/myTestdata/c2_16bit_8k /home/data/myTestdata/c1_16bit_16k # #!/bin/bash sox_precision(){ echo 'first arg is $1' echo 'second arg is $2' for file in $1/*.wav do echo $file filename=${file##*/} echo $filename sox $file -r 16000 -c 1 $2/$filename done } sox_precision $1 $2

ソックスツールリンク

ソックス公式ウェブサイト
ソックスの使い方をまとめました
soxがsphをwavに変換できるかどうかを確認したいのですが、オーディオでsoxコマンドを使用して以下のエラーを報告しています。このaal圧縮のオーディオエンコーディングはサポートしていません。たぶん、このデータは違法です。圧縮形式のオーディオなので、適切ではありません

sox test.sph 1.wav sox FAIL formats: can't open input file `test.sph': sph: unsupported coding `alaw'