質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

3083閲覧

pythonでsoxを利用したいのですがsoxを認識してくれない

primer57

総合スコア2

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/12/29 07:24

編集2021/12/29 12:19

###pythonのプログラムでsoxを利用したい

vscodeで音声認識をしたくその過程でsoxを利用したいのですが下記のようなエラーメッセージ出たので解決方法を知りたいです

発生している問題・エラーメッセージ

python

1'sox' is not recognized as an internal or external command, 2operable program or batch file. 3SoX could not be found! 4 5 If you do not have SoX, proceed here: 6 - - - http://sox.sourceforge.net/ - - - 7 8 If you do (or think that you should) have SoX, double-check your 9 path variables. 10 11../data/original/jsut_ver1.1/basic5000/wav\BASIC5000_0001.wav 12This install of SoX cannot process .wav files. 13This install of SoX cannot process .wav files. 14Traceback (most recent call last): 15 File ".\01prepare_wav.py", line 54, in <module> 16 tfm.build_file(input_filepath=wav_path_in, 17 File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\sox\transform.py", line 710, in build_file 18 return self.build( 19 File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\sox\transform.py", line 593, in build 20 input_format, input_filepath = self._parse_inputs( 21 File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\sox\transform.py", line 496, in _parse_inputs 22 input_format['channels'] = file_info.channels(input_filepath) 23 File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\sox\file_info.py", line 82, in channels 24 output = soxi(input_filepath, 'c') 25 File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\sox\core.py", line 147, in soxi 26 shell_output = subprocess.check_output( 27 File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 411, in check_output 28 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, 29 File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 489, in run 30 with Popen(*popenargs, **kwargs) as process: 31 File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__ 32 self._execute_child(args, executable, preexec_fn, close_fds, 33 File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child 34 hp, ht, pid, tid = _winapi.CreateProcess(executable, args, 35FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。

該当のソースコード

python

1 2import sox 3 4 5import os 6 7 8if __name__ == "__main__": 9 10 original_wav_dir = '../data/original/jsut_ver1.1/basic5000/wav' 11 12 out_wav_dir = '../data/wav' 13 14 out_scp_dir = '../data/label/all' 15 16 os.makedirs(out_wav_dir, exist_ok=True) 17 os.makedirs(out_scp_dir, exist_ok=True) 18 19 20 tfm = sox.Transformer() 21 22 tfm.convert(samplerate=16000) 23 24 25 with open(os.path.join(out_scp_dir, 'wav.scp'), mode='w') as scp_file: 26 27 for i in range(5000): 28 filename = 'BASIC5000_%04d' % (i+1) 29 30 wav_path_in = os.path.join(original_wav_dir, filename+'.wav') 31 32 wav_path_out = os.path.join(out_wav_dir, filename+'.wav') 33 34 print(wav_path_in) 35 36 if not os.path.exists(wav_path_in): 37 print('Error: Not found %s' % (wav_path_in)) 38 exit() 39 40 41 tfm.build_file(input_filepath=wav_path_in, 42 output_filepath=wav_path_out) 43 44 45 scp_file.write('%s %s\n' % 46 (filename, os.path.abspath(wav_path_out))) 47

###試したこと
調べてみると同じエラーメッセージが出ている人がいてその人が解決したように自分も同じ方法をしてみました.
その人がしたこと

  • soxをインストールして同じディレクトリ内にsoxを移動

また自分はコマンドライン上に下記のコードを打ち込みパスを通そうとしましたが下記のようなエラーメッセージが発生しました

打ち込んだコード path %path;C:Program Files (x86)\sox-14-4-2
発生したエラー path : The term 'path' is not recognized as the name of a cmdlet, function, script file, or operab le program. Check the spelling of the name, or if a path was included, verify that the path is cor rect and try again. At line:1 char:1 + path %path;C:Program Files (x86)\sox-14-4-2 + ~~~~ + CategoryInfo : ObjectNotFound: (path:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException x86 : The term 'x86' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is corre ct and try again. At line:1 char:29 + path %path;C:Program Files (x86)\sox-14-4-2 + ~~~ + CategoryInfo : ObjectNotFound: (x86:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

となり解決できませんでした
結局原因すらわからず困っています
特にsoxのインストールがうまくいっていないのかパスが通っていないのかすらわかりません.コードはいただいたものなので間違って位はいないと思います.
よろしくお願いします

コメントを受けて追記

soxのダウンロードが上手くいっていない気がします
エラー文に乗っているURLからsoxをダウンロードをしてインストールしたのですが下記のような状況になりました.
イメージ説明

  • インストールすると追加される二つのショートカットが何かわからず放置していたのですが,クリックしてみると一瞬だけ読み込んですぐに落ちるみたいな状況で機能していません
  • 移動したディレクトリとは今実行しているコードのディレクトリである00prepareと同じ場所に移動してあります上記の画像のように

補足情報 (FW/ツールのバージョンなど)

vscode - ver 1.63.2

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Supernove

2021/12/29 07:47

エラーメッセージが何も無いので追記してもらってもいいでしょうか?
primer57

2021/12/29 08:03

すみません 誤って質問の記述途中に投稿してしまいました
Supernove

2021/12/29 08:14

なるほど、でしたらそのまま編集できると思うのでよろしくお願いします
primer57

2021/12/29 10:29

編集して質問を完成させました よろしくお願いいたします
primer57

2021/12/29 12:21 編集

お願いします
guest

回答1

0

ベストアンサー

soxのパスが通っているかはコマンドラインで「sox」と入力したときに「コマンドが見つかりません」みたいなメッセージが表示されるかどうかで判断できると思います。
Windowsのコマンドラインでのパスの設定方法が正しいか分かりませんが、自分だったらコントロールパネルから環境変数の設定ができるので、そこでやりますね。
Windowsでsoxを使うときには以下の記事が参考になると思います。
http://pika.way-nifty.com/pika/2019/09/post-c996ed.html

投稿2021/12/29 11:00

Supernove

総合スコア1154

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

primer57

2021/12/29 11:24

回答ありがとうございます しかしいまだにプログラムが動作しません 上記の一番最初のプログラム自体を実行したときにエラーが変わらずでます まだ解決しません 解決方法を教えていただけないでしょうか?
Supernove

2021/12/29 11:32

「soxのパスが通っているかはコマンドラインで「sox」と入力したときに「コマンドが見つかりません」みたいなメッセージが表示されるかどうかで判断できると思います。」 と書いてあるので、その結果がどうだったかを教えてほしいです。 プログラムのエラーが出るのは分かっているので、そう言われても何も解決のしようがありません
primer57

2021/12/29 11:43

回答ありがとうございます soxと入力したところ下記のように出ました sox : The term 'sox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and tr y again. At line:1 char:1 + sox + ~~~ + CategoryInfo : ObjectNotFound: (sox:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Supernove

2021/12/29 12:04

たぶんsoxのパスが正しく通ってませんね。 「soxをインストールして同じディレクトリ内にsoxを移動」とありますが、どこにインストールしましたか?
primer57

2021/12/29 12:22

回答ありがとうございます. 上記にコメントを受けて追記という項目を追加したので確認よろしくお願いします. 説明不足によりお手を煩わせてすみません
Supernove

2021/12/29 13:07

ありがとうございます。インストールができていてもパスが通っているわけではないので、パスは自分で設定する必要があります。なので、コントロールパネルの「システム環境変数」を開き、「Path」の項目に以下のパスを追加します。 「C:\Program Files (x86)\sox-14-4-2」 設定を保存したら、VSCodeを再起動してコマンドラインから「sox」と叩いて検索してみてください
primer57

2021/12/29 13:21

回答ありがとうございます pathを追加してみて後にコマンドラインにsoxと入力してみたら下記に様なエラーが出てきました sox : The term 'sox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and tr y again. At line:1 char:1 + sox + ~~~ + CategoryInfo : ObjectNotFound: (sox:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Supernove

2021/12/29 13:23

コマンドプロンプトかPowerShellで確認しましたか?
primer57

2021/12/29 13:27

vscodeのターミナルでしてました
Supernove

2021/12/29 13:33

soxをどこにインストールしているかわかりますか?デスクトップのショートカットの中のsox.exeを右クリックして「ファイルの場所を開く」をクリックするとインストール先が表示されるはずです。
primer57

2021/12/29 13:38

回答ありがとうございます ローカルディスクの中のProgram Files(x86)の中にありました
Supernove

2021/12/29 13:39

パスで教えてほしいです
primer57

2021/12/29 13:42

C:\Program Files (x86)\sox-14-4-2 お願いします
Supernove

2021/12/29 13:46

であればコマンドプロンプトかPowerShellを使って「sox」と叩いてみて確認してほしいです。
primer57

2021/12/29 13:51

回答ありがとうございます 下記のような結果が出ました C:\Program Files (x86)\sox-14-4-2\sox.exe: SoX v14.4.2 C:\Program Files (x86)\sox-14-4-2\sox.exe FAIL sox: Not enough input filenames specified Usage summary: [gopts] [[fopts] infile]... [fopts] outfile [effect [effopt]]... 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 all input files (default for sox, rec) --combine sequence Sequence all input files (default for play) -D, --no-dither Don't dither automatically --dft-min NUM Minimum size (log2) for DFT processing (default 10) --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) --combine mix-power Mix to equal power (instead of concatenating) -M, --combine merge Merge multiple input files (instead of concatenating) --multi-threaded Enable parallel effects channels processing --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 -T, --combine multiply Multiply samples of corresponding channels from all input files (instead of concatenating) --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 overridden 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 -e|--encoding ENCODING Set encoding (ENCODING may be one of signed-integer, unsigned-integer, floating-point, mu-law, a-law, ima-adpcm, ms-adpcm, gsm-full-rate) -b|--bits BITS Encoded sample size in bits -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 amr-nb amr-wb anb au avr awb cdda cdr cvs cvsd cvu dat dvms f32 f4 f64 f8 flac fssd gsm gsrt hcom htk ima ircam la lpc lpc10 lu maud mp2 mp3 nist ogg prc raw s1 s16 s2 s24 s3 s32 s4 s8 sb sf sl sln smp snd sndr sndt sou sox sph sw txw u1 u16 u2 u24 u3 u32 u4 u8 ub ul uw vms voc vorbis vox wav wavpcm wv wve xa PLAYLIST FORMATS: m3u pls AUDIO DEVICE DRIVERS: waveaudio EFFECTS: allpass band bandpass bandreject bass bend biquad chorus channels compand contrast dcshift deemph delay dither divide+ downsample earwax echo echos equalizer fade fir firfit+ flanger gain highpass hilbert input# ladspa loudness lowpass mcompand noiseprof noisered norm oops output# overdrive pad phaser pitch rate remix repeat reverb reverse riaa silence sinc spectrogram speed splice stat stats stretch swap synth tempo treble tremolo trim upsample vad vol * Deprecated effect + Experimental effect # LibSoX-only effect EFFECT OPTIONS (effopts): effect dependent; see --help-effect
Supernove

2021/12/29 14:20

いいですね!soxのパスが通ってます。 コマンドプロンプトかPowerShellで動かしたいPythonのプログラムがあるディレクトリ上に移動してプログラムを実行したら多分エラーが解消するはずです。
primer57

2021/12/29 14:25

回答ありがとうございます ちゃんとエラーもなくプログラムも実行できました
primer57

2021/12/29 14:26

最後まで付き合ってありがとうございます 本当に助かりました
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問